<?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 Angle Measurement in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/angle-measurement/m-p/1779098#M157062</link>
    <description>Hi All,&lt;BR /&gt;
&lt;BR /&gt;
I have an assembly with a sub assembly, and I want to write some code to measure the angle of the sub assembly YZ plane with respects to the parent assembly YZ plane.  &lt;BR /&gt;
&lt;BR /&gt;
I have tried to use getangle but I am getting an invalid call error.&lt;BR /&gt;
&lt;BR /&gt;
Any ideas on the best way to do this? &lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
Regards,&lt;BR /&gt;
Mark.</description>
    <pubDate>Mon, 02 Oct 2006 03:15:47 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2006-10-02T03:15:47Z</dc:date>
    <item>
      <title>Angle Measurement</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/angle-measurement/m-p/1779098#M157062</link>
      <description>Hi All,&lt;BR /&gt;
&lt;BR /&gt;
I have an assembly with a sub assembly, and I want to write some code to measure the angle of the sub assembly YZ plane with respects to the parent assembly YZ plane.  &lt;BR /&gt;
&lt;BR /&gt;
I have tried to use getangle but I am getting an invalid call error.&lt;BR /&gt;
&lt;BR /&gt;
Any ideas on the best way to do this? &lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
Regards,&lt;BR /&gt;
Mark.</description>
      <pubDate>Mon, 02 Oct 2006 03:15:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/angle-measurement/m-p/1779098#M157062</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-10-02T03:15:47Z</dc:date>
    </item>
    <item>
      <title>Re: Angle Measurement</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/angle-measurement/m-p/1779099#M157063</link>
      <description>If you want to get the angle between the workplane, you can just get the &lt;BR /&gt;
angle between their normals. But, depending on how you view it, this answer &lt;BR /&gt;
could be one of the two possible angle between the vectors. If this is not &lt;BR /&gt;
important, here's the macro that gets the angle between their normals:&lt;BR /&gt;
&lt;BR /&gt;
Public Sub GetAngle()&lt;BR /&gt;
&lt;BR /&gt;
    Dim ActiveAssemDoc As AssemblyDocument&lt;BR /&gt;
    Set ActiveAssemDoc = ThisApplication.ActiveDocument&lt;BR /&gt;
&lt;BR /&gt;
    Dim AssemXYWorkPlane As WorkPlane&lt;BR /&gt;
    Set AssemXYWorkPlane = ActiveAssemDoc.ComponentDefinition.WorkPlanes(3)&lt;BR /&gt;
&lt;BR /&gt;
    Dim FirstOcc As ComponentOccurrence&lt;BR /&gt;
    Set FirstOcc = ActiveAssemDoc.ComponentDefinition.Occurrences(1)&lt;BR /&gt;
&lt;BR /&gt;
    If FirstOcc.DefinitionDocumentType = kAssemblyDocumentObject Then&lt;BR /&gt;
&lt;BR /&gt;
        Dim FirstOccPartDef As AssemblyComponentDefinition&lt;BR /&gt;
        Set FirstOccPartDef = FirstOcc.Definition&lt;BR /&gt;
&lt;BR /&gt;
        Dim FirstOccXYWorkPlane As WorkPlane&lt;BR /&gt;
        Set FirstOccXYWorkPlane = FirstOccPartDef.WorkPlanes(3)&lt;BR /&gt;
&lt;BR /&gt;
        Dim FirstOccXYWorkPlaneProxy As WorkPlaneProxy&lt;BR /&gt;
        FirstOcc.CreateGeometryProxy FirstOccXYWorkPlane, &lt;BR /&gt;
FirstOccXYWorkPlaneProxy&lt;BR /&gt;
&lt;BR /&gt;
        Dim AngleInRadians As Double&lt;BR /&gt;
        AngleInRadians = &lt;BR /&gt;
AssemXYWorkPlane.Plane.Normal.AngleTo(FirstOccXYWorkPlaneProxy.Plane.Normal)&lt;BR /&gt;
&lt;BR /&gt;
        Dim PI As Double&lt;BR /&gt;
        PI = 4 * Math.Atn(1)&lt;BR /&gt;
&lt;BR /&gt;
        Dim AngleInDegrees As Double&lt;BR /&gt;
        AngleInDegrees = AngleInRadians * 180 / PI&lt;BR /&gt;
&lt;BR /&gt;
    End If&lt;BR /&gt;
&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
But, this angle between any two vectors as returned by the "Vector.AngleTo" &lt;BR /&gt;
method is always less than 180 deg irrespective of the directions of the &lt;BR /&gt;
vectors. The angle returned is the included angle between the vectors and &lt;BR /&gt;
hence, is always less than 180 deg.&lt;BR /&gt;
&lt;BR /&gt;
This angle is the smaller of "theta" and "360-theta" (where "theta" is the &lt;BR /&gt;
angle that you would consider when calculating the dot product or the cross &lt;BR /&gt;
product between the vectors), this applies irrespective of how your &lt;BR /&gt;
coordinate system is defined.&lt;BR /&gt;
&lt;BR /&gt;
If you want your angles to be returned in a particular "sense" &lt;BR /&gt;
(anti-clockwise or clockwise) then you could define this "sense" as a &lt;BR /&gt;
direction vector. With this direction defined, you could compare the cross &lt;BR /&gt;
product of the vectors (say Vector1 and Vector2) between which you want to &lt;BR /&gt;
measure the angle to this direction vector, if they are the same then the &lt;BR /&gt;
angle is Vector1.AngleTo(Vector2), but, if opposite in direction, then the &lt;BR /&gt;
angle is (2*pi) - Vector1.AngleTo(Vector2).&lt;BR /&gt;
&lt;BR /&gt;
As an example, let us consider that all vectors lie on the XY plane. If you &lt;BR /&gt;
are looking at the XY plane in such a manner that the positive X direction &lt;BR /&gt;
points to the right and the positive Y direction points towards the top, &lt;BR /&gt;
then the Z direction would be pointing out of the plane towards you. Given &lt;BR /&gt;
this direction of viewing the XY plane, and if you want to measure the &lt;BR /&gt;
angles between all vectors that might be drawn on the XY planes in the &lt;BR /&gt;
anti-clockwise direction only, then the steps are:&lt;BR /&gt;
1) Define the "sense" or direction vector corresponding to the &lt;BR /&gt;
anti-clockwise measurement; in this case it would be the Z vector.&lt;BR /&gt;
2) In order to find the angle between any two vectors, e.g. Vector1 and &lt;BR /&gt;
Vector2, find the cross product of the two vectors, i.e. Vector1 x Vector2, &lt;BR /&gt;
if the direction of the cross product vector is the same as the direction &lt;BR /&gt;
vector (in this case the Z direction), then the angle between them in the &lt;BR /&gt;
anti-clockwise direction is Vector1.AngleTo(Vector2) but, if the direction &lt;BR /&gt;
of the cross-product is opposite that of the direction vector, then the &lt;BR /&gt;
angle between the vectors is 2*pi - Vector1.AngleTo(Vector2).&lt;BR /&gt;
&lt;BR /&gt;
Here is the VBA code:&lt;BR /&gt;
Public Sub AngleWithDirectionSense()&lt;BR /&gt;
    Dim pi As Double&lt;BR /&gt;
    pi = 4 * Atn(1)&lt;BR /&gt;
&lt;BR /&gt;
    Dim oTransGeom As TransientGeometry&lt;BR /&gt;
    Set oTransGeom = ThisApplication.TransientGeometry&lt;BR /&gt;
&lt;BR /&gt;
    'if you have many vectors on a plane and want to measure angles in the &lt;BR /&gt;
same sense:e.g anticlockwise&lt;BR /&gt;
    'use two vectors to set up the sense&lt;BR /&gt;
&lt;BR /&gt;
    Dim oXDir As Vector&lt;BR /&gt;
    Set oXDir = oTransGeom.CreateVector(1, 0, 0)&lt;BR /&gt;
&lt;BR /&gt;
    Dim oYDir As Vector&lt;BR /&gt;
    Set oYDir = oTransGeom.CreateVector(0, 1, 0)&lt;BR /&gt;
&lt;BR /&gt;
    'set up direction as anti-clockwise&lt;BR /&gt;
    Dim oDirSense As Vector&lt;BR /&gt;
    Set oDirSense = oXDir.CrossProduct(oYDir)&lt;BR /&gt;
    'use above or reverse it for clockwise:&lt;BR /&gt;
    '    oDirSense.X = -(oDirSense.X)&lt;BR /&gt;
    '    oDirSense.Y = -(oDirSense.Y)&lt;BR /&gt;
    '    oDirSense.Z = -(oDirSense.Z)&lt;BR /&gt;
&lt;BR /&gt;
    'now use the sense to measure angles between any other vectors on the &lt;BR /&gt;
plane&lt;BR /&gt;
    'define the first vector&lt;BR /&gt;
    Dim oVector1 As Vector&lt;BR /&gt;
    Set oVector1 = oTransGeom.CreateVector(1, 1, 0)&lt;BR /&gt;
&lt;BR /&gt;
    'define the second vector&lt;BR /&gt;
    Dim oVector2 As Vector&lt;BR /&gt;
    Set oVector2 = oTransGeom.CreateVector(1, -1, 0)&lt;BR /&gt;
&lt;BR /&gt;
    'get the crossproduct&lt;BR /&gt;
    Dim oCrossProd As Vector&lt;BR /&gt;
    Set oCrossProd = oVector1.CrossProduct(oVector2)&lt;BR /&gt;
&lt;BR /&gt;
    'now determine the angle between Vector1 and Vector2 in the &lt;BR /&gt;
anti-clockwise direction&lt;BR /&gt;
    Dim AngleRadians As Double&lt;BR /&gt;
    If oCrossProd.DotProduct(oDirSense) &amp;lt; 0 Then&lt;BR /&gt;
    AngleRadians = 2 * pi - oVector1.AngleTo(oVector2)&lt;BR /&gt;
    Else&lt;BR /&gt;
    AngleRadians = oVector1.AngleTo(oVector2)&lt;BR /&gt;
    End If&lt;BR /&gt;
&lt;BR /&gt;
    Dim AngleDegrees As Double&lt;BR /&gt;
    AngleDegrees = AngleRadians * 180 / pi&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
-Venkatesh Thiyagarajan.&lt;BR /&gt;
&lt;BR /&gt;
&lt;MARK ashmore=""&gt; wrote in message news:5346853@discussion.autodesk.com...&lt;BR /&gt;
Hi All,&lt;BR /&gt;
&lt;BR /&gt;
I have an assembly with a sub assembly, and I want to write some code to &lt;BR /&gt;
measure the angle of the sub assembly YZ plane with respects to the parent &lt;BR /&gt;
assembly YZ plane.&lt;BR /&gt;
&lt;BR /&gt;
I have tried to use getangle but I am getting an invalid call error.&lt;BR /&gt;
&lt;BR /&gt;
Any ideas on the best way to do this?&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
Regards,&lt;BR /&gt;
Mark.&lt;/MARK&gt;</description>
      <pubDate>Mon, 02 Oct 2006 17:46:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/angle-measurement/m-p/1779099#M157063</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-10-02T17:46:06Z</dc:date>
    </item>
    <item>
      <title>Re: Angle Measurement</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/angle-measurement/m-p/1779100#M157064</link>
      <description>Thanks Venkatesh,&lt;BR /&gt;
&lt;BR /&gt;
I had to use a transient geometry so getangle would work.&lt;BR /&gt;
The direction was important and that Cross/Dot product stuff was gold.  You deserve a raise!&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
Mark.</description>
      <pubDate>Wed, 04 Oct 2006 08:35:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/angle-measurement/m-p/1779100#M157064</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-10-04T08:35:26Z</dc:date>
    </item>
    <item>
      <title>Re: Angle Measurement</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/angle-measurement/m-p/9468978#M157065</link>
      <description>&lt;P&gt;This post was from 2006, now in 2020, is there a different approach to this? Or same methodology works?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 24 Apr 2020 21:19:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/angle-measurement/m-p/9468978#M157065</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-04-24T21:19:59Z</dc:date>
    </item>
  </channel>
</rss>

