|
![](/i/fill.gif) |
I've been where you are chasing down formulas for my Polygon/Prism c++
program. I don't know where I got my first parametric equations from
(they where not perfect) I had to play with them until I got something
close to what POV prisms does. Of course prisms uses 4 types of splines
linear, quadratic, cubic and bezier. I have the formulas for the last 3.
void PCanvasPane :: ConDraw(point P,point P1, point P2, point P3)
{ double a_x,b_x,c_x,d_x,a_y,b_y,c_y,d_y,t;
int Xp,Yp,Ox,Oy;
if (Spl == 3)
{ a_x = P.x-3*P1.x+3*P2.x -P3.x; a_y = P.y-3*P1.y+3*P2.y
-P3.y;
b_x = 3*P1.x-6*P2.x+3*P3.x; b_y = 3*P1.y-6*P2.y+3*P3.y;
c_x = 3*P2.x-3*P3.x; c_y =
3*P2.y-3*P3.y;
d_x = P3.x; d_y = P3.y;
}
if (Spl == 2)
{a_x=-.5*P.x+1.5*P1.x-1.5*P2.x+.5*P3.x;
a_y=-.5*P.y+1.5*P1.y-1.5*P2.y+.5*P3.y;
b_x= P.x-2.5*P1.x+2.0*P2.x-.5*P3.x; b_y=
P.y-2.5*P1.y+2.0*P2.y-.5*P3.y;
c_x=-.5*P.x +.5 *P2.x; c_y=-.5*P.y
+.5 *P2.y;
d_x= P1.x; d_y= P1.y;
}
if (Spl == 1)
{a_x=0; a_y=0;
b_x= .5*P.x-P1.x+.5*P2.x; b_y= .5*P.y-P1.y+.5*P2.y;
c_x=-.5*P.x +.5*P2.x; c_y=-.5*P.y +.5*P2.y;
d_x= P1.x; d_y= P1.y;
}
t = 0;
do{
/*if(Spl == 3 || Spl==2){
Xp = ax*pow(t,3) + bx*pow(t,2) + dx * t + P.x;// X function
Yp = ay*pow(t,3) + by*pow(t,2) + dy * t + P.y;// Y function
}
Xp = a_x*pow(t,3) + b_x*pow(t,2) + c_x * t + d_x;// X funtion
Yp = a_y*pow(t,3) + b_y*pow(t,2) + c_y * t + d_y;// Y funtion
if (t>0) DrawLine (Xp*Dx+cx,Yp*Dy+cy,Ox,Oy);
Ox=Xp*Dx+cx;
Oy=Yp*Dy+cy;
t+=.005;}
while (t <= 1);
}
Here is what used. Hope it helps.
Spl means spline; 3 is bezier 2 is cubic 1 is cubic
You'll need to play with until you get what you want!
Have Fun!
Post a reply to this message
|
![](/i/fill.gif) |