Accueil > > > CERCLE DISCRET (POINT PAR POINT) EN C++
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
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
|
Derniers Blogs
SESSION SILVERLIGHT 5 3D : SLIDES ET DEMOSSESSION SILVERLIGHT 5 3D : SLIDES ET DEMOS par Groc
Durant les techdays, j'ai eu le plaisir d'animer une session sur Silverlight 5 et la 3D avec Simon Ferquel. Comme promis, voici nos slides et mes démos (celles avec le viper BSG) ici et là. Pour mémoire, les démos utilisent toutes le viper BSG...
Cliquez pour lire la suite de l'article par Groc [TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES[TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES par gpommier
Suite à la session que j'ai présenté sur WebMatrix 2, vous pouvez trouver les slides ici, ainsi que les démos en packages nuget : démos1 et démos2 J'en profite pour remercier chaleureusement tous ceux qui sont venus très nombreux à cette sess...
Cliquez pour lire la suite de l'article par gpommier [SHAREPOINT] LES SESSIONS TECHDAYS 2012.[SHAREPOINT] LES SESSIONS TECHDAYS 2012. par Patrick Guimonet
Voici donc pour ceux qui n'ont pas pu venir, ou ceux qui n'ont pas pu toutes les suivre la liste des sessions SharePoint aux TechDays 2012, que je mettrais à jour dès que les liens des vidéo seront disponibles. Ou ici : http...
Cliquez pour lire la suite de l'article par Patrick Guimonet TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3 par ROMELARD Fabrice
Speaker: Bernard Ourghanlian Cette session est comme chaque jour transmise en live par BrainSonic, et j'ai donc suivi cette troisième pleinière par ce moyen sur mon iPad . Elle est dédiée comme chaque année à la mise en perspective de l'é...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice MISHRA READER : UN LECTEUR RSS TRèS ZUNE STYLE EN OPEN SOURCE !MISHRA READER : UN LECTEUR RSS TRèS ZUNE STYLE EN OPEN SOURCE ! par Vko
Hier durant une session dédiée aux Techdays 2012, j'ai eu le plaisir d'annoncer la sortie de la Béta 2 de Mishra Reader. C'est quoi ? Pour les utilisateurs, c'est une vraie expérience de lecture de flux RSS sur Windows. Rien à voir avec les produit...
Cliquez pour lire la suite de l'article par Vko
Logiciels
Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning
|