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. double R(double L, int N){//組み込んだ
  12. double T = tan((M_PI/N));
  13. return (L / 2)*sqrt(1 + 1 / (T*T));
  14. }
  15.  
  16. template<class T>
  17. struct Vector2
  18. {
  19. T x, y;
  20. };
  21. typedef Vector2<double> Vector2D;
  22.  
  23. template<class T>
  24. Vector2<T> TransForm(Vector2<T>& Length, double RotRadian, Vector2<T>& Scale, Vector2<T>& Move)
  25. {
  26. Vector2<T> Ret = { 0, };
  27. double Sin = sin(RotRadian);
  28. double Cos = cos(RotRadian);
  29.  
  30. Ret.x = ((Length.x * Scale.x) * Cos) - ((Length.y * Scale.y) * Sin) + Move.x;
  31. Ret.y = ((Length.x * Scale.x) * Sin) + ((Length.y * Scale.y) * Cos) + Move.y;
  32.  
  33. return Ret;
  34. }
  35.  
  36. std::vector<Vector2D> SeiNKakukei(int N,double Rotaion, Vector2D Scale, Vector2D Move){
  37. double Degree = 360.0 / N;
  38. double Radius = R(1.0, N);
  39. std::vector<Vector2D> vec;
  40. Vector2D L{ Radius, 0 };
  41.  
  42.  
  43. for (int i = 0; i < N; i++){
  44. vec.push_back(TransForm(L, ((Degree*i)+Rotaion - 90)*(M_PI / 180.0), Scale, Move));
  45. }
  46. return vec;
  47. }
  48.  
  49. int main(){
  50. double Rot = 0;
  51. Vector2D S{ 1, 1 };
  52. Vector2D M{ 0, 0 };
  53.  
  54. for (int N = 3; N < 9; N++){
  55. auto vec = SeiNKakukei(N, Rot, S, M);
  56. std::cout << "正" << N << "角形??:";
  57. for (auto& o : vec) std::cout << '[' << o.x << ',' << o.y << ']' << ',';
  58. std::cout << std::endl;
  59. }
  60. int N = 3;
  61. for (int R = 0; R < 360; R+=45){
  62. auto vec = SeiNKakukei(N, R, S, M);
  63. std::cout << "正" << N << "角形??:";
  64. for (auto& o : vec) std::cout << '[' << o.x << ',' << o.y << ']' << ',';
  65. std::cout << std::endl;
  66. }
  67. return 0;
  68. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
正3角形??:[3.53525e-17,-0.57735],[0.5,0.288675],[-0.5,0.288675],
正4角形??:[4.32978e-17,-0.707107],[0.707107,0],[4.32978e-17,0.707107],[-0.707107,8.65956e-17],
正5角形??:[5.20873e-17,-0.850651],[0.809017,-0.262866],[0.5,0.688191],[-0.5,0.688191],[-0.809017,-0.262866],
正6角形??:[6.12323e-17,-1],[0.866025,-0.5],[0.866025,0.5],[6.12323e-17,1],[-0.866025,0.5],[-0.866025,-0.5],
正7角形??:[7.05631e-17,-1.15238],[0.900969,-0.718499],[1.12349,0.256429],[0.5,1.03826],[-0.5,1.03826],[-1.12349,0.256429],[-0.900969,-0.718499],
正8角形??:[8.00039e-17,-1.30656],[0.92388,-0.92388],[1.30656,0],[0.92388,0.92388],[8.00039e-17,1.30656],[-0.92388,0.92388],[-1.30656,1.60008e-16],[-0.92388,-0.92388],
正3角形??:[3.53525e-17,-0.57735],[0.5,0.288675],[-0.5,0.288675],
正3角形??:[0.408248,-0.408248],[0.149429,0.557678],[-0.557678,-0.149429],
正3角形??:[0.57735,0],[-0.288675,0.5],[-0.288675,-0.5],
正3角形??:[0.408248,0.408248],[-0.557678,0.149429],[0.149429,-0.557678],
正3角形??:[3.53525e-17,0.57735],[-0.5,-0.288675],[0.5,-0.288675],
正3角形??:[-0.408248,0.408248],[-0.149429,-0.557678],[0.557678,0.149429],
正3角形??:[-0.57735,7.0705e-17],[0.288675,-0.5],[0.288675,0.5],
正3角形??:[-0.408248,-0.408248],[0.557678,-0.149429],[-0.149429,0.557678],