Rotation with vector / matrix

Rotation with vector / matrix

Cadkunde.nl
Collaborator Collaborator
765 Views
5 Replies
Message 1 of 6

Rotation with vector / matrix

Cadkunde.nl
Collaborator
Collaborator

Hello Forum,

 

I'm having trouble with matrix and vectors.

 

Attached an ipt with an ilogic rule.

 

With the rule I can't get the orientation of a "fake flange" at 90 degrees angle from the front face

Cadkundenl_0-1711034679419.png

Cadkundenl_1-1711034779435.png

 

I can get the normal from the front face using this:

https://adndevblog.typepad.com/manufacturing/2012/08/what-is-the-best-way-to-compute-a-normal-of-a-f...

 

But I can't find the right inputs to rotate the current result to be 90 degrees from the front face.

I find it hard to visualize vectors and how I should give the inputs

 

Any advice is greatly appreciated

 

0 Likes
766 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

Hi @Cadkunde.nl.  Those can definitely be a bit odd at first when you have to work with them by code.  I have attached a PDF file that I believe will help you understand some of it.  It is from an Autodesk University class back in 2008 by Brian Ekins.  The portion about the Matrix is especially helpful for visualization (starting around page 18).  As for vectors...think of starting a line from the 0,0,0 coordinates, then being drawn straight to the X, Y, & Z inputs you specify in 3D space.  That is how the direction is specified.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

Cadkunde.nl
Collaborator
Collaborator

Ye I read down the rabbit hole numerous times. Still got trouble with it when putting it to solve my problem

0 Likes
Message 4 of 6

Cadkunde.nl
Collaborator
Collaborator

Solved using UCS

 

Public Sub Main()
	Dim partDoc As PartDocument = ThisDoc.Document
	Dim oCompDef As PartComponentDefinition = partDoc.ComponentDefinition

	Dim transBRep As TransientBRep = ThisApplication.TransientBRep
	Dim transGeom As TransientGeometry = ThisApplication.TransientGeometry

	Dim Selectededge As Edge = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeFilter, "Select an edge.")

	Dim faces As Faces = Selectededge.Faces
	Dim baseface As Face = Nothing
	For i = 1 To faces.Count
		If baseface Is Nothing Then
			baseface = Faces(i)
		ElseIf Faces(i).Evaluator.Area > baseface.Evaluator.Area Then
			baseface = Faces(i)
		End If
	Next

	Dim egdeLength As Double = Selectededge.StartVertex.Point.DistanceTo(Selectededge.StopVertex.Point)
	Dim line As LineSegment = Selectededge.Geometry

	Dim startPoint = line.StartPoint

	Dim boxMinPoint As Point = transGeom.CreatePoint(0, 0, 0)
	Dim boxMaxPoint As Point = transGeom.CreatePoint(egdeLength, 10, 0.3)

	Dim box As Box = transGeom.CreateBox()
	box.Extend(boxMinPoint)
	box.Extend(boxMaxPoint)
	
	Dim boxXpoint As Point = transGeom.CreatePoint(0, 0, egdeLength)
	Dim boxYpoint As Point = transGeom.CreatePoint(0, 10, 0)
	
	Dim oBody As SurfaceBody = transBRep.CreateSolidBlock(box)
	
	Dim edgeStartWP As Inventor.WorkPoint = partDoc.ComponentDefinition.WorkPoints.AddByPoint(Selectededge.StartVertex)
	Dim edgeXWP As Inventor.WorkPoint = partDoc.ComponentDefinition.WorkPoints.AddByPoint(Selectededge.StopVertex)
	
	Dim edgeYWP As Inventor.WorkPoint
	For Each oEdge As Inventor.Edge In Selectededge.StartVertex.Edges
		If Not oEdge Is Selectededge Then
			If Not Math.Round(oEdge.StartVertex.Point.DistanceTo(oEdge.StopVertex.Point), 2) = 0.3 Then
				If Math.Round(oEdge.StartVertex.Point.DistanceTo(Selectededge.StartVertex.Point), 2) > 0 Then
					edgeYWP = partDoc.ComponentDefinition.WorkPoints.AddByPoint(oEdge.StartVertex)
				Else
					edgeYWP = partDoc.ComponentDefinition.WorkPoints.AddByPoint(oEdge.StopVertex)
				End If
			End If
		End If					
	Next
	
	Dim oUCSDef As UserCoordinateSystemDefinition = oCompDef.UserCoordinateSystems.CreateDefinition
	oUCSDef.SetByThreePoints(edgeStartWP, edgeXWP, edgeYWP)
    Dim oEdgeUCS As UserCoordinateSystem = oCompDef.UserCoordinateSystems.Add(oUCSDef)
	
	Dim Edgematrix As Matrix = oEdgeUCS.Transformation
	
	transBRep.Transform(oBody, Edgematrix)
	
	Dim vector = line.Direction.AsVector()
	Edgematrix.SetToRotation(180 * Math.PI / 180, vector, Selectededge.StartVertex.Point)
	transBRep.Transform(oBody, Edgematrix)
	partDoc.ComponentDefinition.SetEndOfPartToTopOrBottom(True)
	Dim oBaseFeature As NonParametricBaseFeature = oCompDef.Features.NonParametricBaseFeatures.Add(oBody)
	partDoc.ComponentDefinition.SetEndOfPartToTopOrBottom(False)	
	
End Sub

0 Likes
Message 5 of 6

JelteDeJong
Mentor
Mentor

probably it's not really what you are looking for but on the topic of "matrix and vectors". 3B1B did a great series about Linear Algebra. "Matrices and vectors" are a big part of the series (at least to chapter 5). I found it very informative. Check out his site: https://www.3blue1brown.com/topics/linear-algebra

I also like the Wikipedia page on the topic. https://en.wikipedia.org/wiki/Transformation_matrix

But I guess all of that does not help you much directly with the inventor stuff.

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 6 of 6

Cadkunde.nl
Collaborator
Collaborator

Kinda starting to understand the concepts.

Looks useful, thanks. I will look into it.

 

For me, i think i will work with the UCS method for now. Might not be most efficient for running the script. But it definitely speeds up the development and easy to see what you are doing

0 Likes