Measure angle between faces if angle is more than 180 deg (PI)

Measure angle between faces if angle is more than 180 deg (PI)

dariuszm
Advocate Advocate
689 Views
7 Replies
Message 1 of 8

Measure angle between faces if angle is more than 180 deg (PI)

dariuszm
Advocate
Advocate

How to measure angle by iLogic in Inventor, when it's more than 180 deg? There is sample file in attachment to test it.

Please look at screen below. Alpha is angle between red face and blue face. It should be 90 deg (it's ok). Beta is angle between red face and green face. It should be 270 deg (I don't know how to measure it). Of course I'm looking for solution to work with more complex model but this example should be simple to understand.

Sub Main
	
	Dim myPartDoc As PartDocument = ThisDoc.Document
	Dim myPartCompDef As PartComponentDefinition = myPartDoc.ComponentDefinition
	Dim oTg As TransientGeometry = ThisApplication.TransientGeometry
	
	Dim namedEntities = iLogicVb.Automation.GetNamedEntities(myPartDoc)
	
	Dim redFace As Face = namedEntities.FindEntity("redFace")
	Dim greenFace As Face = namedEntities.FindEntity("greenFace")
	Dim blueFace As Face = namedEntities.FindEntity("blueFace")
	
	Dim myRedFaceParams(1) As Double
	Dim myRedFaceNormal(2) As Double
	redFace.Evaluator.GetNormal(myRedFaceParams, myRedFaceNormal)
	Dim myRedFaceNormalVector As Vector = oTg.CreateVector(myRedFaceNormal(0), myRedFaceNormal(1), myRedFaceNormal(2))
	
	Dim myGreenFaceParams(1) As Double
	Dim myGreenFaceNormal(2) As Double
	greenFace.Evaluator.GetNormal(myGreenFaceParams, myGreenFaceNormal)
	Dim myGreenFaceNormalVector As Vector = oTg.CreateVector(myGreenFaceNormal(0), myGreenFaceNormal(1), myGreenFaceNormal(2))
	
	Dim myBlueFaceParams(1) As Double
	Dim myBlueFaceNormal(2) As Double
	blueFace.Evaluator.GetNormal(myBlueFaceParams, myBlueFaceNormal)
	Dim myBlueFaceNormalVector As Vector = oTg.CreateVector(myBlueFaceNormal(0), myBlueFaceNormal(1), myBlueFaceNormal(2))
	
	Dim angleFaceGreenToRed As Double = myGreenFaceNormalVector.AngleTo(myRedFaceNormalVector) * 180 / Math.PI
	Dim angleFaceBlueToRed As Double = myBlueFaceNormalVector.AngleTo(myRedFaceNormalVector) * 180 / Math.PI
	
	Logger.Info("angleFaceBlueToRed:" & angleFaceBlueToRed)
	Logger.Info("angleFaceGreenToRed:" & angleFaceGreenToRed & " How to measure this to get 270 deg?")
	
End Sub

 

dariuszm_0-1657307712946.png

 

I have read this articles but can't find solution.

https://adndevblog.typepad.com/manufacturing/2012/07/finding-the-angle-between-two-vectors-along-a-g...

https://adndevblog.typepad.com/manufacturing/2012/08/normal-vectors-and-points-on-brep-surfaces.html

https://modthemachine.typepad.com/files/mathgeometry.pdf

 

690 Views
7 Replies
Replies (7)
Message 2 of 8

abdullah_elq
Advocate
Advocate

I would also be very interested in a solution to this.

0 Likes
Message 3 of 8

j.brodersen
Enthusiast
Enthusiast

I'm facing the same problem right now and I'm as well interested in a solution to get the "correct" angle using faces.  Tried both 

Measure.Angle("Face1", "Face2")

and

ThisApplication.MeasureTools.GetAngle("Face1", "Face2")

 both with the same result in getting the complementary angle. The only way it could figure out to get the correct angle (an angle greater than 90°) was using 3 dots instead of faces/edges

Measure.Angle("DOT1", "DOT2", "DOT3")

but that doesn't help me much😓

 

Angle.JPG

 

0 Likes
Message 4 of 8

abdullah_elq
Advocate
Advocate

Hi,

 

I believe that I have a working solution. Let me know if you find any cases where it doesn't work.

 

Sub Main()
	Dim MT As MeasureTools = ThisApplication.MeasureTools

	Dim Face1 As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Pick planar face #1")
	Dim Face2 As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Pick planar face #2")

	Face1Points = GetComparisionPoints(Face1)
	Face2Points = GetComparisionPoints(Face2)
	
	Dim Distance1 As Double = MT.GetMinimumDistance(Face1Points(0), Face2Points(0))
	Dim Distance2 As Double = MT.GetMinimumDistance(Face1Points(1), Face2Points(1))
	Dim FaceAngle As Double = MT.GetAngle(Face1, Face2) * 180 / Math.PI
	
	If FaceAngle = 180 Or FaceAngle = 0 Then
		MessageBox.Show("Faces are parallel", "Faces are parallel")
	ElseIf Distance2 > Distance1 Then
		Dim AdjustedAngle As Double = 180 + FaceAngle
		MessageBox.Show("Angle is greater than 180", "Angle: " & Str(AdjustedAngle))
	ElseIf Distance1 > Distance2 Then
		MessageBox.Show("Angle is less than 180", "Angle: " & Str(FaceAngle))
	Else
		MessageBox.Show("An error occured", "Angle: " & Str(FaceAngle))
	End If
End Sub

Function GetComparisionPoints(Face As Face)

	Dim TG As TransientGeometry = ThisApplication.TransientGeometry
	Dim OffsetMultiplier As Double = 0.0001
	Dim FacePoint1 As Point = Face.PointOnFace
	
	Dim Params(1) As Double 
	Params(0) = 0
	Params(1) = 0
	
	Dim Normals(2) As Double
	Face.Evaluator.GetNormal(Params, Normals)
	
	Dim FacePoint2 As Point = TG.CreatePoint(FacePoint1.X + Normals(0) * OffsetMultiplier, FacePoint1.Y + Normals(1) * OffsetMultiplier, FacePoint1.Z + Normals(2) * OffsetMultiplier)
	
	GetComparisionPoints = New Point(){FacePoint1, FacePoint2}

End Function
Message 5 of 8

j.brodersen
Enthusiast
Enthusiast

hi abdullah.elq

thank's a lot, just tried your code and it worked perfectly. I only needed to modify it a bit 'cause if have one statice face and need the angle of each face attached to this one with a base angle of 90° instead of 180° 

 

Message 6 of 8

abdullah_elq
Advocate
Advocate

@dariuszm did this work for you? If yes, please accept the solution, so that others can find it in the future. 

Message 7 of 8

j.brodersen
Enthusiast
Enthusiast
Hi again abdullah.elq

I had now some time to mess around with your code and discovered a little problem.
If i take a cylinder with a cut out (that it looks like a pac man) and start to change the angle of the cut out the measuring results between 1 - 90 deg are correct, from 91 - 180 deg it calculates backwards (eg. angle is 91 deg but the result i get running the code is 89 deg because 180 - 91 = 89), from 181 - 270 deg the result is correct again and from 271 - 359 deg it's calculating backwards again.

I tried to figure out how to get the proper result for 91 - 180 and 271 - 359 but since I'm just a advanced noob when it comes to programming I've unfortunately no clue what I need to adjust/ change to get i working!
Message 8 of 8

Cadkunde.nl
Collaborator
Collaborator

@j.brodersen @dariuszm @abdullah_elq 

 

I needed this measuring angle from a face to face.

I used abdullahs code but noticed some angles were measured incorrect.

So I checked what the code was doing with distance1 and distance2.

I liked the idea and added another check if the normal of face1 intersects with face2

With those 2 checks, you can determine in which quadrant you are.

Quad1: <90 deg

Quad2: <180 - 90 deg

Quad3: <270-180 deg

Quad4: 270-360

 

Here is the code, but if you accept as solution, please also accept abdullah, for I wouldn't have come up with this idea if it wasn't for his idea.

Last note: I have a serious feeling this could all have been done easier with matrices or vectors, but i dunno, this works

 

Sub Main()
Dim oApp As Inventor.Application = ThisApplication
Dim MT As MeasureTools = oApp.MeasureTools

Dim Face1 As Face = oApp.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Pick planar face #1")
Dim Face2 As Face = oApp.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Pick planar face #2")

Dim Face1Points As Object = GetComparisionPoints(Face1)
Dim Face2Points As Object = GetComparisionPoints(Face2)

Dim Distance1 As Double = MT.GetMinimumDistance(Face1Points(0), Face2Points(0))
Dim Distance2 As Double = MT.GetMinimumDistance(Face1Points(1), Face2Points(1))
Dim FaceAngle As Double = MT.GetAngle(Face1, Face2) * 180 / Math.PI

Dim otg As Inventor.TransientGeometry = oApp.TransientGeometry
Dim lineseg As LineSegment = otg.CreateLineSegment(Face1Points(0), Face1Points(2))
Dim intersectpoint As ObjectsEnumerator = lineseg.IntersectWithSurface(Face2.Geometry)

Dim oDoc As PartDocument = oApp.ActiveDocument
Dim wps As Inventor.WorkPoints = oDoc.ComponentDefinition.WorkPoints

'Try
'	wps.AddFixed(intersectpoint.Item(1))
'Catch
'End Try
'MsgBox(oApp.MeasureTools.GetMinimumDistance(intersectpoint.Item(1), Face2))

If Distance1 > Distance2 And Not intersectpoint Is Nothing Then
	MsgBox("quadrant1" & vbLf & FaceAngle)
ElseIf Distance1 > Distance2 And intersectpoint Is Nothing Then
	FaceAngle = 180 - FaceAngle
	MsgBox("quadrant2" & vbLf & FaceAngle)
ElseIf Distance1 < Distance2 And Not intersectpoint Is Nothing Then
	FaceAngle = 180 + FaceAngle
	MsgBox("quadrant3" & vbLf & FaceAngle)
ElseIf Distance1 < Distance2 And intersectpoint Is Nothing Then
	FaceAngle = 360 - FaceAngle
	MsgBox("quadrant4" & vbLf & FaceAngle)

End If


'If FaceAngle = 180 Or FaceAngle = 0 Then
'	MessageBox.Show("Faces are parallel", "Faces are parallel")
'ElseIf Distance2 > Distance1 Then
'	Dim AdjustedAngle As Double = 180 + FaceAngle
'	MessageBox.Show("Angle is greater than 180", "Angle: " & Str(AdjustedAngle))
'ElseIf Distance1 > Distance2 Then
'	MessageBox.Show("Angle is less than 180", "Angle: " & Str(FaceAngle))
'Else
'	MessageBox.Show("An error occured", "Angle: " & Str(FaceAngle))
'End If
End Sub

Function GetComparisionPoints(Face As Face)
	Dim oApp As Inventor.Application = ThisApplication
	Dim TG As TransientGeometry = oApp.TransientGeometry
	Dim OffsetMultiplier1 As Double = 0.001
	Dim OffsetMultiplier2 As Double = 9999
	Dim FacePoint1 As Point = Face.PointOnFace

	Dim Params(1) As Double
	Params(0) = 0
	Params(1) = 0

	Dim Normals(2) As Double
	Face.Evaluator.GetNormal(Params, Normals)

	Dim FacePoint2 As Point = TG.CreatePoint(FacePoint1.X + Normals(0) * OffsetMultiplier1, FacePoint1.Y + Normals(1) * OffsetMultiplier1, FacePoint1.Z + Normals(2) * OffsetMultiplier1)
	Dim FacePoint3 As Point = TG.CreatePoint(FacePoint1.X + Normals(0) * OffsetMultiplier2, FacePoint1.Y + Normals(1) * OffsetMultiplier2, FacePoint1.Z + Normals(2) * OffsetMultiplier2)

	GetComparisionPoints = New Point() {FacePoint1, FacePoint2, FacePoint3 }

	'Dim odoc As PartDocument = oApp.ActiveDocument
	'Dim x As Inventor.WorkPoints = odoc.ComponentDefinition.WorkPoints
	'Dim wp1 As WorkPoint = x.AddFixed(FacePoint1)
	'Dim wp2 As WorkPoint = x.AddFixed(FacePoint2)
	'Dim k As Inventor.WorkAxes = oDoc.ComponentDefinition.WorkAxes

	'k.AddByTwoPoints(wp1, wp2)

End Function