Guest User

Untitled

a guest
Nov 20th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. float centerX = 100;
  2. float centerY = 100;
  3. float radiusX = 100;
  4. float radiusY = 100;
  5. float rotation = PI;
  6. float res = 30;
  7. for (int i = 0; i < res; i++) {
  8.  
  9. //find the point in space for the circle resolution
  10. float angle = (float)i/res * TWO_PI;
  11.  
  12. float x = radiusX * cos(angle);
  13. float y = -radiusY * sin(angle);
  14.  
  15. //rotate the point
  16. float s = sin(rotation);
  17. float c = cos(rotation);
  18.  
  19. // translate point to origin:
  20. p->x -= centerX;
  21. p->y -= centerY;
  22.  
  23. float xnew = p->x * c - p->y * s;
  24. float ynew = p->x * s + p->y * c;
  25.  
  26. // translate point back
  27. x = xnew + centerX;
  28. y = ynew + centerY;
  29.  
  30. //apply X Y
  31. }
  32.  
  33. //setup the four coordinates
  34. float topX = 20;
  35. float topY = 10;
  36.  
  37. float bottomX = 30;
  38. float bottomY = 20;
  39.  
  40. float rightX = 30;
  41. float rightY = 20;
  42.  
  43. float leftX = 30;
  44. float leftY = 20;
  45.  
  46. //calculate the horizontal radius
  47. float distHorX = rightX-leftX;
  48. float distHorY = rightY-leftY;
  49. float radiusX = sqrt(distHorX * distHorX + distHorY * distHorY)/2.f;
  50.  
  51. //calculate the vertical radius
  52. float distVerX = topX-bottomX;
  53. float distVerY = topY-bottomY;
  54. radiusY = sqrt(distVerX * distVerX + distVerY * distVerY)/2.f;
  55.  
  56. float res = 30;
  57. for (int i = 0; i < res; i++) {
  58.  
  59. float angle = (float)i/res * TWO_PI;
  60.  
  61. float x = radiusX * cos(angle);
  62. float y = -radiusY * sin(angle);
  63.  
  64. //corvert the circle inside a square to a square inside a circle
  65. //it is a magical number I have found to convert that proportion
  66. x /= 0.705069124;
  67. y /= 0.705069124;
  68.  
  69. //transform the points based on that four coordinates
  70. float pctx = (x + radiusX) / (radiusX*2);
  71. float pcty = (y + radiusY) / (radiusY*2);
  72.  
  73. float linePt0x = (1-pcty)* topX + pcty * leftX;
  74. float linePt0y = (1-pcty)* topY + pcty * leftY;
  75. float linePt1x = (1-pcty)* rightX + pcty * bottomX;
  76. float linePt1y = (1-pcty)* rightY + pcty * bottomY;
  77. float ptx = (1-pctx) * linePt0x + pctx * linePt1x;
  78. float pty = (1-pctx) * linePt0y + pctx * linePt1y;
  79.  
  80. //apply X Y
  81. x = ptx;
  82. y = pty;
  83. }
Add Comment
Please, Sign In to add comment