#include <iostream> #include <vector> #define _USE_MATH_DEFINES #include <math.h> //Make Radius document -> ttp://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q1215054992 /*double R(double L, double Degree){ return L / (M_PI*(Degree / 180)); } */ double R(double L, int N){//組み込んだ double T = tan((M_PI/N)); return (L / 2)*sqrt(1 + 1 / (T*T)); } template<class T> struct Vector2 { T x, y; }; typedef Vector2<double> Vector2D; template<class T> Vector2<T> TransForm(Vector2<T>& Length, double RotRadian, Vector2<T>& Scale, Vector2<T>& Move) { Vector2<T> Ret = { 0, }; double Sin = sin(RotRadian); double Cos = cos(RotRadian); Ret.x = ((Length.x * Scale.x) * Cos) - ((Length.y * Scale.y) * Sin) + Move.x; Ret.y = ((Length.x * Scale.x) * Sin) + ((Length.y * Scale.y) * Cos) + Move.y; return Ret; } std::vector<Vector2D> SeiNKakukei(int N,double Rotaion, Vector2D Scale, Vector2D Move){ double Degree = 360.0 / N; double Radius = R(1.0, N); std::vector<Vector2D> vec; Vector2D L{ Radius, 0 }; for (int i = 0; i < N; i++){ vec.push_back(TransForm(L, ((Degree*i)+Rotaion - 90)*(M_PI / 180.0), Scale, Move)); } return vec; } int main(){ double Rot = 0; Vector2D S{ 1, 1 }; Vector2D M{ 0, 0 }; for (int N = 3; N < 9; N++){ auto vec = SeiNKakukei(N, Rot, S, M); std::cout << "正" << N << "角形??:"; for (auto& o : vec) std::cout << '[' << o.x << ',' << o.y << ']' << ','; std::cout << std::endl; } int N = 3; for (int R = 0; R < 360; R+=45){ auto vec = SeiNKakukei(N, R, S, M); std::cout << "正" << N << "角形??:"; for (auto& o : vec) std::cout << '[' << o.x << ',' << o.y << ']' << ','; std::cout << std::endl; } return 0; }
Standard input is empty
正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],