home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1998 March
/
Chip_1998-03_cd.bin
/
tema
/
MINICAD
/
MC7DEMO
/
MINICAD.1
/
OFFSET.MPC
< prev
next >
Wrap
Text File
|
1997-04-30
|
4KB
|
226 lines
Procedure DrawCurve;
LABEL 99;
CONST
MaxPoints = 10;
ec = 0.25;
VAR
a,b1,b2,e,L,r11,r12,Phi1,Theta1 : REAL;
c1,c2,h1,h2,r21,r22,Phi2,Theta2 : REAL;
hMin,p1,p2,q1,q2 : REAL;
x0,y0,x11,y11,x12,y12 : REAL;
x21,y21,x22,y22,Alpha : REAL;
x,y,xp,yp,R : ARRAY[1..MaxPoints] OF REAL;
k, nPoints : INTEGER;
Procedure Swap(VAR v1,v2:REAL);
VAR
Temp : REAL;
BEGIN
Temp:=v1;
v1:=v2;
v2:=Temp;
END;
Procedure DrawPolyPoint(x,y,R : REAL);
{
This procedure draws a polyline point based on the value of R:
R = 0 ==> Corner point
R > 0 ==> Arc point of radius, R
R = -1 ==> Cubic spline point
R = any value less than 0 except -1
==> Bezier control point
}
BEGIN
IF R = 0 THEN
LineTo(x,y)
ELSE IF R > 0 THEN
ArcTo(x,y,R)
ELSE IF R = -1 THEN
CurveThrough(x,y)
ELSE
CurveTo(x,y);
END; {of DrawPolyPoint}
Function xt(x,y,x0,y0,Alpha:REAL) : REAL;
{
This function transforms the x-coordinate of a point relative to the x,y axis to an axis passing through x0,y0 at an angle, Alpha.
}
VAR
A : REAL;
BEGIN
A:=Deg2Rad(Alpha);
xt:=x0 + x*Cos(A) - y*Sin(A);
END; {of Function xt}
Function yt(x,y,x0,y0,Alpha:REAL) : REAL;
{
This function transforms the y-coordinate of a point relative to the x,y axis to an axis passing through x0,y0 at an angle, Alpha.
}
VAR
A : REAL;
BEGIN
A:=Deg2Rad(Alpha);
yt:=y0 + y*Cos(A) + x*Sin(A);
END; {of Function yt}
{
Main program.
}
BEGIN
DSelectAll;
{
Get insertion point of object and dimensions a, b, h1, and h2.
}
Message('Draw side A');
GetPt(x11,y11);
GetPtL(x11,y11,x12,y12);
IF y11 < y12 THEN Swap(y11,y12);
Message('Draw side B');
GetPt(x21,y21);
GetPtL(x21,y21,x22,y22);
IF y21 < y22 THEN Swap(y21,y22);
IF x21 < x11 THEN
BEGIN
Swap(x21,x11);
Swap(y11,y21);
Swap(y12,y22);
END;
x0:=x11;
y0:=y11;
{
Get angle of object with respect to x-axis (optional).
GetPtL(x1,y1,x2,y2);
IF (x1 = x2) AND (y1 = y2) THEN GOTO 99;
L:=Distance(x1,y1,x2,y2);
Alpha:=Rad2Deg(ArcCos((x2-x1)/L));
IF y2 < y1 THEN Alpha:=360 - Alpha;}
a:=x21-x11;
b1:=y11-y21;
h1:=y11-y12;
h2:=y21-y22;
e:=ec;
Message(a,' ',b1,' ',h1,' ',h2);
hMin:=h1;
IF h2 < hMin THEN hMin:=h2;
c1:=Sqrt(a^2 + b1^2);
Phi1:=ArcSin(b1/c1);
IF b1 <> 0 THEN
BEGIN
r11:=hMin/2 + e*c1/Sin(Phi1);
r12:=(a^2 + b1^2)/(2*b1) - r11;
Theta1:=ArcSin(a/(r11+r12));
END ELSE
BEGIN
r11:=0;
r12:=0;
Theta1:=0;
END;
p1:=r11*Tan(Theta1/2);
q1:=r12*Tan(Theta1/2);
b2:=b1+h2-h1;
c2:=Sqrt(a^2 + b2^2);
Phi2:=ArcSin(b2/c2);
IF b2 <> 0 THEN
BEGIN
r21:=hMin/2 + e*c2/Sin(Phi2);
r22:=(a^2 + b2^2)/(2*b2) - r21;
Theta2:=ArcSin(a/(r21+r22));
END ELSE
BEGIN
r21:=0;
r22:=0;
Theta2:=0;
END;
p2:=r21*Tan(Theta2/2);
q2:=r22*Tan(Theta2/2);
{
Calculate the coordinates of the poly points relative to the insertion point of the object (x0,y0) at an angle of Alpha=0.
}
nPoints:=10;
x[1]:=0;
y[1]:=0;
R[1]:=0;
x[2]:=p1;
y[2]:=0;
R[2]:=r11;
x[3]:=p1*(1+Cos(Theta1));
y[3]:=-p1*Sin(Theta1);
R[3]:=0;
x[4]:=a-q1;
y[4]:=-b1;
R[4]:=r12;
x[5]:=a;
y[5]:=-b1;
R[5]:=0;
x[6]:=a;
y[6]:=-(b1+h2);
R[6]:=0;
x[7]:=a-p2;
y[7]:=y[6];
R[7]:=r21;
x[8]:=a-p2*(1+Cos(Theta2));
y[8]:=y[6]+p2*Sin(Theta2);
R[8]:=0;
x[9]:=q2;
y[9]:=-h1;
R[9]:=r22;
x[10]:=0;
y[10]:=-h1;
R[10]:=0;
{
Calculate the points relative to the x and y axis of the drawing (0,0) and, if appropiate, adjust for any rotation (Alpha).
}
FOR k:=1 TO nPoints DO
BEGIN
xp[k]:=xt(x[k],y[k],x0,y0,Alpha);
yp[k]:=yt(x[k],y[k],x0,y0,Alpha);
END;
{
Move to the absolute coordinates of the first point and draw the polyline.
}
Absolute;
MoveTo(x0,y0);
ClosePoly;
BeginPoly;
FOR k:=1 TO nPoints DO
DrawPolyPoint(xp[k],yp[k],R[k]);
EndPoly;
99:END; {of Main program}
RUN(DrawCurve);