Geometrical calculations : points, lines, planes : intersections, distances, angles


Hi Klvnk,

very interesting functions. As i’m not familiar with geometry data structure, can you please give a usage example ?
How to build a struct vertex for any given mesh ?
I was thinking about that :

- sm = snapshotasmesh (Teapot())
- loop through each vert and get :
    p = meshop.getvert sm v
    n = getnormal sm v
    col = -- vertex color ?
    uvw1 = getTVert sm <tvert_index_integer> -- how to get tvert from current vert ?
- build array of faces indices :
    fi = for f=1 to sm.numfaces collect ((meshop.getVertsUsingFace sm f) as array)
- once i got my vertex array struct, i can call your functions :
ComputeTangents myVertStruct fi

Sorry if i bother with noob question


yep that kind of thing will do it, I’ll start a new thread with an example.

yep that kind of thing will do it, I'll start a new thread with an example.

thanks !


randomize a normal…


simple but was quite tricky to find…

pos is the position of the base of the cone and pnt is the position of the point on the cone, r & h are the radius and height respectively


:thumbsup: :applause: :applause:


I apparently annoyed the wrong people on stackoverflow so perhaps i’ll get more joy here. If I have a plane in the YZ plane and want to project it onto a sphere, what equation do I use for the X axis?


one more modification :wink:

fn rotatePointAroundCenter center dir radius steps:8 debug:false = (

	local tm = (matrixFromNormal dir)
	local p = center+(tm.row1*radius)
	local div = 360/steps
	local points = for i = 0 to (360 - div) by div collect (

		local q = quat i (normalize dir)
		(((p - center ) * q) + center)
	if debug do for p in points do point pos:p dir:dir wirecolor:green
rotatePointAroundCenter $Box011.pos $Box011.dir 20 debug:true