Circular approximation of polygon (or its part)

2019-01-28 13:14发布

SHORT DESCRIPTION OF MY PROBLEM

I need to implement GCODE autorefactoring from G1 instructions to G2 and G3 (http://www.cnccookbook.com/CCCNCGCodeArcsG02G03.htm) for 3D Printing.

G1 is a movement in straight line with printing (path is describe by vector).

I'm searching for algorytm to aproxymate circle/arc (specialy it's midpoint) based on given vectors path. Note that G2 and G3 can't print curves that are not part of a circle - so not every vectors path can be approximate this way.

LONG DESCRIPTION OF MY PROBLEM

I'm searching way to approximate part (or all) of vectors path (can be regular polygon, part of it or inregular polygon part) by circle (arc). But let's, at first, focuse on regural polygons.

In the picture i drew different cases of this problem. NOTE: Every polygons are build by vectors (like in point 5). enter image description here

  1. Approximation on full x-gon.
  2. Approximation of part x-gon where one side is different
  3. Approximate of x-gon where two sides are different but equal to each other
  4. Approximate of x-gon where two sides are different (not even to each other)not equal
  5. Approximation of part x-gom where all sides are equal

It's not the eod of story...there are couple criteria:

  • Circle's start/end point must be in the beginning/end of vectors path.
  • I need to know circles mid point.

Solutions that i found (good and bad):

1) and 5) - my simple solution

This is the easiest case. I can count radius between each side that shares one opint. If they have same length and angles between each are equal i can calculate circles mid point (as point that belongs to perpendiculat middle-lines, one middle-line per side) and i have all i need: Start point, end point, mid-point.

But this solution works only for cases 1 and 5.

I realy have no ide what to do when i have cases 2,3,4 or inregural polygon's part

2条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-01-28 13:40
  1. You can obtain curvature radius center for any 2 line segments

    curve radius

    1. find the lines midpoints
    2. cast perpendicular lines from each (red lines)
    3. find the intersection (it is the center of the curvature)

    In 3D use plane of the object (3 lines not 2). The radius is just distance between center and the lines joint point (blue line). If radius is too big then handle both lines as single line (no intersection or too far intersection)

  2. compute all segments like in #1

  3. join arcs with the same radius and center to single arc if joined

  4. handle the changing curvature

    if the arc is changing the center or radius do it like in this picture

    elliptic arc

    first segment does not have previous line so use the next instead that cause the irregularity at start arc ...

That should cover all cases hope my hand-paint-drawings are making sense ...

查看更多
Rolldiameter
3楼-- · 2019-01-28 14:02

If your circular arcs must start and end on given endpoints, then the center point will be somewhere on the mediatrix and there remains a single degree of freedom.

So you can use the least squares method to find a best fit: assume you know the radius, which gives you the center, and compute the sum of squared distances of the remaining vertices to the circumference (distance to the center minus radius). The best fit is the one that minimizes that sum. Let's hope that there is an analytical solution.

查看更多
登录 后发表回答