#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)); } 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, Degree); 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角形??:[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],