@TONELLAL
Yes, you are completely right on that regard. This entire statement only works if the start face defined in the code is actually the start face of said torus. However, if a face is created using features or imported as a solid body does not matter as we just need the faces.
This time I have fired up Inventor and worked out a working test code.
To determine which face is the start face another small vector trick should be used. Compose a new vector from the centerpoint of the torus to a point on the startface (lets suppose this point is the closest point to the center point). if the crossproduct between this vector and the axisvector is in the opposite direction as the normal of the startface, the startface is the actual start face. If not, flip the startface and the endface and compute the angle. I have altered the code quite a bit, but from the short tests I made, it proofed correct result every time:
Function GetTorusSweepAngle(oTorusFace As Face, oStartFace As Face, oEndFace As Face) As Double
Dim vCenterStart As Vector
Dim vCenterEnd As Vector
Dim vAxisDir As UnitVector
Set vAxisDir = oTorusFace.Geometry.AxisVector
Dim dAngle As Double
Dim PI As Double
PI = Math.Atn(1) * 4
Dim oCenterPoint As Point
Set oCenterPoint = oTorusFace.Geometry.CenterPoint
Set vCenterStart = oCenterPoint.VectorTo(oStartFace.GetClosestPointTo(oCenterPoint))
Set vCenterEnd = oCenterPoint.VectorTo(oEndFace.GetClosestPointTo(oCenterPoint))
'short note, if Face.isParamReversed = true, then the normal vector should be flipped 180 degrees
Dim vNormalStart As Vector
Set vNormalStart = oStartFace.Geometry.Normal.AsVector
If oStartFace.IsParamReversed Then
Call vNormalStart.ScaleBy(-1)
End If
If vCenterStart.CrossProduct(vAxisDir.AsVector).DotProduct(vNormalStart) > 0 Then
'switch start with end
Dim vDumpVector As Vector
Set vDumpVector = vCenterStart
Set vCenterStart = vCenterEnd
Set vCenterEnd = vDumpVector
End If
If vCenterStart.IsParallelTo(vCenterEnd) Then
dAngle = 180
GetTorusSweepAngle = dAngle
Exit Function
End If
'Instead of using the normal vectors, actually using the proper vectors
'might be a bit smarter :)
dAngle = vCenterStart.AngleTo(vCenterEnd)
dAngle = dAngle / PI * 180 'convert to degrees.
'I first thought that if they are in opposite direction, the angle
'should be flipped, but fun fact: no.
Dim vCross As Vector
Set vCross = vCenterStart.CrossProduct(vCenterEnd)
If vCross.DotProduct(vAxisDir.AsVector) > 0 Then
dAngle = 360 - dAngle
End If
GetTorusSweepAngle = dAngle
End Function
The important note is to check the Face.isParamReversed property. if that is true, the normal vector is pointing into the body (so in the wrong direction). Also, if you want to have this procedure a tad faster, using getClosestPointTo() is from my experience relatively a slow procedure, using the center point of the edge of both faces is faster, but makes the code a bit larger. I tested this function with torus angles of 60, 120 and 320 degrees using and flipping the start / end faces in the arguments, it all returned the correct answer.
Also good to see you used transientgeometry, because then you are pretty much just as fast and clean (with clean i do not really mean clean code, but just that you dont leave anything in the model when you run it).