Jump to content

Is there a way to sort points in clockwise or CCW order?


magneto

Recommended Posts

Thanks Edward, actually no it's not a polygon. It could be a polygon though :)

Basically I want to create a polygon using the outline of multiple continuous polygons. So I was trying to create the polygon from the outline points manually. Do you think I can rely on the vertex numbers using your technique? I just thought the verte numbers wouldn't necessarily be in increasing order. So that's why I thought of creating a polygon from the points manually, but also have the points in CW or CCW order.

Thanks :)

Link to comment
Share on other sites

I'm not sure I understand your use case, but here's a method for just sorting points in a cw/ccw fashion. Basically just create a cylindrical uv mapping and sort according to u.

For added proceduralism you could maybe make the center of the mapping be the center of bounding box or weighted average of point positions..

ee_clockwise_sort.hip

  • Like 2
Link to comment
Share on other sites

Alternative you can just use a "Sort" SOP and create an expression to sort in a circle:

atan2($TX,$TZ) for the XZ plane

As a matter of fact, I created this a long while back already (so it may be a little inefficient). The attached OTL will only work for points, but the expression above can easily be adapted for primitives as well.

Acey

SortCircle.otl

  • Like 4
Link to comment
Share on other sites

Thanks alot acey, this is definitely a useful OTL. Can this be adapted to use any plane normal? This way if your points lie on an arbitrary normal like {1,2,3}.normalized(), you could still use it to sort the points in the same fashion.

Thanks :)

Link to comment
Share on other sites

Currently it only works on orthogonal planes (XY, XZ and YZ planes), I probably can make it to work on an arbitrary normal as well, but that would require a more complex expression.

I haven't used that OTL in a while, since I tend to use Vopsops more nowadays, which I would also use to tackle this problem.

I can try to update the OTL, using a VopSop if you want to.

  • Like 1
Link to comment
Share on other sites

  • 4 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...