Ok i solved it. If anyone needs a function to check the angle between triangles, or rather the angle between the normals of two triangles, it is contained in there.
I would have spent much more time if it wasn't for you
Stevie G, so thanks again.
I'm not sure this is useful enough to post it in the code archives :)
;Checks the angle between (normals of) two triangles.
;By Braincell, February 2006
;
;Note: If you dont want them to share 2 vertices you can modify the function
;to take 6 verts and calculate the cross prodcut accordingly, ie instead of
;v123 and v432 that is there now, have v123, v456 cross products.
;
;This function was made to be part of the stencil shadow system
Graphics3D 800,600,0,2
;3.bb >> final version with function
Global vectorx#
Global vectory#
Global vectorz#
Global vectorw#
Const UPS=60
cam=CreateCamera()
PositionEntity cam, 0,5,-15
l=CreateLight()
period=1000/UPS
time=MilliSecs()-period
v1=CreateSphere()
ScaleEntity v1,0.5,0.5,0.5
v2=CreateSphere()
ScaleEntity v2,0.5,0.5,0.5
v3=CreateSphere()
ScaleEntity v3,0.5,0.5,0.5
v4=CreateSphere()
ScaleEntity v4,0.5,0.5,0.5
;cp1=CreateSphere();cross product marker
;ScaleEntity cp1,0.5,0.5,0.5
;EntityColor cp1, 0,0,250
;cp2=CreateSphere()
;ScaleEntity cp2,0.5,0.5,0.5
;EntityColor cp2, 0,0,250
smesh = CreateMesh()
ssurf = CreateSurface(smesh)
v1x#=-6;left
v1y#=4
v1z#=2
v2x#=0;middle front
v2y#=1
v2z#=4
v3x#=0;middle back
v3y#=1
v3z#=0
v4x#=6;right
v4y#=1
v4z#=2
v1v = AddVertex (ssurf, v1x,v1y,v1z)
v2v = AddVertex (ssurf, v2x,v2y,v2z)
v3v = AddVertex (ssurf, v3x,v3y,v3z)
v4v = AddVertex (ssurf, v4x,v4y,v4z)
AddTriangle (ssurf, v1v,v2v,v3v)
AddTriangle (ssurf, v2v,v4v,v3v)
PositionEntity v1, v1x,v1y,v1z
PositionEntity v2, v2x,v2y,v2z
PositionEntity v3, v3x,v3y,v3z
PositionEntity v4, v4x,v4y,v4z
.mainloop
Repeat
Repeat
elapsed=MilliSecs()-time
Until elapsed
ticks=elapsed/period
tween#=Float(elapsed Mod period)/Float(period)
msp# = 0.2
;WASDFC moves the camera
If KeyDown(17) Then MoveEntity cam, 0,0,msp
If KeyDown(31) Then MoveEntity cam, 0,0,-msp
If KeyDown(33) Then MoveEntity cam, 0,msp,0
If KeyDown(46) Then MoveEntity cam, 0,-msp,0
If KeyDown(32) Then MoveEntity cam, msp,0,0
If KeyDown(30) Then MoveEntity cam, -msp,0,0
If KeyDown (203) Then TurnEntity cam, 0,msp*5,0
If KeyDown (205) Then TurnEntity cam, 0,-msp*5,0
If KeyDown (200) Then TurnEntity cam, msp*5,0,0
If KeyDown (208) Then TurnEntity cam, -msp*5,0,0
;Insert, Delete, Home, End, PgUP, PgDN moves the vertex
If KeyDown (199) Then v4y = v4y + msp
If KeyDown (207) Then v4y = v4y - msp
If KeyDown (210) Then v4z = v4z + msp
If KeyDown (201) Then v4z = v4z - msp
If KeyDown (209) Then v4x = v4x + msp
If KeyDown (211) Then v4x = v4x - msp
;update verts
VertexCoords ssurf, v4v,v4x,v4y,v4z
;update spheres representing verts
PositionEntity v1, v1x,v1y,v1z
PositionEntity v2, v2x,v2y,v2z
PositionEntity v3, v3x,v3y,v3z
PositionEntity v4, v4x,v4y,v4z
af# = AngleBetweenTriangles#(v1x#,v1y#,v1z#,v2x#,v2y#,v2z#,v3x#,v3y#,v3z#,v4x#,v4y#,v4z#)
If af# < 180.0 Then
txt$ = "No edge."
Else
txt$ = "Edge."
End If
;update the cross product results (places blue spheres at CP result)
;PositionEntity cp1, v1x+t1vx,v1y+t1vy,v1z+t1vz ;values moved to function
;PositionEntity cp2, v4x+t2vx,v4y+t2vy,v4z+t2vz
For k=1 To ticks
time=time+period
If KeyHit(1) End
UpdateWorld
Next
RenderWorld tween
Color 255,255,255
Text 10,10, txt
Text 10,25, "Angle: " + af
Flip
Forever
Function TriangleNormal#(Ax#,Ay#,Az#,Bx#,By#,Bz#,Cx#,Cy#,Cz#)
SubVector Bx#,By#,Bz#,Ax#,Ay#,Az#
ux#=VectorX()
uy#=VectorY()
uz#=VectorZ()
SubVector Cx#,Cy#,Cz#,Bx#,By#,Bz#
vx#=VectorX()
vy#=VectorY()
vz#=VectorZ()
CrossProduct vx#,vy#,vz#,ux#,uy#,uz#
;Normalize vectorx,vectory,vectorz
Return Ax#*vectorx+Ay#*vectory+Az#*vectorz
End Function
Function VectorX#()
Return vectorx
End Function
Function VectorY#()
Return vectory
End Function
Function VectorZ#()
Return vectorz
End Function
Function VectorW#()
Return vectorw
End Function
Function SubVector(Ax#,Ay#,Az#,Bx#,By#,Bz#)
vectorx#=ax#-bx#
vectory#=ay#-by#
vectorz#=az#-bz#
End Function
Function Normalize(nx#,ny#,nz#)
If nx=0 And ny=0 And nz=0 Return
m#=Magnitude(nx#,ny#,nz#)
vectorx#=nx#/m#
vectory#=ny#/m#
vectorz#=nz#/m#
End Function
Function CrossProduct(Ax#,Ay#,Az#,Bx#,By#,Bz#)
vectorx#=Ay#*Bz#-Az#*By#
vectory#=Az#*Bx#-Ax#*Bz#
vectorz#=Ax#*By#-Ay#*Bx#
End Function
Function Magnitude(nx#,ny#,nz#)
m#= Sqr( (nx*nx) + (ny*ny) + (nz*nz) )
Return m#
End Function
Function AngleBetweenTriangles#(v1x#,v1y#,v1z#,v2x#,v2y#,v2z#,v3x#,v3y#,v3z#,v4x#,v4y#,v4z#)
ax#=v1x-v2x
ay#=v1y-v2y
az#=v1z-v2z
bx#=v1x-v3x
by#=v1y-v3y
bz#=v1z-v3z
CrossProduct(ax,ay,az,bx,by,bz)
t1vx#=vectorx/3
t1vy#=vectory/3
t1vz#=vectorz/3
ax#=v4x-v3x
ay#=v4y-v3y
az#=v4z-v3z
bx#=v4x-v2x
by#=v4y-v2y
bz#=v4z-v2z
CrossProduct(ax,ay,az,bx,by,bz)
t2vx#=vectorx/3
t2vy#=vectory/3
t2vz#=vectorz/3
px# = t1vx
py# = t1vy
pz# = t1vz
qx# = t2vx
qy# = t2vy
qz# = t2vz
MagP# = Sqr( px * px + py * py + pz * pz )
MagQ# = Sqr( qx * qx + qy * qy + qz * qz )
Theta1# =ACos ( ( px*qx + py*qy + pz*qz ) / ( MagP * MagQ ) )
;move refference point by 1000th of cross product and check the change ---- <<< solution
t2mx# = t2vx / 1000.0
t2my# = t2vy / 1000.0
t2mz# = t2vz / 1000.0
v4bx# = v4x + t2mx
v4by# = v4y + t2my
v4bz# = v4z + t2mz
ax#=v4bx-v3x
ay#=v4by-v3y
az#=v4bz-v3z
bx#=v4bx-v2x
by#=v4by-v2y
bz#=v4bz-v2z
CrossProduct(ax,ay,az,bx,by,bz)
t2bvx#=vectorx/3
t2bvy#=vectory/3
t2bvz#=vectorz/3
qx# = t2bvx
qy# = t2bvy
qz# = t2bvz
MagP# = Sqr( px * px + py * py + pz * pz )
MagQ# = Sqr( qx * qx + qy * qy + qz * qz )
Theta2# = ACos ( ( px*qx + py*qy + pz*qz ) / ( MagP * MagQ ) )
If Theta2 < Theta1 Then
actualangle# = Theta1 + 180
Else
actualangle# = 180 - Theta1
End If
Return actualangle#
End Function