c++ - sin() cos() ring formula -


this source code:

#include <windows.h> #include <string> #include <iostream> #include <fstream> #include <math.h>  using namespace std;  #define d_open  fstream::in | fstream::out | fstream::app | fstream::ate #define space " " #define d_qq "\""   struct point3d {     float x;     float y;     float z; };  struct objectstruct  {     point3d t_lt;     point3d t_lb;     point3d t_rt;     point3d t_rb;     point3d b_lt;     point3d b_lb;     point3d b_rt;     point3d b_rb; };  void createobject(objectstruct myobject) {     fstream outmap;     outmap.open("prefab.map", d_open);      float * x = new float[6];     float * y = new float[6];     float * z = new float[6];     float * x2 = new float[6];     float * y2 = new float[6];     float * z2 = new float[6];     float * x3 = new float[6];     float * y3 = new float[6];     float * z3 = new float[6];      x[0] = myobject.t_lt.x;     y[0] = myobject.t_lt.y;     z[0] = myobject.t_lt.z;     x2[0] = myobject.t_rt.x;     y2[0] = myobject.t_rt.y;     z2[0] = myobject.t_rt.z;     x3[0] = myobject.t_rb.x;     y3[0] = myobject.t_rb.y;     z3[0] = myobject.t_rb.z;     x[1] = myobject.b_lb.x;     y[1] = myobject.b_lb.y;     z[1] = myobject.b_lb.z;     x2[1] = myobject.b_rb.x;     y2[1] = myobject.b_rb.y;     z2[1] = myobject.b_rb.z;     x3[1] = myobject.b_rt.x;     y3[1] = myobject.b_rt.y;     z3[1] = myobject.b_rt.z;     x[2] = myobject.t_lt.x;     y[2] = myobject.t_lt.y;     z[2] = myobject.t_lt.z;     x2[2] = myobject.t_lb.x;     y2[2] = myobject.t_lb.y;     z2[2] = myobject.t_lb.z;     x3[2] = myobject.b_lb.x;     y3[2] = myobject.b_lb.y;     z3[2] = myobject.b_lb.z;     x[3] = myobject.b_rt.x;     y[3] = myobject.b_rt.y;     z[3] = myobject.b_rt.z;     x2[3] = myobject.b_rb.x;     y2[3] = myobject.b_rb.y;     z2[3] = myobject.b_rb.z;     x3[3] = myobject.t_rb.x;     y3[3] = myobject.t_rb.y;     z3[3] = myobject.t_rb.z;     x[4] = myobject.t_rt.x;     y[4] = myobject.t_rt.y;     z[4] = myobject.t_rt.z;     x2[4] = myobject.t_lt.x;     y2[4] = myobject.t_lt.y;     z2[4] = myobject.t_lt.z;     x3[4] = myobject.b_lt.x;     y3[4] = myobject.b_lt.y;     z3[4] = myobject.b_lt.z;     x[5] = myobject.b_rb.x;     y[5] = myobject.b_rb.y;     z[5] = myobject.b_rb.z;     x2[5] = myobject.b_lb.x;     y2[5] = myobject.b_lb.y;     z2[5] = myobject.b_lb.z;     x3[5] = myobject.t_lb.x;     y3[5] = myobject.t_lb.y;     z3[5] = myobject.t_lb.z;         outmap          << "{" << endl          << "( " << x[0] << space << y[0] << space << z[0] << " ) "         << "( " << x2[0] << space << y2[0] << space << z2[0] << " ) "         << "( " << x3[0] << space << y3[0] << space << z3[0] << " ) "         << "yellow"         << " [ 1 0 0 0 ] [ 0 -1 0 0 ] 0 1 1 " << endl          << "( " << x[1] << space << y[1] << space << z[1] << " ) "         << "( " << x2[1] << space << y2[1] << space << z2[1] << " ) "         << "( " << x3[1] << space << y3[1] << space << z3[1] << " ) "         << "yellow"         << " [ 1 0 0 0 ] [ 0 -1 0 0 ] 0 1 1 " << endl          << "( " << x[2] << space << y[2] << space << z[2] << " ) "         << "( " << x2[2] << space << y2[2] << space << z2[2] << " ) "         << "( " << x3[2] << space << y3[2] << space << z3[2] << " ) "         << "yellow"         << " [ 0 1 0 0 ] [ 0 0 -1 0 ] 0 1 1 " << endl          << "( " << x[3] << space << y[3] << space << z[3] << " ) "         << "( " << x2[3] << space << y2[3] << space << z2[3] << " ) "         << "( " << x3[3] << space << y3[3] << space << z3[3] << " ) "         << "yellow"         << " [ 0 1 0 0 ] [ 0 0 -1 0 ] 0 1 1 " << endl          << "( " << x[4] << space << y[4] << space << z[4] << " ) "         << "( " << x2[4] << space << y2[4] << space << z2[4] << " ) "         << "( " << x3[4] << space << y3[4] << space << z3[4] << " ) "         << "yellow"         << " [ 1 0 0 0 ] [ 0 0 -1 0 ] 0 1 1 " << endl          << "( " << x[5] << space << y[5] << space << z[5] << " ) "         << "( " << x2[5] << space << y2[5] << space << z2[5] << " ) "         << "( " << x3[5] << space << y3[5] << space << z3[5] << " ) "         << "yellow"         << " [ 1 0 0 0 ] [ 0 0 -1 0 ] 0 1 1 " << endl          << "}" << endl;      delete [] x;     delete [] y;     delete [] z;     delete [] x2;     delete [] y2;     delete [] z2;     delete [] x3;     delete [] y3;     delete [] z3;     outmap.flush();     //     outmap.close(); }      int main(int argc, char ** argv) {     //handle console = getstdhandle(std_output_handle);     setconsoletitle("prefab creator raichu (xgm.ru,d3scene.ru)");     sleep(200);     setconsoletitle("prefabtool raichu  v0.1");     int select = 0;     cout << "available shapes: 1-ring, 2-cube, 3-triangle" << endl;     cin >> select;     if (select == 1)     {         cout << "enter quantity of objects:" << endl;         int quality;          cin >> quality;          if (quality > 200 || quality < 10)         {             cout << "error... restart..." << endl;             return main(argc, argv);         }           cout << "enter ring radius:(example 20.0)" << endl;         float whsz;           cin >> whsz;          float inangle = 360 / quality;         //system("cls");         float x1_, x2_, y1_, y2_;         float x1, x2, y1, y2;         float = 0;         x1_ = whsz * cos(a);         y1_ = whsz * sin(a);         x2_ = (whsz + 4) * cos(a);         y2_ = (whsz + 4) * sin(a);         = inangle;         (; <= 360; )         {                x1 = whsz * cos(a);             y1 = whsz * sin(a);             x2 = (whsz + 4) * cos(a);             y2 = (whsz + 4) * sin(a); #pragma region test             //cout << "x:" << x1 << " y:" << y1 << endl;          /*  coord xy;             xy.x = x1;             xy.y = y1;             setconsolecursorposition(console, xy);             cout << "+" << endl;             xy.x = x2;             xy.y = y2;             setconsolecursorposition(console, xy);             cout << "?" << endl;*/ #pragma endregion              objectstruct newobject;             /* down */             newobject.b_lb.z = newobject.b_lt.z = newobject.b_rb.z = newobject.b_rt.z = -5;             /* top */              newobject.t_lb.z = newobject.t_lt.z = newobject.t_rb.z = newobject.t_rt.z = 5;               newobject.t_lt.x = newobject.b_lt.x = x2_;             newobject.t_lt.y = newobject.b_lt.y = y2_;             newobject.t_lb.x = newobject.b_lb.x = x1_;             newobject.t_lb.y = newobject.b_lb.y = y1_;              newobject.t_rt.x = newobject.b_rt.x = x2;             newobject.t_rt.y = newobject.b_rt.y = y2;             newobject.t_rb.x = newobject.b_rb.x = x1;             newobject.t_rb.y = newobject.b_rb.y = y1;               createobject(newobject);               x1_ = x1;             y1_ = y1;             x2_ = x2;             y2_ = y2;              //a += inangle/3; // - create sun             += inangle;            }      }      system("pause");     return 0; } 

problem code:

if (select == 1)     {         cout << "enter quantity of objects:" << endl;         int quality;          cin >> quality;          if (quality > 200 || quality < 10)         {             cout << "error... restart..." << endl;             return main(argc, argv);         }           cout << "enter ring radius:(example 20.0)" << endl;         float whsz;           cin >> whsz;          float inangle = 360 / quality;         //system("cls");         float x1_, x2_, y1_, y2_;         float x1, x2, y1, y2;         float = 0;         x1_ = whsz * cos(a);         y1_ = whsz * sin(a);         x2_ = (whsz + 4) * cos(a);         y2_ = (whsz + 4) * sin(a);         = inangle;         (; <= 360; )         {                x1 = whsz * cos(a);             y1 = whsz * sin(a);             x2 = (whsz + 4) * cos(a);             y2 = (whsz + 4) * sin(a); #pragma region test             //cout << "x:" << x1 << " y:" << y1 << endl;          /*  coord xy;             xy.x = x1;             xy.y = y1;             setconsolecursorposition(console, xy);             cout << "+" << endl;             xy.x = x2;             xy.y = y2;             setconsolecursorposition(console, xy);             cout << "?" << endl;*/ #pragma endregion              objectstruct newobject;             /* down */             newobject.b_lb.z = newobject.b_lt.z = newobject.b_rb.z = newobject.b_rt.z = -5;             /* top */              newobject.t_lb.z = newobject.t_lt.z = newobject.t_rb.z = newobject.t_rt.z = 5;               newobject.t_lt.x = newobject.b_lt.x = x2_;             newobject.t_lt.y = newobject.b_lt.y = y2_;             newobject.t_lb.x = newobject.b_lb.x = x1_;             newobject.t_lb.y = newobject.b_lb.y = y1_;              newobject.t_rt.x = newobject.b_rt.x = x2;             newobject.t_rt.y = newobject.b_rt.y = y2;             newobject.t_rb.x = newobject.b_rb.x = x1;             newobject.t_rb.y = newobject.b_rb.y = y1;               createobject(newobject);               x1_ = x1;             y1_ = y1;             x2_ = x2;             y2_ = y2;              //a += inangle/3; // - create sun             += inangle;            }      } 

i want create ring using objects. turns 3 turns (3 layers) instead of one. how fix it? seems problem in degrees, can not understand. (sorry that use translator google translate)

sin , cos take radians input, not degrees. you'll need convert angles radians before passing them sin , cos:

x1 = whsz * cos(a * 3.141592654 / 180.0); 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -