Nicholas Randall Forystek
unread,Aug 24, 2016, 5:16:42 AM8/24/16You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
Public Type Vector3D
X As Single
Y As Single
Z As Single
End Type
Public Declare Function VertexPoint_Behind_TrianglePlane Lib
"maxlandlib.dll" Alias "PointBehindPoly" _
(ByVal VertexPointX As Single, ByVal VertexPointY As
Single, ByVal VertexPointZ As Single, _
ByVal TrianglePlaneNormalX As Single, ByVal
TrianglePlaneNormalY As Single, ByVal TrianglePlaneNormalZ As Single, _
ByVal TriangleSideLength1 As Single, ByVal
TriangleSideLength2 As Single, ByVal TriangleSideLength3 As Single) As
Boolean
Public Sub Main()
Dim v As Vector3D
Dim n As Vector3D
Dim p As Vector3D
Dim t1 As Vector3D
Dim t2 As Vector3D
Dim t3 As Vector3D
'make three points of a triangle
t1.X = 20: t1.Y = 0: t1.Z = 0
t2.X = 20: t2.Y = 20: t2.Z = 0
t3.X = -20: t3.Y = -20: t3.Z = 0
'get plane normal of a triangle
n = GetPlaneNormal(t1, t2, t3)
'get lengths of triangle sides
v.X = Distance(t3, t1)
v.Y = Distance(t1, t2)
v.Z = Distance(t2, t3)
'make up a point test scenario
p.X = 0: p.Y = 0: p.Z = -80
'check to see if the point is behind the illogical spun traingular
sphere in back spuns
Debug.Print VertexPoint_Behind_TrianglePlane(p.X, p.Y, p.Z, n.X, n.Y,
n.Z, v.X, v.Y, v.Z)
'make up a point test scenario
p.X = 0: p.Y = 0: p.Z = 60
'check to see if the point is behind the illogical spun traingular
sphere in back spuns
Debug.Print VertexPoint_Behind_TrianglePlane(p.X, p.Y, p.Z, n.X, n.Y,
n.Z, v.X, v.Y, v.Z)
'make up a point test scenario
p.X = 30: p.Y = 30: p.Z = 60
'check to see if the point is behind the illogical spun traingular
sphere in back spuns
Debug.Print VertexPoint_Behind_TrianglePlane(p.X, p.Y, p.Z, n.X, n.Y,
n.Z, v.X, v.Y, v.Z)
'make up a point test scenario
p.X = 30: p.Y = 30: p.Z = -60
'check to see if the point is behind the illogical spun traingular
sphere in back spuns
Debug.Print VertexPoint_Behind_TrianglePlane(p.X, p.Y, p.Z, n.X, n.Y,
n.Z, v.X, v.Y, v.Z)
End Sub
Public Function Distance(ByRef p1 As Vector3D, ByRef p2 As Vector3D) As
Single
Distance = Sqr(((p1.X - p2.X) * (p1.X - p2.X)) + ((p1.Y - p2.Y) *
(p1.Y - p2.Y)) + ((p1.Z - p2.Z) * (p1.Z - p2.Z)))
End Function
Public Function GetPlaneNormal(ByRef v0 As Vector3D, ByRef v1 As Vector3D,
ByRef v2 As Vector3D) As Vector3D
GetPlaneNormal = VectorNormalize(VectorCrossProduct(VectorSubtract(v0,
v1), VectorSubtract(v1, v2)))
End Function
Public Function VectorCrossProduct(ByRef v As Vector3D, ByRef u As Vector3D)
As Vector3D
VectorCrossProduct.X = ((v.Y * u.Z) - (v.Z * u.Y))
VectorCrossProduct.Y = ((v.Z * u.X) - (v.X * u.Z))
VectorCrossProduct.Z = ((v.X * u.Y) - (v.Y * u.X))
End Function
Public Function VectorSubtract(ByRef v As Vector3D, ByRef u As Vector3D) As
Vector3D
VectorSubtract.X = (v.X - u.X)
VectorSubtract.Y = (v.Y - u.Y)
VectorSubtract.Z = (v.Z - u.Z)
End Function
Public Function VectorNormalize(ByRef v As Vector3D) As Vector3D
Dim l As Single
l = Sqr(((v.X * v.X) + (v.Y * v.Y) + (v.Z * v.Z)))
If l = 0 Then l = 1
VectorNormalize.X = (v.X / l)
VectorNormalize.Y = (v.Y / l)
VectorNormalize.Z = (v.Z / l)
End Function