I am trying to collect the most usual functions for the geometrical calculations :

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

```
normalize vAB
```

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

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

Cross Product :

```
cross vAB vAC
```

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

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

Dot Product :

```
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:

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

Point along AB : the point at 25% between A and B:

```
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:

```
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:

```
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:

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

or

```
d=distance pC (pointLineProj pA pB pC)
```

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

http://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html

Point-Line Inclusion : is this point on the line ?

```
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)