PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Berechnung eines Rechtecks fuer den Bildschirm



Gsus
27-06-2007, 10:56
Hallo an alle,

so eigentlich nicht so schwer sollte man meinen :(

Ich habe zwei Punkte die eine Linie ergeben. Nun will ich nicht eine Linie haben sonder ich moechte die Linie dick machen also errechne ich mir eine Huelle in form eines rechtecks. Das funktioniert auch prima. Nur wird je nach winkel der Linie die der Streifen dann dicker oder duener. Was ja wahrscheinlich daran liegt das ich mit Pixel arbeite die ja in der diagonalen laenger sind als ind der horizontalen oder in der vertikalen.

Hier meine berechnung:



static point** calculate_hull( point *p, int cnt_p, double fac )
{
double vx, vy, exc, scalar;

point **res = NULL;
res = (void *)calloc( 2, sizeof( void * ));
if(res == NULL)
{
fprintf( stderr, "Error while memory allocation \n" );
return NULL;
}
res[0] = (point *)calloc( 2, sizeof( point ));
if(res[0] == NULL)
{
fprintf( stderr, "Error while memory allocation \n" );
return NULL;
}
res[1] = (point *)calloc( 2, sizeof( point ));
if(res[1] == NULL)
{
fprintf( stderr, "Error while memory allocation \n" );
return NULL;
}



/* calculate scalar and vector for the direction */
vx = (double) p[cnt_p].x - p[cnt_p-1].x;
vy = (double) p[cnt_p].y - p[cnt_p-1].y;
exc = vx; vx = vy; vy = exc;
scalar = sqrt( vx * vx + vy * vy );
if (scalar == 0)
return NULL;

vx = vx / scalar * fac;
vy = vy / scalar * fac;

/* for the first point */
res[0][0].x = -vx + p[cnt_p-1].x;
res[0][0].y = vy + p[cnt_p-1].y;
res[0][1].x = vx + p[cnt_p-1].x;
res[0][1].y = -vy + p[cnt_p-1].y;

/* for the end poin */
res[1][0].x = -vx + p[cnt_p].x;
res[1][0].y = vy + p[cnt_p].y;
res[1][1].x = vx + p[cnt_p].x;
res[1][1].y = -vy + p[cnt_p].y;

return res;



Ich mache dann Lienen um die Huelle mit nem Gupta und Sproull Antialias Algorithmus und Fuelle es dann mit Scanline. Prinzipiell sollte es also gehen. Will aber nicht wie oben beschrieben von mir vermutet. Jemand ne Idee sitze nun schon seit einem Monat an dem Problem.

Hoffe von euch zu hoeren.

Mfg

gsus

Wenn ich im Falschen Thread oder Forum bin sorry hoffe das ich hier richtig bin.