3

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

Community
  • 1
  • 1
Mr.Qbs
  • 152
  • 2
  • 9
  • Turn cases 2 through 4 into case 5 by locating all of the shorter sides, and stretching them until they're the same size as the longest side. – Kevin Dec 02 '14 at 13:35
  • I cant change start/end point...that's the pain. – Mr.Qbs Dec 02 '14 at 13:50
  • It must be a very strange programming language you're using, that you can't modify the value of an object, or create a modified copy. – Kevin Dec 02 '14 at 13:55
  • It's not the language. I can imagine case when this solution failed so i cant accept this method. My problem in most cases will be part of biger structure and i cant make so big changes in it. I dont have knowlage about shape of that figure ect. all i have is G code (buch of vectors). I drew you a simple example: [link](http://i58.tinypic.com/8wbl7l.png). – Mr.Qbs Dec 02 '14 at 14:09
  • Please fix all your typos, this will make the reading more comfortable. –  Dec 02 '14 at 16:26
  • In the case of a full circle the constraint "Circle's start/end point must be in the beginning/end of vectors path" cannot be used. What do you use instead ? –  Dec 02 '14 at 16:34
  • @YvesDaoust I'll try to fix it :) Good question. I gues there is some solution in G2, G3 instructions but if where is no, i can split figure in couple arcs (as Spektre said below) and then try to join them. – Mr.Qbs Dec 02 '14 at 17:40
  • @Mr.Qbs, how did you end up solving this. I'm facing a similar problem. – Yomi1984 Aug 26 '20 at 13:21

2 Answers2

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

Spektre
  • 49,595
  • 11
  • 110
  • 380
  • Great answer! It realy helped me! :) Thank you! – Mr.Qbs Dec 13 '14 at 13:38
  • 2
    @Mr.Qbs I use this a lot to obtain trajectory curvature... I compute speed dynamics constrains from it for advanced movement control in mulltidimensional curved spaces. did try many approaches but this simplest is the best of all I know – Spektre Dec 13 '14 at 14:07
1

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.