Fw: Algoritmus: usecka, kruznice
Milan
milger@pobox.sk
Sobota Září 1 17:51:06 CEST 2007
----- Original Message -----
From: "Milan" <milger@pobox.sk>
To: "HW-news" <hw-list@list.hw.cz>
Sent: Saturday, September 01, 2007 5:13 PM
Subject: Re: Algoritmus: usecka, kruznice
> Dovolim si len tak pre inspiraciu usecku:
>
> DRAW_LINE(unsigned char x1, unsigned char y1,
> unsigned char x2, unsigned char y2)
> {
> char kvadrant;
> int x,y,dx,dy;
> int plus,minus,pos,steps;
> dx = (int)x2 - (int)x1;
> dy = (int)y2 - (int)y1;
> if (abs(dx)<abs(dy)) kvadrant = 1; //kvadrant
> else kvadrant = 0;
> if (dx<0) kvadrant = kvadrant + 2;
> if (dy<0) kvadrant = kvadrant + 4;
> steps = abs(dx) + abs(dy); //number steps
> switch (kvadrant)
> {
> case 0:
> pos = (2*dy-dx);
> plus = 2*(dy-dx);
> minus = 2*dy;
> break;
> case 1:
> pos = (2*dx-dy);
> plus = 2*(dx-dy);
> minus = 2*dx;
> break;
> case 2:
> pos = (2*dy+dx);
> plus = 2*(dy+dx);
> minus = 2*dy;
> break;
> case 3:
> pos = (2*(-dx)-dy);
> plus = 2*((-dx)-dy);
> minus = 2*(-dx);
> break;
> case 4:
> pos = (2*(-dy)-dx);
> plus = 2*((-dy)-dx);
> minus = 2*(-dy);
> break;
> case 5:
> pos = (2*dx+dy);
> plus = 2*(dx+dy);
> minus = 2*dx;
> break;
> case 6:
> pos = (2*(-dy)+dx);
> plus = 2*((-dy)+dx);
> minus = 2*(-dy);
> break;
> case 7:
> pos = (2*(-dx)+dy);
> plus = 2*((-dx)+dy);
> minus = 2*(-dx);
> break;
> }
> x = x1;
> y = y1;
> PUT_PIXEL(x,y);
> while (steps) //step at kvadrant
> {
> switch (kvadrant)
> {
> case 0:
> if (pos>=0) y++;
> x++;
> break;
> case 1:
> if (pos>=0) x++;
> y++;
> break;
> case 2:
> if (pos>=0) y++;
> x--;
> break;
> case 3:
> if (pos>=0) x--;
> y++;
> break;
> case 4:
> if (pos>=0) y--;
> x++;
> break;
> case 5:
> if (pos>=0) x++;
> y--;
> break;
> case 6:
> if (pos>=0) y--;
> x--;
> break;
> case 7:
> if (pos>=0) x--;
> y--;
> break;
> }
> PUT_PIXEL(x,y); //draw pixel
> if (pos>=0) //next step
> {
> pos = pos+plus;
> steps--;
> }
> else
> pos = pos+minus;
> steps--;
> }
> }
>
>
>
> Milan
>
>
> ----- Original Message -----
> From: "Va Sm" <SpiritusII@seznam.cz>
> To: <hw-list@list.hw.cz>
> Sent: Saturday, September 01, 2007 12:09 PM
> Subject: Algoritmus: usecka, kruznice
>
>
> Dobry den,
> hledam vhodny(efektivni) algoritmus pro vykresleni usecky (zadano dvema
> body) a kruznice. Jde mi o implementaci do jednocipu, idelane v C.
> Poradite?
>
> V. Smidl
> _______________________________________________
> HW-list mailing list - sponsored by www.HW.cz
> Hw-list@list.hw.cz
> http://list.hw.cz/mailman/listinfo/hw-list
>
>
>
>
>
Další informace o konferenci Hw-list