Option Explicit On
Sub Main
Do
Dim edgeX As Edge = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeLinearFilter, "Select edge")
If edgeX Is Nothing Then Exit Do
Dim face1 = edgeX.Faces(1)
Dim face2 = edgeX.Faces(2)
'Logger.Info("angle between faces = {0} deg", ThisApplication.MeasureTools.GetAngle(face1, face2) * 180 / PI)
Dim angleBetween = GetAngleBetweenFaces(face1, face2)
Logger.Info("angle between faces = {0} deg", Round(angleBetween * 180 / PI, 2))
Dim convexEdges = face1.Parent.ConvexEdges
If EdgeIsInCollection(convexEdges, edgeX) Then
Logger.Info(" the edge is a convex edge")
Else
Logger.Info(" the edge is not a convex edge")
End If
Loop Until False
End Sub
'''
''' Gets an angle that is not between the normals, but rather between lines normal to the normals
''' that would intersect a common edge at right angles.
'''
'''
'''
''' Angle in radians
Function GetAngleBetweenFaces(face1 As Face, face2 As Face) As Double
Dim norm1 = GetFaceNormal(face1)
'Logger.Debug("normal of face1 = {0}, {1}, {2}", norm1.X, norm1.Y, norm1.Z)
Dim norm2 = GetFaceNormal(face2)
'Logger.Debug("normal of face2 = {0}, {1}, {2}", norm2.X, norm2.Y, norm2.Z)
Dim angleTest = Math.Abs(norm1.AngleTo(norm2))
If angleTest < 0.0001 Then
Return angleTest ' the faces are coplanar or nearly complanar
End If
Dim edgeDirection = norm1.CrossProduct(norm2)
Dim line1 = norm1.CrossProduct(edgeDirection) ' the direction of a line normal to both the normal and the edge line
Dim line2 = edgeDirection.CrossProduct(norm2) ' reverse the sign of the cross product for the second normal.
' This way, both lines point away from the edge.
Return line1.AngleTo(line2)
End Function
Function GetFaceNormal(faceX As Face) As UnitVector
Dim oF1points() As Double = {}
Dim oF1normals() As Double = {}
faceX.PointOnFace.GetPointData(oF1points)
faceX.Evaluator.GetNormalAtPoint(oF1points, oF1normals)
Dim oF1Normal As UnitVector
oF1Normal = ThisApplication.TransientGeometry.CreateUnitVector(oF1normals(0), oF1normals(1), oF1normals(2))
Return oF1Normal
End Function
Function EdgeIsInCollection(edges As EdgeCollection, edgeX As Edge) As Boolean
For Each edgeT As Edge In edges
If edgeT Is edgeX Then Return True
Next
Return False
End Function