|
Trouver une ressource
Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !
CERCLE DISCRET (POINT PAR POINT) EN C++
Information sur la source
Description
Ce programme permet de dessiner un cercle discret (point par point) et d’arrondis les cordonnées réels
Source
- int xd=0,yd=0;
- int n=0;
- int s=0;
- /* Plot generates a point of the circle */
- void plot(x,y)
- int x,y;
- {
- s++;
- cout<<"Val Of X= "<<x+xd<< " and Val of y= "<<y+yd;
- }
- //------------------------------------------------------void main(void)
- {
- s=0;
- int ri,x,y; /* Integer part of radius point */
-
- float a,rph,rpxo,rmxo,rpyo,rmyo; /* constants */
- float xoph,xomh,yoph,yomh;
- float r,xo,yo; /* radius and center */
- double d; /* control value */
- float tmp,tmp1; /* temp. value */
- n=0;
- //Provide the radius and the center:R,xo,yo
-
- cout<<" val of R= ";
- sin>>r;
-
- xo=0;yo=0 ;
- ri=(int)r; /* integer part of the radius */
- r=r-0.5; /* circle of radius r'=r-0.5 is generated */
- a=r-ri; /* corresponding fractional part of radius */
- /* CIRCLE WITH SMALL RADIUS */
- if (ri<=1)
- {
- tmp=2*r+1;
- for(x=-2;x<=2;x++) /* the generation is brute force */
- for(y=-2;y<=2;y++)
- {
- tmp1=x*x+y*y-r*r;
- if ((tmp1>=0) && (tmp1<tmp))
- plot(x,y);
- }
- }
- else
- {
- // ri>1
- /* GENERAL CASE */
- /* Initialization of loop constants */
- rph=r+0.5;
- rpxo=r; rmxo=r-xo; rpyo=r+yo; rmyo=r-yo;
- xoph=xo+0.5; xomh=xo-0.5; yoph=yo+0.5; yomh=yo-0.5;
- /* STARTING POINT COMPUTATION */
- y=0;
- d=((ri-rpxo)*(ri+rmxo)+yo*yo)/2.0; /* Initial value of d for (ri,0) */
- if (d<(a+xo)) /* does (ri+1,0) belong to the circle ? */
- { plot(ri+1,0); /* (ri+1,0) does belong to the circle */
- if (d>=0) { plot(ri,0); x=ri;} /* (ri,0) belongs also to the circle */
- else { x=ri+1; d+=ri-xomh;} /* (ri,0) doesn't belong to the circle */
- }
- else if ((d>=0) && (d<rph)) /* does (ri,0) belong to the circle ? */
- { plot(ri,0);
- x=ri;
- }
- else /* if neither (ri+1,0) nor (ri,0) belong to the
- circle then (ri-1,0) does */
- {
- x=ri-1; plot(x,0);
- d+=xoph-ri;
- }
- /* END OF STARTING POINT PHASE */
- /* GENERATION OF QUADRANT 1 */
- while (x>0)
- {
- if (d<(rpyo-y)) /* Type (a) ? */
- { d+=y-yomh;
- y++;
- plot(x,y);
- }
- else
- { d+=xoph-x;
- x--;
- if (d>=0) plot(x,y); /* Type (b) ? */
- else
- { d+=y-yomh; /* Type (c) !*/
- y++;
- plot(x,y);
- }
- }
- }
- /* END OF GENERATION OF QUADRANT 1 */
- /* LIMIT POINTS BETWEEN QUADRANT #1 AND QUADRANT #2 */
- if (d<(rpyo-y)) /* Does (0,y+1) belong to the circle ? */
- { d+=xoph; plot(0,y+1); x--; plot(-1,y); }
- /* GENERATION OF QUADRANT 2 */
- while (y>0 )
- { if (d<(rmxo+x))
- {
- d+=xoph-x;
- x--;
- plot(x,y);
- }
- else
- { d+=yoph-y;
- y--;
- if (d>=0) plot(x,y);
- else
- { d+=xoph-x;
- x--;
- plot(x,y);
- }
- }
- }
- /* END OF GENERATION OF QUADRANT #2 */
- /* LIMIT POINTS BETWEEN QUADRANT #2 AND QUADRANT #3 */
- if (d<(rpxo+x))
- { d+=yoph; plot(x-1,0); y--; plot(x,-1); }
- /* GENERATION OF QUADRANT #3 */
- while (x<0)
- { if (d<(rmyo+y))
- { d+=yoph-y;
-
- y--;
- plot(x,y);
- }
- else
- { d+=x-xomh;
- x++;
- if (d>=0) plot(x,y);
- else
- { d+=yoph-y;
- y--;
- plot(x,y);
- }
- }
- }
- /* END OF GENERATION OF QUADRANT #3 */
- /* LIMIT POINTS BETWEEN QUADRANT #3 AND QUADRANT #4 */
- if (d<(rmyo+y))
- { d-=xomh; plot(0,y-1); x++; plot(1,y); }
- /* GENERATION OF QUADRANT #4 */
- while (y<0)
- { if (d<(rpxo-x))
- { d+=x-xomh;
- x++;
- plot(x,y);
- }
- else
- { d+=y-yomh;
- y++;
- if ((d>=0)&&(y)) plot(x,y);
- else
- { d+=x-xomh;
- x++;
- if (y) plot(x,y);
- }
- }
- }
- /* END OF GENERATION OF QUADRANT #4 */
- } /* END OF THE GENERAL CASE */
- }
- //------------------------------------------------------
- GO and test
-
int xd=0,yd=0;
int n=0;
int s=0;
/* Plot generates a point of the circle */
void plot(x,y)
int x,y;
{
s++;
cout<<"Val Of X= "<<x+xd<< " and Val of y= "<<y+yd;
}
//------------------------------------------------------void main(void)
{
s=0;
int ri,x,y; /* Integer part of radius point */
float a,rph,rpxo,rmxo,rpyo,rmyo; /* constants */
float xoph,xomh,yoph,yomh;
float r,xo,yo; /* radius and center */
double d; /* control value */
float tmp,tmp1; /* temp. value */
n=0;
//Provide the radius and the center:R,xo,yo
cout<<" val of R= ";
sin>>r;
xo=0;yo=0 ;
ri=(int)r; /* integer part of the radius */
r=r-0.5; /* circle of radius r'=r-0.5 is generated */
a=r-ri; /* corresponding fractional part of radius */
/* CIRCLE WITH SMALL RADIUS */
if (ri<=1)
{
tmp=2*r+1;
for(x=-2;x<=2;x++) /* the generation is brute force */
for(y=-2;y<=2;y++)
{
tmp1=x*x+y*y-r*r;
if ((tmp1>=0) && (tmp1<tmp))
plot(x,y);
}
}
else
{
// ri>1
/* GENERAL CASE */
/* Initialization of loop constants */
rph=r+0.5;
rpxo=r; rmxo=r-xo; rpyo=r+yo; rmyo=r-yo;
xoph=xo+0.5; xomh=xo-0.5; yoph=yo+0.5; yomh=yo-0.5;
/* STARTING POINT COMPUTATION */
y=0;
d=((ri-rpxo)*(ri+rmxo)+yo*yo)/2.0; /* Initial value of d for (ri,0) */
if (d<(a+xo)) /* does (ri+1,0) belong to the circle ? */
{ plot(ri+1,0); /* (ri+1,0) does belong to the circle */
if (d>=0) { plot(ri,0); x=ri;} /* (ri,0) belongs also to the circle */
else { x=ri+1; d+=ri-xomh;} /* (ri,0) doesn't belong to the circle */
}
else if ((d>=0) && (d<rph)) /* does (ri,0) belong to the circle ? */
{ plot(ri,0);
x=ri;
}
else /* if neither (ri+1,0) nor (ri,0) belong to the
circle then (ri-1,0) does */
{
x=ri-1; plot(x,0);
d+=xoph-ri;
}
/* END OF STARTING POINT PHASE */
/* GENERATION OF QUADRANT 1 */
while (x>0)
{
if (d<(rpyo-y)) /* Type (a) ? */
{ d+=y-yomh;
y++;
plot(x,y);
}
else
{ d+=xoph-x;
x--;
if (d>=0) plot(x,y); /* Type (b) ? */
else
{ d+=y-yomh; /* Type (c) !*/
y++;
plot(x,y);
}
}
}
/* END OF GENERATION OF QUADRANT 1 */
/* LIMIT POINTS BETWEEN QUADRANT #1 AND QUADRANT #2 */
if (d<(rpyo-y)) /* Does (0,y+1) belong to the circle ? */
{ d+=xoph; plot(0,y+1); x--; plot(-1,y); }
/* GENERATION OF QUADRANT 2 */
while (y>0 )
{ if (d<(rmxo+x))
{
d+=xoph-x;
x--;
plot(x,y);
}
else
{ d+=yoph-y;
y--;
if (d>=0) plot(x,y);
else
{ d+=xoph-x;
x--;
plot(x,y);
}
}
}
/* END OF GENERATION OF QUADRANT #2 */
/* LIMIT POINTS BETWEEN QUADRANT #2 AND QUADRANT #3 */
if (d<(rpxo+x))
{ d+=yoph; plot(x-1,0); y--; plot(x,-1); }
/* GENERATION OF QUADRANT #3 */
while (x<0)
{ if (d<(rmyo+y))
{ d+=yoph-y;
y--;
plot(x,y);
}
else
{ d+=x-xomh;
x++;
if (d>=0) plot(x,y);
else
{ d+=yoph-y;
y--;
plot(x,y);
}
}
}
/* END OF GENERATION OF QUADRANT #3 */
/* LIMIT POINTS BETWEEN QUADRANT #3 AND QUADRANT #4 */
if (d<(rmyo+y))
{ d-=xomh; plot(0,y-1); x++; plot(1,y); }
/* GENERATION OF QUADRANT #4 */
while (y<0)
{ if (d<(rpxo-x))
{ d+=x-xomh;
x++;
plot(x,y);
}
else
{ d+=y-yomh;
y++;
if ((d>=0)&&(y)) plot(x,y);
else
{ d+=x-xomh;
x++;
if (y) plot(x,y);
}
}
}
/* END OF GENERATION OF QUADRANT #4 */
} /* END OF THE GENERAL CASE */
}
//------------------------------------------------------
GO and test
Conclusion
pour plus de détailles contactez moi à l'adresse suivante: bob_carlos2006@yahoo.fr
Sources de la même categorie
Sources en rapport avec celle ci
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
Dessiner sous Visual Studio C++ [ par KryztL ]
Bonjour,J ai actuellement un programme a faire et entre autre chose, il faudrait qu il dessine un cercle mais sans passer par la fonction pDC->Elli
comment dessiner un cercle en c++ [ par Pa109 ]
je voudrais connaitre la fonction est la lib eventuel pour la realiser
Dessiner ses forms [ par dread ]
Bonjour.Je voudrais savoir si il existe des programmes qui permettent de dessiner sa form dans un fichier de ressource a la manière de vc++ pour les a
Dessiner une ellipse [ par Azul ]
Je dois modifier un programme VC++ pour représenter (dessiner dans une fenêtre ) des objets par des ellipses. Ces objets sont actuellement identifiés
Dessiner une ellipse [ par Azul ]
Je dois modifier un programme VC++ pour représenter (dessiner dans une fenêtre ) des objets par des ellipses. Ces objets sont actuellement identifiés
dessiner une droite [ par gus2647 ]
Bonjour,j aurais voulu savoir comment on faisait pour dessiner les droites de types suivants :1- les pointillés .....2- les ----------3- les .-.-.-.-.
dessiner des formes libres [ par nbeaumont ]
je souhaite trouver un composant qui reprendrait le principe du dessin d'une forme libre (suite de traits).je suis peut être passé à coté sans le voir
Dessiner une icone sur un toolbar [ par gagah1 ]
Comment dessine une icône ou un bitmap sur un bouton de ToolBar ,à part les 15 boutons standard prédéfinis.
Dessiner un joli cadre en C :-) [ par did2604 ]
Bonsoir,Petite question toute bête... je m'amuse à créer des cadres de présentation qui commence du style :___________________________________________
Dessiner sur tout l'ecran [ par memiks ]
Voila, je voudrais pouvoir déssiner sur tout l'écran comme si je prenais des notes avec un feutre sur mon écran.J'ai penser à creer une fenetre transp
|
Téléchargements
Logiciels à télécharger sur le même thème :
Comparez les prix Nouvelle version
|