Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MEllipse
- {
- public:
- TPoint points[4];
- TPoint *pell;
- float polX, polY, e, p;
- TPoint cm;
- MEllipse(){}
- MEllipse(TPoint p1, TPoint p2)
- {
- points[0] = p1;
- points[1] = p2;
- // rightP(p1, p2); делает, чтобы п1 - верхн левая, п2 - правая нижн
- polX = (p2.x - p1.x)/2;
- polY = (p2.y - p1.y)/2;
- if (polX > polY)
- {
- e = sqrt(1.0 - polY*polY/polX/polX);
- p = polY*polY/polX;
- }
- else
- {
- e = sqrt(1.0 - polX*polX/polY/polY);
- p = polX*polX/polY;
- }
- cm.x = p1.x + polX;
- cm.y = p1.y + polY;
- pell = new TPoint[361];
- for (int i = 0; i < 360; ++i)
- {
- float j = i*M_PI/180;
- float r = p/(1 + e*cos(j));
- pell[i].x = cos(j)*r + cm.x;
- pell[i].y = sin(j)*r + cm.y;
- }
- }
- void showEllipse(TCanvas* Canvas)
- {
- Canvas -> Polygon (pell, 359);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement