<?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: Orienting newly added UCS &amp;quot;bottom down&amp;quot; in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/orienting-newly-added-ucs-quot-bottom-down-quot/m-p/11481325#M11312</link>
    <description>&lt;P&gt;Apologies!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;        public static double[] Cross3D(double[] A, double[] B)
        {
            if (A.Length != 3 || B.Length != 3)
            {
                string message = "Vectors must have a length of 3";
                throw new System.Exception(message);
            }
            double[] C = new double[3];
            C[0] = (A[1] * B[2]) - (A[2] * B[1]);
            C[1] = -((A[0] * B[2]) - (A[2] * B[0]));
            C[2] = (A[0] * B[1]) - (A[1] * B[0]);
            return C;
        }&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;Well this is news to me! I have been casting them out of their native and writing custom functions and rebuilding Autocad types as needed...me wasting my own time aside...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Origin, xaxis, yaxis are indeed Point3D's originally (prior to being given to this function creating the UCS).&amp;nbsp; From your code it looks functionally the same, minus the yvec being crossproduct(z, x) vs (x, z), changing this flips all the outputed UCS's orientation 180.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My understanding of the right-hand rule and it's uses is near NULL, I basically understand it's something that exists&amp;nbsp; and when respected, certain questions become easier (or possible) to answer&lt;span class="lia-unicode-emoji" title=":grinning_face_with_sweat:"&gt;😅&lt;/span&gt;&amp;nbsp;I also assumed that AutoCAD stores it's lines and poly's with handedness in mind. (based on minimal observations clicking next vertex on a few closed 3dpolylines) Please be gentle!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EDIT:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;acUCSTblRec.XAxis = xaxisVec.GetNormal();
acUCSTblRec.YAxis = yaxisVec.GetNormal();&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;Just noticed this bit...Tried with:&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;&lt;LI-CODE lang="csharp"&gt;acUCSTblRec.Origin = new Point3d(origin);
acUCSTblRec.XAxis = new Vector3d(xaxisVec).GetNormal();
acUCSTblRec.YAxis = new Vector3d(perpYaxisPnt).GetNormal();&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;Having the same issue where this just flips all the coins. Top up to Top down and visa versa.&lt;/P&gt;</description>
    <pubDate>Thu, 13 Oct 2022 22:26:49 GMT</pubDate>
    <dc:creator>CadWCCNL</dc:creator>
    <dc:date>2022-10-13T22:26:49Z</dc:date>
    <item>
      <title>Orienting newly added UCS "bottom down"</title>
      <link>https://forums.autodesk.com/t5/net-forum/orienting-newly-added-ucs-quot-bottom-down-quot/m-p/11481152#M11310</link>
      <description>&lt;LI-CODE lang="general"&gt;//Get Vector from origin to xaxis
double[] xaxisVec = new double[3];
xaxisVec[0] = xaxis[0] - origin[0];
xaxisVec[1] = xaxis[1] - origin[1];
xaxisVec[2] = xaxis[2] - origin[2];
//Get Vector from origin to yaxis
double[] yaxisVec = new double[3];
yaxisVec[0] = yaxis[0] - origin[0];
yaxisVec[1] = yaxis[1] - origin[1];
yaxisVec[2] = yaxis[2] - origin[2];


double[] xCy = Cross3D(xaxisVec, yaxisVec);
double[] normyaxisVec = Cross3D(xaxisVec, xCy);

acUCSTblRec = acTrans.GetObject(acUCSTable[name],
                                    OpenMode.ForWrite) as UcsTableRecord;

acUCSTblRec.Origin = new Point3d(origin);
acUCSTblRec.XAxis = new Vector3d(xaxisVec);
acUCSTblRec.YAxis = new Vector3d(normyaxisVec);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With a newly generated UCS given Point3d origin, Vector3d Xaxis, Vector3d yaxis:&lt;/P&gt;&lt;P&gt;Is it possible insure that the orientation of the UCS is always "bottom down" &amp;amp; "top up"?&lt;/P&gt;</description>
      <pubDate>Thu, 13 Oct 2022 20:35:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/orienting-newly-added-ucs-quot-bottom-down-quot/m-p/11481152#M11310</guid>
      <dc:creator>CadWCCNL</dc:creator>
      <dc:date>2022-10-13T20:35:16Z</dc:date>
    </item>
    <item>
      <title>Re: Orienting newly added UCS "bottom down"</title>
      <link>https://forums.autodesk.com/t5/net-forum/orienting-newly-added-ucs-quot-bottom-down-quot/m-p/11481248#M11311</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is very difficult, if not impossible, to answer you without knowing what exactly does the 'Cross3d' method.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The Geometry namespace of the AutoCAD .NET API provides a &lt;A href="https://help.autodesk.com/view/OARX/2023/ENU/?guid=OARX-ManagedRefGuide-Autodesk_AutoCAD_Geometry_Point3d" target="_blank" rel="noopener"&gt;Point3d structure&lt;/A&gt; and a &lt;A href="https://help.autodesk.com/view/OARX/2023/ENU/?guid=OARX-ManagedRefGuide-Autodesk_AutoCAD_Geometry_Vector3d" target="_blank" rel="noopener"&gt;Vector3d structure&lt;/A&gt; with many methods for manipulating points and vectors which should save you from having to define custom methods.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming origin, xaxisPt and yaxisPt are Point3d instances instead of array of doubles, you could write the same thing like this:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;            //Get Vector from origin to xaxis
            Vector3d xaxisVec = origin.GetVectorTo(xaxisPt);
            //Get Vector from origin to yaxis
            Vector3d yaxisVec = origin.GetVectorTo(yaxisPt);

            Vector3d zaxisVec = xaxisVec.CrossProduct(yaxisVec);
            yaxisVec = zaxisVec.CrossProduct(xaxisVec);

            acUCSTblRec = acTrans.GetObject(acUCSTable[name], OpenMode.ForWrite) as UcsTableRecord;
            acUCSTblRec.Origin = origin;
            acUCSTblRec.XAxis = xaxisVec.GetNormal();
            acUCSTblRec.YAxis = yaxisVec.GetNormal();&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The cross product of X axis vector by Y axis vectors generates a Z axis vector which respects the "right hand rule".&lt;/P&gt;
&lt;P&gt;Then, to insure the Y axis to be perpendicular to the X axis respecting the "right hand rule", you have to get the cross product of the Z axis by the X axis. This orger is mandatory because the cross product is not a commutative operation.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Oct 2022 21:24:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/orienting-newly-added-ucs-quot-bottom-down-quot/m-p/11481248#M11311</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2022-10-13T21:24:51Z</dc:date>
    </item>
    <item>
      <title>Re: Orienting newly added UCS "bottom down"</title>
      <link>https://forums.autodesk.com/t5/net-forum/orienting-newly-added-ucs-quot-bottom-down-quot/m-p/11481325#M11312</link>
      <description>&lt;P&gt;Apologies!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;        public static double[] Cross3D(double[] A, double[] B)
        {
            if (A.Length != 3 || B.Length != 3)
            {
                string message = "Vectors must have a length of 3";
                throw new System.Exception(message);
            }
            double[] C = new double[3];
            C[0] = (A[1] * B[2]) - (A[2] * B[1]);
            C[1] = -((A[0] * B[2]) - (A[2] * B[0]));
            C[2] = (A[0] * B[1]) - (A[1] * B[0]);
            return C;
        }&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;Well this is news to me! I have been casting them out of their native and writing custom functions and rebuilding Autocad types as needed...me wasting my own time aside...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Origin, xaxis, yaxis are indeed Point3D's originally (prior to being given to this function creating the UCS).&amp;nbsp; From your code it looks functionally the same, minus the yvec being crossproduct(z, x) vs (x, z), changing this flips all the outputed UCS's orientation 180.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My understanding of the right-hand rule and it's uses is near NULL, I basically understand it's something that exists&amp;nbsp; and when respected, certain questions become easier (or possible) to answer&lt;span class="lia-unicode-emoji" title=":grinning_face_with_sweat:"&gt;😅&lt;/span&gt;&amp;nbsp;I also assumed that AutoCAD stores it's lines and poly's with handedness in mind. (based on minimal observations clicking next vertex on a few closed 3dpolylines) Please be gentle!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EDIT:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;acUCSTblRec.XAxis = xaxisVec.GetNormal();
acUCSTblRec.YAxis = yaxisVec.GetNormal();&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;Just noticed this bit...Tried with:&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;&lt;LI-CODE lang="csharp"&gt;acUCSTblRec.Origin = new Point3d(origin);
acUCSTblRec.XAxis = new Vector3d(xaxisVec).GetNormal();
acUCSTblRec.YAxis = new Vector3d(perpYaxisPnt).GetNormal();&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;Having the same issue where this just flips all the coins. Top up to Top down and visa versa.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Oct 2022 22:26:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/orienting-newly-added-ucs-quot-bottom-down-quot/m-p/11481325#M11312</guid>
      <dc:creator>CadWCCNL</dc:creator>
      <dc:date>2022-10-13T22:26:49Z</dc:date>
    </item>
    <item>
      <title>Re: Orienting newly added UCS "bottom down"</title>
      <link>https://forums.autodesk.com/t5/net-forum/orienting-newly-added-ucs-quot-bottom-down-quot/m-p/11481545#M11313</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;Updated code to use the native types of AutoCAD and the available methods they come with. Very succinct. On that note alone you have saved me hours of future hassle, thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Still have the same behavior though. I feel that I am missing some kind of conditional trick here. I have a series of X surfaces that need UCS's generated, all in the same drawing. It would be great if "top" was oriented for "top" in the WCS. I'm not sure if I'm heading in the right direction, but degrees of rotation required to rotate a vector to be parallel with z axis &amp;gt; 180 degrees = flip x/y. Something like that possible. I am looking further into this to see if there is a way to do that.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Oct 2022 01:26:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/orienting-newly-added-ucs-quot-bottom-down-quot/m-p/11481545#M11313</guid>
      <dc:creator>CadWCCNL</dc:creator>
      <dc:date>2022-10-14T01:26:39Z</dc:date>
    </item>
    <item>
      <title>Re: Orienting newly added UCS "bottom down"</title>
      <link>https://forums.autodesk.com/t5/net-forum/orienting-newly-added-ucs-quot-bottom-down-quot/m-p/11482083#M11314</link>
      <description>&lt;P&gt;If I don't misunderstand, the issue comes from the the specified points.&lt;/P&gt;
&lt;P&gt;As said upper, coordinate systems uses the "&lt;A href="https://en.wikipedia.org/wiki/Right-hand_rule" target="_blank" rel="noopener"&gt;right hand rule&lt;/A&gt;" to compute the axis. IOW, when looking from the "top", origin, point on x and point on Y are counterclockwise.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Oct 2022 07:11:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/orienting-newly-added-ucs-quot-bottom-down-quot/m-p/11482083#M11314</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2022-10-14T07:11:01Z</dc:date>
    </item>
    <item>
      <title>Re: Orienting newly added UCS "bottom down"</title>
      <link>https://forums.autodesk.com/t5/net-forum/orienting-newly-added-ucs-quot-bottom-down-quot/m-p/11483339#M11315</link>
      <description>&lt;P&gt;You are correct, I was able to fix it! I really appreciate your help, you are a champion of the people sir.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Oct 2022 16:11:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/orienting-newly-added-ucs-quot-bottom-down-quot/m-p/11483339#M11315</guid>
      <dc:creator>CadWCCNL</dc:creator>
      <dc:date>2022-10-14T16:11:31Z</dc:date>
    </item>
  </channel>
</rss>

