<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Understanding matrix transformations in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/understanding-matrix-transformations/m-p/12531584#M14132</link>
    <description>&lt;P&gt;I'm sorry, I don't understand what do you try to do. transformation matrices works well, when you need to recalculate coordinates from one coordinate system to another. For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) You know the 3D point in global coordinate system (GCS) and you want to get its coordinates in sketch coordinate system (SCS). You can use&amp;nbsp;ModelToSketchTransform matrix to calculate its coordinates (ignore Z value, it is always 0).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ModelToSketchTransform_Sample&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Similar to project point, but without reference to original geometry&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;Dim part As PartDocument =ThisDoc.Document
Dim targetSketch As PlanarSketch = part.ComponentDefinition.Sketches("TargetSketch1")
Dim workPoint1 As WorkPoint = part.ComponentDefinition.WorkPoints("Work Point1")

Dim pt1 = workPoint1.Point
pt1.TransformBy(targetSketch.ModelToSketchTransform)

Dim pt1_2D As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(pt1.X, pt1.Y)

targetSketch.SketchPoints.Add(pt1_2D, True)​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) You can manipulate with objects within coordinate system.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;DrawHexagon_Sample&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Move point from one vertex of hexagon to the next one and draw the lines between them&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;Dim part As PartDocument =ThisDoc.Document
Dim targetSketch As PlanarSketch = part.ComponentDefinition.Sketches("HexagonSketch1")

Dim pt1_2D As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(0,0)
Dim startSketchPoint As SketchPoint
Dim endSketchPoint As SketchPoint

Dim mtxTranslation As Matrix2d = ThisApplication.TransientGeometry.CreateMatrix2d()
Dim vectorTranslation As Vector2d = ThisApplication.TransientGeometry.CreateVector2d(1,0)
mtxTranslation.SetTranslation(vectorTranslation)

Dim mtxRotation As Matrix2d = ThisApplication.TransientGeometry.CreateMatrix2d()
Dim center As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(0,0)
mtxRotation.SetToRotation(PI / 3, center)

Dim mtxNextVertex As Matrix2d = ThisApplication.TransientGeometry.CreateMatrix2d()
mtxNextVertex.PostMultiplyBy(mtxRotation)
mtxNextVertex.PostMultiplyBy(mtxTranslation)

startSketchPoint = targetSketch.SketchPoints.Add(pt1_2D)

For i = 1 To 6
	pt1_2D.TransformBy(mtxNextVertex)
	endSketchPoint = targetSketch.SketchPoints.Add(pt1_2D)
	targetSketch.SketchLines.AddByTwoPoints(startSketchPoint, endSketchPoint)
	startSketchPoint = endSketchPoint
Next​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 31 Jan 2024 12:21:51 GMT</pubDate>
    <dc:creator>Michael.Navara</dc:creator>
    <dc:date>2024-01-31T12:21:51Z</dc:date>
    <item>
      <title>Understanding matrix transformations</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/understanding-matrix-transformations/m-p/12527412#M14129</link>
      <description>&lt;P&gt;Using standard .Net math object like Sin, Cos and Tan, a line starting at (0, 0) and extending to the right will have a degree angle of 0°. The rotation is counter clock wise and thus a line at 270° will be pointing straight down. So, lets consider a line that starts at (0,0) and extends to (0,-12).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I apply this logic to a sketch created on a workplane, it inverts the line to be vertical from (0,0) to (0, 12). Is there a way to fix this using a matrix object?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jan 2024 20:04:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/understanding-matrix-transformations/m-p/12527412#M14129</guid>
      <dc:creator>eric.mathews7BV6E</dc:creator>
      <dc:date>2024-01-29T20:04:12Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding matrix transformations</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/understanding-matrix-transformations/m-p/12528443#M14130</link>
      <description>&lt;P&gt;Transformation matrices are very useful for manipulation with objects in 2D and 3D space. But in the sketch you can use much simpler methods&amp;nbsp;&lt;A href="https://help.autodesk.com/view/INVNTOR/2023/ENU/?guid=GUID-37331F02-2D51-4A2E-98E5-16BEEDFC5801" target="_blank" rel="noopener"&gt;Sketch.MoveSketchObjects&lt;/A&gt;&amp;nbsp;and&amp;nbsp;&lt;A href="https://help.autodesk.com/view/INVNTOR/2023/ENU/?guid=GUID-9C3EB691-CADC-43B1-8E63-5D76780E38AC" target="_blank" rel="noopener"&gt;Sketch.RotateSketchObjects&lt;/A&gt; which provides simple transformation in 2D space.&lt;/P&gt;&lt;P&gt;But be careful if you don't forgot some geometrical constrains on the sketch line. (Vertical constraint in your sample.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EDIT:&lt;/P&gt;&lt;P&gt;Code sample&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;Dim sketch As PlanarSketch = ThisApplication.ActiveEditObject
Dim objectsToRotate = ThisApplication.TransientObjects.CreateObjectCollection
objectsToRotate.Add(sketch.SketchLines(1))
Dim centerPoint = ThisApplication.TransientGeometry.CreatePoint2d(0, 0)
Dim angle As Double = 3 / 2 * PI
Dim copy = False
Dim removeConstraints = True
sketch.RotateSketchObjects(objectsToRotate, centerPoint, angle, copy, removeConstraints)&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 30 Jan 2024 07:32:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/understanding-matrix-transformations/m-p/12528443#M14130</guid>
      <dc:creator>Michael.Navara</dc:creator>
      <dc:date>2024-01-30T07:32:48Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding matrix transformations</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/understanding-matrix-transformations/m-p/12529476#M14131</link>
      <description>&lt;P&gt;I can rotate, mirror and move points before they are inserted into the sketch. I'm trying to come up with a bullet proof way to feed in 2d points and get 2d sketch points that match my expectations.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;ILine2D _sketchLine2d = new ILine2D(0, 0, 10, 12);            
PlanarSketch _sketch = GetSketch(); // On the YZ Plane. 

Matrix _modelMatrix = _sketch.ModelToSketchTransform;

// By this logic, _xAxisTemp == Z Vector &amp;amp;&amp;amp; _yAxisTemp == X Vector &amp;amp;&amp;amp; _zAxisTemp == Y Vector.
_modelMatrix.GetCoordinateSystem(out Point _origin1, out Vector _xAxisTemp, out Vector _yAxisTemp, out Vector _zAxisTemp);

// Using the above information the matrix coordinate system is reset.
_modelMatrix.SetCoordinateSystem(_origin1, _yAxisTemp, _zAxisTemp, _xAxisTemp);

// Now, all the vectors come out as the correct axes. 
_modelMatrix.GetCoordinateSystem(out Point _origin1A, out Vector _xAxisTempA, out Vector _yAxisTempA, out Vector _zAxisTempA);

// Create the start/end points of the line.
Point _pt1 = _tg.CreatePoint(_sketchLine2d.StartPoint.X, _sketchLine2d.StartPoint.Y);
Point _pt2 = _tg.CreatePoint(_sketchLine2d.EndPoint.X, _sketchLine2d.EndPoint.Y);

// This is where I'd expect the points to be transformed, that is; the values  are changed, by the new matrix. 
// But, nothing happens. The values don't change.
_pt1.TransformBy(_modelMatrix);
_pt2.TransformBy(_modelMatrix);

// These points are wrong.
Point2d _2dPt1 = _sketch.ModelToSketchSpace(_pt1);
Point2d _2dPt2 = _sketch.ModelToSketchSpace(_pt2);&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 30 Jan 2024 15:54:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/understanding-matrix-transformations/m-p/12529476#M14131</guid>
      <dc:creator>eric.mathews7BV6E</dc:creator>
      <dc:date>2024-01-30T15:54:01Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding matrix transformations</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/understanding-matrix-transformations/m-p/12531584#M14132</link>
      <description>&lt;P&gt;I'm sorry, I don't understand what do you try to do. transformation matrices works well, when you need to recalculate coordinates from one coordinate system to another. For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) You know the 3D point in global coordinate system (GCS) and you want to get its coordinates in sketch coordinate system (SCS). You can use&amp;nbsp;ModelToSketchTransform matrix to calculate its coordinates (ignore Z value, it is always 0).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ModelToSketchTransform_Sample&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Similar to project point, but without reference to original geometry&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;Dim part As PartDocument =ThisDoc.Document
Dim targetSketch As PlanarSketch = part.ComponentDefinition.Sketches("TargetSketch1")
Dim workPoint1 As WorkPoint = part.ComponentDefinition.WorkPoints("Work Point1")

Dim pt1 = workPoint1.Point
pt1.TransformBy(targetSketch.ModelToSketchTransform)

Dim pt1_2D As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(pt1.X, pt1.Y)

targetSketch.SketchPoints.Add(pt1_2D, True)​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) You can manipulate with objects within coordinate system.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;DrawHexagon_Sample&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Move point from one vertex of hexagon to the next one and draw the lines between them&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;Dim part As PartDocument =ThisDoc.Document
Dim targetSketch As PlanarSketch = part.ComponentDefinition.Sketches("HexagonSketch1")

Dim pt1_2D As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(0,0)
Dim startSketchPoint As SketchPoint
Dim endSketchPoint As SketchPoint

Dim mtxTranslation As Matrix2d = ThisApplication.TransientGeometry.CreateMatrix2d()
Dim vectorTranslation As Vector2d = ThisApplication.TransientGeometry.CreateVector2d(1,0)
mtxTranslation.SetTranslation(vectorTranslation)

Dim mtxRotation As Matrix2d = ThisApplication.TransientGeometry.CreateMatrix2d()
Dim center As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(0,0)
mtxRotation.SetToRotation(PI / 3, center)

Dim mtxNextVertex As Matrix2d = ThisApplication.TransientGeometry.CreateMatrix2d()
mtxNextVertex.PostMultiplyBy(mtxRotation)
mtxNextVertex.PostMultiplyBy(mtxTranslation)

startSketchPoint = targetSketch.SketchPoints.Add(pt1_2D)

For i = 1 To 6
	pt1_2D.TransformBy(mtxNextVertex)
	endSketchPoint = targetSketch.SketchPoints.Add(pt1_2D)
	targetSketch.SketchLines.AddByTwoPoints(startSketchPoint, endSketchPoint)
	startSketchPoint = endSketchPoint
Next​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2024 12:21:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/understanding-matrix-transformations/m-p/12531584#M14132</guid>
      <dc:creator>Michael.Navara</dc:creator>
      <dc:date>2024-01-31T12:21:51Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding matrix transformations</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/understanding-matrix-transformations/m-p/12532672#M14133</link>
      <description>&lt;P&gt;I appreciate your help. However; I'm not quite there yet. Let me explain it another way. I went into the sketch options and turned on the "Coordinate System Indicator". You see the global UCS on the left and the sketch UCS on the right. According to the help file: "The default Autodesk Inventor coordinate system follows the conventional rectangular Cartesian system with the positive X direction to the right, the positive Y direction upwards, and the positive Z direction towards you." Here in lies the problem. The X-Axis isn't pointing to the right. it's point up. The Y-Axis isn't pointing up, it's pointing to the left. Just to be clear this is looking at the sketch from the "positive" side. This is why adding a point (5, 5) goes to the top left instead of the top right. So, at this point, I'm not 100% sure what I need that will allow me to add points with a "conventional rectangular Cartesian system...".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Dual UCS.PNG" style="width: 218px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1320748iAC2D97F8120FDF72/image-size/large?v=v2&amp;amp;px=999" role="button" title="Dual UCS.PNG" alt="Dual UCS.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2024 19:59:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/understanding-matrix-transformations/m-p/12532672#M14133</guid>
      <dc:creator>eric.mathews7BV6E</dc:creator>
      <dc:date>2024-01-31T19:59:53Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding matrix transformations</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/understanding-matrix-transformations/m-p/12533626#M14134</link>
      <description>&lt;P&gt;Directions up, down left right has no sense. Because you can change the orientation of the SCS. See the picture below&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2024-02-01_8-22-00.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1320929i5F4D9B0A72EF9EED/image-size/medium?v=v2&amp;amp;px=400" role="button" title="2024-02-01_8-22-00.png" alt="2024-02-01_8-22-00.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you want to calculate coordinates, you need to choose one coordinate system (usually GCS) and all calculations needs to be done in this CS. Then you can transform the coordinates to target CS (in your case it is the SCS)&lt;/P&gt;&lt;P&gt;I have a lot of experience with working with transformations and in my opinion this is the best practice.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2024 07:49:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/understanding-matrix-transformations/m-p/12533626#M14134</guid>
      <dc:creator>Michael.Navara</dc:creator>
      <dc:date>2024-02-01T07:49:26Z</dc:date>
    </item>
  </channel>
</rss>

