fork download
  1. #include <iostream>
  2. #include <vector>
  3. #define _USE_MATH_DEFINES
  4. #include <math.h>
  5. //Make Radius document -> ttp://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q1215054992
  6.  
  7. double R(double L, double Degree){
  8. return L / (M_PI*(Degree / 180));
  9. }
  10.  
  11. template<class T>
  12. struct Vector2
  13. {
  14. T x, y;
  15. };
  16. typedef Vector2<double> Vector2D;
  17.  
  18. template<class T>
  19. Vector2<T> TransForm(Vector2<T>& Length, double RotRadian, Vector2<T>& Scale, Vector2<T>& Move)
  20. {
  21. Vector2<T> Ret = { 0, };
  22. double Sin = sin(RotRadian);
  23. double Cos = cos(RotRadian);
  24.  
  25. Ret.x = ((Length.x * Scale.x) * Cos) - ((Length.y * Scale.y) * Sin) + Move.x;
  26. Ret.y = ((Length.x * Scale.x) * Sin) + ((Length.y * Scale.y) * Cos) + Move.y;
  27.  
  28. return Ret;
  29. }
  30.  
  31. std::vector<Vector2D> SeiNKakukei(int N,double Rotaion, Vector2D Scale, Vector2D Move){
  32. double Degree = 360.0 / N;
  33. double Radius = R(1.0, Degree);
  34. std::vector<Vector2D> vec;
  35. Vector2D L{ Radius, 0 };
  36.  
  37.  
  38. for (int i = 0; i < N; i++){
  39. vec.push_back(TransForm(L, ((Degree*i)+Rotaion - 90)*(M_PI / 180.0), Scale, Move));
  40. }
  41. return vec;
  42. }
  43.  
  44. int main(){
  45. double Rot = 0;
  46. Vector2D S{ 1, 1 };
  47. Vector2D M{ 0, 0 };
  48.  
  49. for (int N = 3; N < 9; N++){
  50. auto vec = SeiNKakukei(N, Rot, S, M);
  51. std::cout << "正" << N << "角形??:";
  52. for (auto& o : vec) std::cout << '[' << o.x << ',' << o.y << ']' << ',';
  53. std::cout << std::endl;
  54. }
  55. int N = 3;
  56. for (int R = 0; R < 360; R+=45){
  57. auto vec = SeiNKakukei(N, R, S, M);
  58. std::cout << "正" << N << "角形??:";
  59. for (auto& o : vec) std::cout << '[' << o.x << ',' << o.y << ']' << ',';
  60. std::cout << std::endl;
  61. }
  62. return 0;
  63. }
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
正3角形??:[2.92363e-17,-0.477465],[0.413497,0.238732],[-0.413497,0.238732],
正4角形??:[3.89817e-17,-0.63662],[0.63662,0],[3.89817e-17,0.63662],[-0.63662,7.79634e-17],
正5角形??:[4.87271e-17,-0.795775],[0.756827,-0.245908],[0.467745,0.643795],[-0.467745,0.643795],[-0.756827,-0.245908],
正6角形??:[5.84726e-17,-0.95493],[0.826993,-0.477465],[0.826993,0.477465],[5.84726e-17,0.95493],[-0.826993,0.477465],[-0.826993,-0.477465],
正7角形??:[6.8218e-17,-1.11408],[0.871026,-0.69462],[1.08615,0.247907],[0.483383,1.00376],[-0.483383,1.00376],[-1.08615,0.247907],[-0.871026,-0.69462],
正8角形??:[7.79634e-17,-1.27324],[0.900316,-0.900316],[1.27324,0],[0.900316,0.900316],[7.79634e-17,1.27324],[-0.900316,0.900316],[-1.27324,1.55927e-16],[-0.900316,-0.900316],
正3角形??:[2.92363e-17,-0.477465],[0.413497,0.238732],[-0.413497,0.238732],
正3角形??:[0.337619,-0.337619],[0.123577,0.461196],[-0.461196,-0.123577],
正3角形??:[0.477465,0],[-0.238732,0.413497],[-0.238732,-0.413497],
正3角形??:[0.337619,0.337619],[-0.461196,0.123577],[0.123577,-0.461196],
正3角形??:[2.92363e-17,0.477465],[-0.413497,-0.238732],[0.413497,-0.238732],
正3角形??:[-0.337619,0.337619],[-0.123577,-0.461196],[0.461196,0.123577],
正3角形??:[-0.477465,5.84726e-17],[0.238732,-0.413497],[0.238732,0.413497],
正3角形??:[-0.337619,-0.337619],[0.461196,-0.123577],[-0.123577,0.461196],