Jump to content

Polygon to circle


thoma.v

Recommended Posts

Hi Odforce!
I have a large three-dimensional hexagonal mesh. Now I need to approximate every polygon of it by a circle that best fits the given shape. What would be the most efficient way to address this problem in Houdini?

Any opinions or suggestions are greatly appreciated!

Link to comment
Share on other sites

so you want to replace a bunch of triangles with circles?

http://www.efunda.com/math/areas/circleinscribetrianglegen.cfm

 

take your mesh, feed it into a divide and turn on compute dual (gives you the midpoints),  add the radius math to each midpoint after the divide, feed that into a copy sop that takes a circle. stamp radius value into the circle radius

Link to comment
Share on other sites

Thanks Jim, thanks Michael!

@Jim: The polygons are not triangles but hexagons so I don´t think the math will work.

@Michael: That is a great idea and works like a charm for regular polygons. Unfortunately it does not work so good for distorted ones. I´ve uploaded a small part of the model where you can see the problem.

 

Thanks again! 

polyToCircle.hipnc

Link to comment
Share on other sites

Thanks Matt but that´s what I did in the uploaded file. One problem is that I need circles not ellipses :). The other one is the center of the circle. When I transform a circle to find a good approximation "by hand" it seems that its center does not correspond with the centroid of the polygon and so far I have no idea how to tackle this problem.

Link to comment
Share on other sites

Heh, serves me right for not looking at your scene first. :)

 

Here's the start of an idea, needs improvement. Basically iterate through each hexagon, get the points, calculate the midpoints of the edges, measure the distance between each opposite pair of edges, determine the shortest one, create a point at the midpoint of the shortest width, and set the radius from that.

 

Doesn't handle concave shapes very well, and its hardcoded for hexagons, but should give you a start. Google seems to have lots of examples of inscribing a circle in a hexagon, should be trivial (!?!) to apply that to the little vex wrangle here.

 

polyToCircle2.hipnc

 

post-7292-0-12764100-1456272909_thumb.gi

Edited by mestela
Link to comment
Share on other sites

Thanks Matt, thanks Tomas for the scene files! Unfortunately this is not what I was looking for. My apologies for the confusion and my vague description of the problem!

I´ll do my best to explain what I´m after: What I´m trying to do is to measure the average deviation between the polygon and the circle. In this context "circle that best fits the given shape" means to find a circle such that the distance to all points of the polygon is as small as possible. It´s kinda hard to explain in words but the picture should show what I mean.

 

Thanks again!

post-7715-0-04451600-1456311610_thumb.jp

Edited by thoma.v
Link to comment
Share on other sites

Yet another method.
post-13104-0-76928400-1456322305_thumb.p
 

// Primitive Wrangle.
// Radius from mean centroid-to-point distances.
addpointattrib(0, "N", {0.0, 0.0, 0.0});
addpointattrib(0, "pscale", 0.0);

float dists[];
foreach (int pt; primpoints(0, @primnum))
{
    vector pt_pos = point(0, "P", pt);
    float dist = distance(@P, pt_pos);
    append(dists, dist);
}
float mean_dist = avg(dists);

int pt = addpoint(0, @P);
setpointattrib(0, "pscale", pt, mean_dist);
setpointattrib(0, "N", pt, @N);

removeprim(0, @primnum, true);

average_circles.hipnc

Link to comment
Share on other sites

Many thanks, that´s a nice solution and works very well for most of the polygons. Finding the circle-center for the few distorted ones is still a problem but I have a vague idea how to resolve this in a Foreach-Sop. I´ll let you know how it goes.

 

 

 

Link to comment
Share on other sites

there are different ways how you can do this depending on geometry and accuracy. generally it´s a typical minimization problem and could be solved by using a least squares approach but you can also try to solve it geometrically.
if you compute the largest inscribed and the smallest circumsribed circle you´ll get a good approximation by blending between them. for the inner circle rely on the file from anim or use the one in this thread (for pre-houdini 15 versions). for the outer circle use the bounding sop in sphere mode.
another method would be to find the intersections of two lines orthogonal to all consecutive edges. calculate the average of all intersection which are inside the prim and you´ll get the center of the circle. after that compute the average distance to the vertices and use this as radius.
the third option would be to find the best fittiing circle by using least squares. this works for pretty much every case and ensures that the squared sum of distances from all points to the circle is the smallest possible.

hth.
petz

polyToCircle1.hipnc

  • Like 4
Link to comment
Share on other sites

Thanks Petz, that's what I was looking for! Works like a charm!

@Michael: Ha, ha, no, not a chain mail! I work in the field of computational design and would like to know how much every polygon deviates from a regular shaped hexagon. Use it fo a chain mail is not a bad idea, though. :)
 

Link to comment
Share on other sites

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...