Intersection point, projection, distance, angle, ...

Of course there are many Web sites about this, but I do not seek the mathematical formulas but functions 'ready-to-use' in maxscript.

I start by giving the formulas which I know already.

If you know other formulas do not hesitate to add them.

Let's say that you have 4 points:

pA=[ax,ay,az]

pB=[bx,by,bz]

pC=[cx,cy,cz]

pD=[dx,dy,dz]

With these points you can define a vector, a line, a plane.

**Vector:**vAB=pB-pA

vAC=pC-pA

vCD=pD-pC

__Vector Normalization__: length vector = 1.0

Code:

normalize vAB

see also : Eric W. Weisstein. From MathWorld--A Wolfram Web Resource.

http://mathworld.wolfram.com/NormalizedVector.html

__Cross Product__:

Code:

cross vAB vAC

see also : Eric W. Weisstein. From MathWorld--A Wolfram Web Resource.

http://mathworld.wolfram.com/CrossProduct.html

__Dot Product__:

Code:

dot vAB vAC dot (normalize vAB) (normalize vAC)

see also : Eric W. Weisstein. From MathWorld--A Wolfram Web Resource.

http://mathworld.wolfram.com/DotProduct.html

**line:**A line can be defined :

- by 2 points

- or by 1 point and 1 vector

__Middle Point__M of AB:

Code:

fn middlePoint pA pB = ((pA+pB)/2.0)

__Point along AB__: the point at 25% between A and B:

Code:

fn alongPoint pA pB prop = (pA+((pB-pA)*prop))

**plane:**A plane can be defined :

- by 3 points

- or by 1 point and 2 vectors

- or by 1 point and 1 vector (the normal vector)

__Normal Vector__: the vector perpendicular to the plane:

Code:

normalVector=normalize (cross vAB vAC)

see also : Eric W. Weisstein. From MathWorld--A Wolfram Web Resource.

http://mathworld.wolfram.com/NormalVector.html

**line and point:**__Point-Line Projection__: find the point on the line AB which is the projection of the point C:

Code:

fn pointLineProj pA pB pC = ( local vAB=pB-pA local vAC=pC-pA local d=dot (normalize vAB) (normalize vAC) (pA+(vAB*(d*(length vAC/length vAB)))) )

__Point-Line Distance__: the distance between the line AB and the point C:

Code:

fn pointLineDist2 pA pB pC = ( local vAB=pB-pA local vAC=pC-pA (length (cross vAB vAC))/(length vAB) )

or

Code:

d=distance pC (pointLineProj pA pB pC)

see also : Eric W. Weisstein. From MathWorld--A Wolfram Web Resource.

http://mathworld.wolfram.com/Point-...imensional.html

__Point-Line Inclusion__: is this point on the line ?

Code:

fn isPointLine pA pB pC tol = ( local vAB=pB-pA local vAC=pC-pA local d=1.0-abs(dot (normalize vAB) (normalize vAC)) if d<=tol then true else false )

or Point-Line Distance <= tolerance distance

(to be continued)