Geometric functions

From Tech Artists Wiki

Jump to: navigation, search

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.

Contents

[edit] Vector

  • vAB = pB - pA
  • vAC = pC - pA
  • vCD = pD - pC

[edit] Vector Normalization

length vector = 1.0
normalize vAB

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

[edit] Cross Product

cross vAB vAC

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

[edit] Dot Product

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

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


[edit] Line

A line can be defined :

  • by 2 points
  • or by 1 point and 1 vector

[edit] Middle Point

M of AB:

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

[edit] Point along AB

the point at 25% between A and B:

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


[edit] 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)

[edit] Normal Vector

the vector perpendicular to the plane:

normalVector=normalize (cross vAB vAC)

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

[edit] Line and Point

[edit] 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))))
)

[edit] 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


[edit] 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

[edit] Line and Line

[edit] Line-Line Intersection

Intersection of two lines AB and CD

fn lineLineIntersect pA pB pC pD =
(
	local a=pB-pA
	local b=pD-pC
	local c=pC-pA
	local cross1 = cross a b
	local cross2 = cross c b
	pA + ( a*( (dot cross2 cross1)/((length cross1)^2) ) )
)

or by using vectors:

fn lineLineIntersect pA a pB b = (
	local c=pB-pA
	local cross1 = cross a b
	local cross2 = cross c b
	pA + ( a*( (dot cross2 cross1)/((length cross1)^2) ) )
	)

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

[edit] Line-Line Distance

Distance between two skew lines

fn lineLineDist pA a pB b =
(
	local c=pB-pA
	local crossAB=cross a b
	abs (dot c crossAB) / (length crossAB)
)

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

[edit] Line-Line // Distance

Distance between two parallel lines

use "Point-Line Distance" : pA-pB is the first line and pC is a point of the second line

[edit] Line-Line Angle

Angle between two lines:

fn getVectorsAngle vAB vCD =
(
	acos (dot (normalize vAB) (normalize vCD))
)

or

fn lineLineAngle pA pB pC pD =
(
	local vAB=pB-pA
	local vCD=pD-pC
	local angle=acos (dot (normalize vAB) (normalize vCD))
	if angle<90.0 then angle else (180.0-angle)
)

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

[edit] Plane and Point

[edit] Point-Plane Projection

Find the point on the plane ABC which is the projection of the point D

fn pointPlaneProj pA pB pC pD =
(
	local nABC=normalize (cross (pB-pA) (pC-pA))
	pD+((dot (pA-pD) nABC)*nABC)
)

[edit] Point-Plane Distance

Find the distance between a plane and a point

fn pointPlaneDist pA pB pC pD =
(
	local nABC=normalize (cross (pB-pA) (pC-pA))
	length ((dot (pA-pD) nABC)*nABC)
)

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

[edit] Plane and Line

[edit] Line-Plane Intersection

Intersection between a line and a plane

fn planeLineIntersect planePoint planeNormal linePoint lineVector =
(
	local lineVector=normalize lineVector
	local d1=dot (planePoint-linePoint) planeNormal
	local d2=dot lineVector planeNormal
	if abs(d2)<.0000000754 then ( if abs(d1)>.0000000754 then 0 else -1 )
		else ( linePoint + ( (d1/d2)*lineVector ) )
)

This script is based on an original script of Joshua Newman.

return 0 for parrallel (no intersections) results
and -1 for co-incident (infinate) results

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

[edit] Line-Plane Distance

Distance between a plane and a line //

use "Point-Plane Distance" : where 'point' is a point of the line

[edit] Vector perpendicular to a line into a Plane

The perpendicular of AB into the plane ABC

vectorPerp = cross vectorAB (cross vectorAB vectorAC)

or

vectorPerp = cross (cross vectorAB vectorAC) vectorAB[/CODE]

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

Personal tools