Professional Documents
Culture Documents
type
tdPoint= record x,y,z:double; end;
tdLine= record Point1,Point2:tdPoint; end;
tdArc= record Center:tdPoint; r,sa,ea:double; end;
const
RADIANS=57.29577951;
Find Distance Between Two Points:
function distance2d(x1,y1,x2,y2:double):double;
var a,b,c:double;
begin
a:=abs(x1-x2);
b:=abs(y1-y2);
c:=sqr(a)+sqr(b);
if c>0 then result:=sqrt(c) else result:=0;
end;
function distance3d(x1,y1,z1,x2,y2,z2:double):double;
var c:double;
begin
c:=sqr(abs(x1-x2))+sqr(abs(y1-y2))+sqr(abs(z1-z2));
if c>0 then result:=sqrt(c) else result:=0;
end;
angle:=get_angle_degrees(line1.point1.x,line1.point1.y,line1.point2.x,line1.point2.
y);
arc1.center.x:=pick_point.x;
arc1.center.y:=pick_point.y;
arc1.center.z:=pick_point.z;
arc1.r:=1;
temp_point:=point_arc_angle(arc1,angle+90);
line_2_points(pick_point,temp_point,TDLine2);
point_inter_2_lines(line1,TDLine2,return_point);
end;
Offset a Line
function offset_line(orig_line:TDLine;dist:double;pick_point:TDPoint):TDLine);
var angle1:double;
temp_point,new_end_point1,new_end_point2:TDPoint;
temp_line:T2DLine;
temp_circle:TDArc;
begin
get_closest_point_line(orig_line,pick_point,temp_point);
temp_line.point1:=temp_point;
temp_line.point2:=pick_point;
angle1:=get_angle_line(temp_line);
temp_circle.center:=orig_line.point1;
temp_circle.r:=dist;
point_arc_angle(temp_circle,angle1,new_end_point1);
temp_circle.center:=orig_line.point2;
point_arc_angle(temp_circle,angle1,new_end_point2);
new_line.point1:=new_end_point1;
new_line.point2:=new_end_point2;
end;
Find Point at the Intersection of Two Lines
function point_inter_2_lines(line1,line2:TDLine;var point1:TDPoint):integer;
var x1_start,y1_start,x1_end,y1_end,
x2_start,y2_start,x2_end,y2_end,
k1,b1,k2,b2:double;
ka,xa,xb:double;
begin
point_inter_2_lines:=0;
x1_start:=line1.point1.x;
y1_start:=line1.point1.y;
x1_end:=line1.point2.x;
y1_end:=line1.point2.y;
x2_start:=line2.point1.x;
y2_start:=line2.point1.y;
x2_end:=line2.point2.x;
y2_end:=line2.point2.y;
xa:=(x1_start-x1_end);
if abs(xa)<0.000001 then
begin
xa:=0.000001;
end;
k1:=(y1_start-y1_end)/xa;
b1:=(y1_start-(k1*x1_start));
xb:=(x2_start-x2_end);
if abs(xb)<0.000001 then
begin
xb:=0.000001;
end;
k2:=(y2_start-y2_end)/xb;
b2:=(y2_start-(k2*x2_start));
ka:=(k1-k2);
if ka=0.0 then begin point_inter_2_lines:=902;{Parallel Lines} exit; end;
if abs(ka)<0.000001 then
begin
ka:=0.000001;
end;
point1.x :=(b2-b1)/ka;
point1.y:=(k1*point1.x)+b1;
end;
function line_2_points(point1,point2:TDPoint;var line1:TDLine):integer;
begin
if (point1.x=point2.x)and(point1.y=point2.y)then line_2_points:=903{undefined
line} else line_2_points:=0;
line1.point1.x:=point1.x;
line1.point1.y:=point1.y;
line1.point1.z:=point1.z;
line1.point2.x:=point2.x;
line1.point2.y:=point2.y;
line1.point2.z:=point2.z;
end;
Find Sides and Angles of Right Triangle
Right Triangle
A:=arccos(b/c) * RADIANS;
To find angle B:
B:=arctan(b/a) * RADIANS;
B:=arcsin(b/c) * RADIANS;
B:=arccos(a/c) * RADIANS;