<?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 回复： Algorithm: counter clockwise 1, 2, 3, 4, 5 in ObjectARX Forum</title>
    <link>https://forums.autodesk.com/t5/objectarx-forum/algorithm-counter-clockwise-1-2-3-4-5/m-p/10460985#M3199</link>
    <description>&lt;P&gt;first of all, you need to convert Decart (Cartesian) coordinates (X,Y,Z) to Spherical coordinates (r,phi, theta). Spherical - is a 3D variant of polar coordinates.&lt;BR /&gt;then, you have to sort your array of spherical coordinates by "phi" (phi[i] &amp;lt; phi[i+1] = counterclockwise. phi[i] &amp;gt; phi[i+1] = clockwise. if you have two points with the same phi, compare "r" and "theta" values).&lt;BR /&gt;and when sort is done, you can convert polar coordinates of your sorted array back to decart.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;/*
DECART 
AcGePoint3d::x - X
AcGePoint3d::y - Y
AcGePoint3d::z - Z

SPHERICAL
AcGePoint3d::x - r
AcGePoint3d::y - phi
AcGePoint3d::z - theta
*/
AcGePoint3d Decart2Spherical(AcGePoint3d c)
{
	AcGePoint3d p;
	p.x=sqrt(c.x*c.x+c.y*c.y+c.z*c.z);
	p.y=acos(c.x/sqrt(c.x*c.x+c.y*c.y))*(c.y&amp;gt;=0?1:-1);
	p.z=acos(c.z/p.x);
	return p;
}

AcGePoint3d Spherical2Decart(AcGePoint3d p)
{
	decart d;
	d.x=p.x*cos(p.y)*sin(p.z);
	d.y=p.x*sin(p.y)*sin(p.z);
	d.z=p.x*cos(p.z);
	return d;
}&lt;/LI-CODE&gt;&lt;P&gt;almost forgot. may be, before convertation you will need to&amp;nbsp;subtract "A" coords from the rest points, to make "A" a zero point and append "A" after Spheriacal2Decart. In most cases it's&amp;nbsp;&lt;SPAN&gt;unnecessary, but who knows &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 12 Jul 2021 07:02:21 GMT</pubDate>
    <dc:creator>nick83</dc:creator>
    <dc:date>2021-07-12T07:02:21Z</dc:date>
    <item>
      <title>Algorithm: counter clockwise 1, 2, 3, 4, 5</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/algorithm-counter-clockwise-1-2-3-4-5/m-p/10450035#M3197</link>
      <description>&lt;P&gt;All lines have the same short point A. find the other end point and sort it anticlockwise 1, 2, 3, 4, 5&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jul 2021 14:45:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/algorithm-counter-clockwise-1-2-3-4-5/m-p/10450035#M3197</guid>
      <dc:creator>463017170</dc:creator>
      <dc:date>2021-07-07T14:45:48Z</dc:date>
    </item>
    <item>
      <title>回复： Algorithm: counter clockwise 1, 2, 3, 4, 5</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/algorithm-counter-clockwise-1-2-3-4-5/m-p/10460516#M3198</link>
      <description>My friend, who can provide me with an algorithm.</description>
      <pubDate>Mon, 12 Jul 2021 01:20:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/algorithm-counter-clockwise-1-2-3-4-5/m-p/10460516#M3198</guid>
      <dc:creator>463017170</dc:creator>
      <dc:date>2021-07-12T01:20:46Z</dc:date>
    </item>
    <item>
      <title>回复： Algorithm: counter clockwise 1, 2, 3, 4, 5</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/algorithm-counter-clockwise-1-2-3-4-5/m-p/10460985#M3199</link>
      <description>&lt;P&gt;first of all, you need to convert Decart (Cartesian) coordinates (X,Y,Z) to Spherical coordinates (r,phi, theta). Spherical - is a 3D variant of polar coordinates.&lt;BR /&gt;then, you have to sort your array of spherical coordinates by "phi" (phi[i] &amp;lt; phi[i+1] = counterclockwise. phi[i] &amp;gt; phi[i+1] = clockwise. if you have two points with the same phi, compare "r" and "theta" values).&lt;BR /&gt;and when sort is done, you can convert polar coordinates of your sorted array back to decart.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;/*
DECART 
AcGePoint3d::x - X
AcGePoint3d::y - Y
AcGePoint3d::z - Z

SPHERICAL
AcGePoint3d::x - r
AcGePoint3d::y - phi
AcGePoint3d::z - theta
*/
AcGePoint3d Decart2Spherical(AcGePoint3d c)
{
	AcGePoint3d p;
	p.x=sqrt(c.x*c.x+c.y*c.y+c.z*c.z);
	p.y=acos(c.x/sqrt(c.x*c.x+c.y*c.y))*(c.y&amp;gt;=0?1:-1);
	p.z=acos(c.z/p.x);
	return p;
}

AcGePoint3d Spherical2Decart(AcGePoint3d p)
{
	decart d;
	d.x=p.x*cos(p.y)*sin(p.z);
	d.y=p.x*sin(p.y)*sin(p.z);
	d.z=p.x*cos(p.z);
	return d;
}&lt;/LI-CODE&gt;&lt;P&gt;almost forgot. may be, before convertation you will need to&amp;nbsp;subtract "A" coords from the rest points, to make "A" a zero point and append "A" after Spheriacal2Decart. In most cases it's&amp;nbsp;&lt;SPAN&gt;unnecessary, but who knows &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jul 2021 07:02:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/algorithm-counter-clockwise-1-2-3-4-5/m-p/10460985#M3199</guid>
      <dc:creator>nick83</dc:creator>
      <dc:date>2021-07-12T07:02:21Z</dc:date>
    </item>
    <item>
      <title>回复： Algorithm: counter clockwise 1, 2, 3, 4, 5</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/algorithm-counter-clockwise-1-2-3-4-5/m-p/10465326#M3200</link>
      <description>Thank you for your help. It seems that this algorithm doesn't work. Can you give me more details?</description>
      <pubDate>Tue, 13 Jul 2021 14:47:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/algorithm-counter-clockwise-1-2-3-4-5/m-p/10465326#M3200</guid>
      <dc:creator>463017170</dc:creator>
      <dc:date>2021-07-13T14:47:35Z</dc:date>
    </item>
    <item>
      <title>回复： Algorithm: counter clockwise 1, 2, 3, 4, 5</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/algorithm-counter-clockwise-1-2-3-4-5/m-p/10468021#M3201</link>
      <description>&lt;P&gt;Hm... i have found 2 mistakes in my post:&lt;/P&gt;
&lt;P&gt;1. i forgot to change "decart" variable to "AcGePoint3d" variable at Spherical2Decart function, but it's not hard to understand it looking through the rest code and change it at your side.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2.&amp;nbsp;&lt;SPAN&gt;phi[i] &amp;lt; phi[i+1] = clockwise. phi[i] &amp;gt; phi[i+1] = counterclockwise, that will be correct. this mistake can be fixed at your side too, by changing a sign "&amp;gt;" to "&amp;lt;" after code running and analyze the result.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;that's all. so, if &lt;STRONG&gt;"this algorithm doesn't work"&lt;/STRONG&gt; can you provide your code?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I've created a sample project for demonstration. May be i did something wrong, but i cant attach a screencast video. So, the link to it is below&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://knowledge.autodesk.com/ru/community/screencast/8b3bdff1-82c2-478e-b9e7-2481ddc03c7c" target="_blank" rel="noopener"&gt;https://knowledge.autodesk.com/ru/community/screencast/8b3bdff1-82c2-478e-b9e7-2481ddc03c7c&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IFRAME src="https://screencast.autodesk.com/Embed/Timeline/8b3bdff1-82c2-478e-b9e7-2481ddc03c7c" width="696" height="655" frameborder="0" allowfullscreen="allowfullscreen" webkitallowfullscreen="webkitallowfullscreen"&gt;&lt;/IFRAME&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jul 2021 12:55:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/algorithm-counter-clockwise-1-2-3-4-5/m-p/10468021#M3201</guid>
      <dc:creator>nick83</dc:creator>
      <dc:date>2021-07-14T12:55:00Z</dc:date>
    </item>
    <item>
      <title>回复： Algorithm: counter clockwise 1, 2, 3, 4, 5</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/algorithm-counter-clockwise-1-2-3-4-5/m-p/10469568#M3202</link>
      <description>&lt;P&gt;If the plane is rotated to this point, the result of the algorithm is wrong.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jul 2021 23:31:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/algorithm-counter-clockwise-1-2-3-4-5/m-p/10469568#M3202</guid>
      <dc:creator>463017170</dc:creator>
      <dc:date>2021-07-14T23:31:32Z</dc:date>
    </item>
    <item>
      <title>回复： Algorithm: counter clockwise 1, 2, 3, 4, 5</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/algorithm-counter-clockwise-1-2-3-4-5/m-p/10471083#M3203</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/11088771"&gt;@463017170&lt;/a&gt;&amp;nbsp; написал (-а):&lt;BR /&gt;&lt;P&gt;If the plane is rotated to this point, the result of the algorithm is wrong.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;no one told it would be easy :).&lt;/P&gt;&lt;P&gt;you have to transform coordinates according to current view before decart-polar and after polar-decart&amp;nbsp;converting (reverse converting is necessary, if you need points in WCS).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jul 2021 13:08:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/algorithm-counter-clockwise-1-2-3-4-5/m-p/10471083#M3203</guid>
      <dc:creator>nick83</dc:creator>
      <dc:date>2021-07-15T13:08:27Z</dc:date>
    </item>
  </channel>
</rss>

