Advertisement
Guest User

Untitled

a guest
May 20th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. class MEllipse
  2. {
  3. public:
  4. TPoint points[4];
  5. TPoint *pell;
  6. float polX, polY, e, p;
  7. TPoint cm;
  8. MEllipse(){}
  9. MEllipse(TPoint p1, TPoint p2)
  10. {
  11. points[0] = p1;
  12. points[1] = p2;
  13. // rightP(p1, p2); делает, чтобы п1 - верхн левая, п2 - правая нижн
  14. polX = (p2.x - p1.x)/2;
  15. polY = (p2.y - p1.y)/2;
  16. if (polX > polY)
  17. {
  18. e = sqrt(1.0 - polY*polY/polX/polX);
  19. p = polY*polY/polX;
  20. }
  21. else
  22. {
  23. e = sqrt(1.0 - polX*polX/polY/polY);
  24. p = polX*polX/polY;
  25. }
  26. cm.x = p1.x + polX;
  27. cm.y = p1.y + polY;
  28. pell = new TPoint[361];
  29. for (int i = 0; i < 360; ++i)
  30. {
  31. float j = i*M_PI/180;
  32. float r = p/(1 + e*cos(j));
  33. pell[i].x = cos(j)*r + cm.x;
  34. pell[i].y = sin(j)*r + cm.y;
  35. }
  36. }
  37.  
  38. void showEllipse(TCanvas* Canvas)
  39. {
  40. Canvas -> Polygon (pell, 359);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement