| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- /*****************************************************************
- Fichier : DrawEllipse.cpp
- Date : 07/01/11
- Version : 1.000
- Description : Classe de dessin des ellipses
- |*****************************************************************/
- #include <cstdlib>
- #include "drawEllipse.h"
- CDrawEllipse::CDrawEllipse()
- {
- top = 0;
- bottom = 0;
- left = 0;
- right = 0;
- }
- CDrawEllipse::~CDrawEllipse()
- {
- }
- void CDrawEllipse::PutPixEllipse(void (*ptFonction) (int, int), float xc,float yc,float x,float y)
- {
- ptFonction( (int) (xc + x), (int) (yc + y));
- ptFonction( (int) (xc - x), (int) (yc - y));
- ptFonction( (int) (xc + x), (int) (yc - y));
- ptFonction( (int) (xc - x), (int) (yc + y));
- }
- // Algorithme MidPoint de dessin d'une Ellipse
- void CDrawEllipse::myDrawEllipse(void (*ptFonction) (int, int))
- {
- float x = 0, y = 0;
- double p1, p2, t1, t2;
- int k;
- float rx, ry, xc, yc;
- rx = (float) (right - left) / 2;
- ry = (float) (bottom - top) / 2;
- xc = left + rx;
- yc = top + ry;
- y = ry;
- p1 = ry * ry - rx * rx * ry + 0.25 * rx * rx;
-
- PutPixEllipse(ptFonction, xc, yc, x, y);
- for (k = 0; (2 * ry * ry * x) <= (2 * rx * rx * y); k++)
- {
- t1 = 2 * ry * ry * x + 2 * ry * ry;
- t2 = 2 * rx * rx * y - 2 * rx * rx;
-
- if (p1 < 0)
- {
- p1 = p1 + t1 + ry * ry;
- }
- else
- {
- p1 = p1 + t1 - t2 + ry * ry;
- y--;
- }
- x++;
- PutPixEllipse(ptFonction, xc, yc, x, y);
- }
- p2 = ry * ry * ( x + 0.5 ) * ( x + 0.5 ) + rx * rx * (y - 1) * (y - 1) - rx * rx * ry * ry;
-
- PutPixEllipse(ptFonction, xc, yc, x, y);
- for (k = 0 ; y >= 0 ; k++)
- {
- t1 = 2 * ry * ry * x + 2 * ry * ry;
- t2 = 2 * rx * rx * y - 2 * rx * rx;
-
- if (p2 > 0)
- {
- p2 = p2 - t2 + rx * rx;
- }
- else
- {
- p2 = p2 + t1 - t2 + rx * rx;
- x++;
- }
- y--;
- PutPixEllipse(ptFonction, xc, yc, x, y);
- }
- }
|