Unit DXF_Utils

///////////////////////////////////////////////////////////////////////////// // Assorted routines for DXF project // ŠJohn Biddiscombe // Rutherford Appleton Laboratory, UK // j.biddiscombe@rl.ac.uk // DXF code release 3.0 - July 1997 // // /////////////////////////////////////////////////////////////////////////////

Classes

Functions

allocate_matrix -
allocate_points - ///////////////////////////////////////////////////////////////////////////// Memory /////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////// Memory /////////////////////////////////////////////////////////////////////////////
angle -
aPoint3D - ///////////////////////////////////////////////////////////////////////////// General point 3D stuff /////////////////////////////////////////////////////////////////////////////
BoolToStr -
CreateTransformation - Matrix order : For reference start with a point at ( cos(30),sin(30),0 ) rotate by 30 degrees - shifts point to (1,0,0) then translate by (10,0,0) shifts to (11,0,0) then rotate by -45 degrees goes to (7.
cross -
deallocate_matrix -
deallocate_points -
dist2D -
dist3D -
dmax -
dmin -
dot - ///////////////////////////////////////////////////////////////////////////// Vector 3D stuff /////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////// Vector 3D stuff /////////////////////////////////////////////////////////////////////////////
float_out - ///////////////////////////////////////////////////////////////////////////// String /////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////// String /////////////////////////////////////////////////////////////////////////////
imax -
imin -
mag -
MatrixMultiply -
max_bound - ///////////////////////////////////////////////////////////////////////////// Bounds /////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////// Bounds /////////////////////////////////////////////////////////////////////////////
min_bound -
normalize -
p1_eq_p2_2D -
p1_eq_p2_3D -
p1_minus_p2 -
p1_plus_p2 -
p1_x_n -
Point3DToStr - result := FloatToStr(f);
RotationAxis -
ScaleMatrix -
set_accuracy -
sq_dist2D -
sq_dist3D -
sq_mag3D -
TransformPoint -
TranslateMatrix -
update_transformations -
XRotateMatrix - ///////////////////////////////////////////////////////////////////////////// Rotations for Insert/Block drawing /////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////// Rotations for Insert/Block drawing /////////////////////////////////////////////////////////////////////////////
YRotateMatrix -
ZRotateMatrix -

Types

Matrix
pM
pMatrix
Point2D
Point3D
pointlist
PPoint3D
ppointlist

Constants

identity
origin3D
WCS_X
WCS_Y
WCS_Z

Variables


Functions


function allocate_matrix : pMatrix;


function allocate_points(n:integer) : ppointlist;

///////////////////////////////////////////////////////////////////////////// Memory /////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////// Memory /////////////////////////////////////////////////////////////////////////////


function angle(p1,p2,p3:Point3D; do_3D:boolean) : double;


function aPoint3D(a,b,c:double) : Point3D;

///////////////////////////////////////////////////////////////////////////// General point 3D stuff /////////////////////////////////////////////////////////////////////////////

function BoolToStr(b:boolean) : string;


function CreateTransformation(Ax,Ay,Az:Point3D) : Matrix;

Matrix order : For reference start with a point at ( cos(30),sin(30),0 ) rotate by 30 degrees - shifts point to (1,0,0) then translate by (10,0,0) shifts to (11,0,0) then rotate by -45 degrees goes to (7.77, 7.77 ,0) 7.77 = Sqrt(11^2 /2 ) NOTE THE ORDER OF MATRIX OPERATIONS ! test := aPoint3D( cos(degtorad(30)) , sin(degtorad(30)) , 0); mat := ZRotateMatrix( cos(degtorad(30)) , sin(degtorad(30)) ); mat := MatrixMultiply( mat , TranslateMatrix(aPoint3D(10,0,0)) ); mat := MatrixMultiply( mat , ZRotateMatrix( cos(degtorad(-45)) , sin(degtorad(-45)) ) ); test := TransformPoint(mat,test);

function cross(p1,p2:Point3D) : Point3D;


procedure deallocate_matrix(var m:pMatrix);


procedure deallocate_points(var pts:ppointlist; n:integer);


function dist2D(p1,p2:Point3D) : double;


function dist3D(p1,p2:Point3D) : double;


function dmax(a,b:double) : double;


function dmin(a,b:double) : double;


function dot(p1,p2:Point3D) : double;

///////////////////////////////////////////////////////////////////////////// Vector 3D stuff /////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////// Vector 3D stuff /////////////////////////////////////////////////////////////////////////////


function float_out(f:double) : string;

///////////////////////////////////////////////////////////////////////////// String /////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////// String /////////////////////////////////////////////////////////////////////////////


function imax(a,b:integer) : integer;


function imin(a,b:integer) : integer;


function mag(p1:Point3D) : double;


function MatrixMultiply(matrix1,matrix2:Matrix) : Matrix;


procedure max_bound(var bounds:Point3D; point:Point3D);

///////////////////////////////////////////////////////////////////////////// Bounds /////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////// Bounds /////////////////////////////////////////////////////////////////////////////


procedure min_bound(var bounds:Point3D; point:Point3D);


function normalize(p1:Point3D) : Point3D;


function p1_eq_p2_2D(p1,p2:Point3D) : boolean;


function p1_eq_p2_3D(p1,p2:Point3D) : boolean;


function p1_minus_p2(p1,p2:Point3D) : Point3D;


function p1_plus_p2 (p1,p2:Point3D) : Point3D;


function p1_x_n(p1:Point3D; n:double) : Point3D;


function Point3DToStr(p:Point3D) : string;

result := FloatToStr(f);

function RotationAxis(A:Point3D; angle:double) : Matrix;


function ScaleMatrix(p:Point3D) : Matrix;


function set_accuracy(factor:double; p:Point3D) : Point3D;


function sq_dist2D(p1,p2:Point3D) : double;


function sq_dist3D(p1,p2:Point3D) : double;


function sq_mag3D(p1:Point3D) : double;


function TransformPoint(TM:Matrix; p:Point3D) : Point3D;


function TranslateMatrix(p:Point3D) : Matrix;


function update_transformations(OCS_WCS,OCS:pMatrix) : pMatrix;


function XRotateMatrix(cos_a,sin_a:double) : Matrix;

///////////////////////////////////////////////////////////////////////////// Rotations for Insert/Block drawing /////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////// Rotations for Insert/Block drawing /////////////////////////////////////////////////////////////////////////////


function YRotateMatrix(cos_a,sin_a:double) : Matrix;


function ZRotateMatrix(cos_a,sin_a:double) : Matrix;


Types


Matrix = record
val : array[0..3,0..3] of double;
end;

pM      = pMatrix

pMatrix = ^Matrix

Point2D = record
x : Double;
y : Double;
end;

Point3D = record
x : double;
y : double;
z : double;
end;

pointlist  = array[0..0] of Point3D;

PPoint3D   = ^Point3D

ppointlist = ^pointlist

Constants

identity = (val:((1,0,0,0),(0,1,0,0),(0,0,1,0),(0,0,0,1)))

origin3D = (x:0; y:0; z:0)

WCS_X = (x:1; y:0; z:0)

WCS_Y = (x:0; y:1; z:0)

WCS_Z = (x:0; y:0; z:1)


Variables