Comment 11 for bug 611907

Revision history for this message
Brian Bidulock (bidulock) wrote : Re: [Bug 611907] Re: gerbview does not handle arcs correctly

William,

On Thu, 02 Sep 2010, William Lash wrote:

> > The term quadrant is a poor choice. It bears no relation to the
> > x-y axis of the plot (true Cartesian coordinate system
> > quadrants), but is basically internal angles from zero to pi/2
> > or interior angles from pi/2+ to 2pi. It does not matter in
> > which Cartesian quadrant the arc starts or finishes but whether
> > the included angle would span one or multiple quadrants if the
> > centre was placed at the origin and the start on an axis.
>
> A reference I have seen would seem to contradict this.
>
> http://www.rulabinsky.com/cavd/text/chapa.html
>
-X-snip-X-
>
> Also, at http://www.ams-us.com/princi.html the description of G74 versus
> G75 seems to imply this.
>
-X-snip-X-

After doing a bunch of research, I think that I now understand
the difference between single-quadrant and multiple-quadrant
circular interpolation.

Yes, it appears that single-quadrant arc must be constrained to
lay within the confines of a Cartesian quadrant, but not for the
reasons stated by Steve in your reference above. Also note that
Steve was working from now long obsolete 1983 Gerber format
specifications (it includes G06 parabolic and G07 cubic
interpolations that are no longer supported, as well as G56 text
which also is long deleted from the spec). Steve says:

 "One restriction on the drawing of arcs is that they must start
  and end in the same quadrant. This is because the I and J
  parameters, which specify the arc center, are unsigned
  absolute distances relative to the starting point. Therefore
  the arc must remain in the same quadrant to prevent ambiguity
  in the center location."

This is not true: there is no ambiguity in the center location.
The reason that the arc could not cross a quadrant was because
the old CNC controllers on photo-plotters could not handle a
reversal in direction on the axis. Consider, for example, a
photo-plotter table movement controlled by a worm gear and
stepper motor. If there was any slop in the worm gear, a
reversal in direction would result in a discontinuity in the
arc. Compensation for this effect was only performed at the
beginning of travel (i.e. between part program blocks). A CNC
controller that was capable of compensating while moving or that
used a movement that did not require compensation (e.g.
recirculating ball gear) was capable of multiple-quadrant arcs
(arcs that crossed quadrant boundaries or was capable of
reversals in the movement without significant discontinuities).

Now, two ways evolved of specifying arcs with G02 and G03
commands: center location using I and J coordinates (i.e.
G02X#Y#I#J#) and another using radius (i.e. G02X#Y#R#). Some
controllers were incapable of the later (radius specification).
Some controllers specified the I and J using absolute
coordinates and some relative coordinates with sign indicating
direction. RS274-D and RS274/NG3 always use relative
coordinates with directional sign. Single quadrant arcs could
be specified with center or (positive) radius. Multiple
quadrant arcs could be specified with center or radius (positive
radius 0 to 180 degrees, negative radius 180+ to 359.999
degrees).

For a single-quadrant arc the center form (I and J) could easily
be converted to the radius form by calculating the hypotenuse of
the I and J vectors. For single-quadrant arcs, this results in
ignoring the sign of the I and J vectors. That is, as RS274X
says, the I and J values are always treated as unsigned. In
this way an error in the sign of the I or J vector would not
result in the destruction of a part. Note that this also
applies to an arc with an included angle of 180 degrees or less.

For multiple-quadrant arcs (more precisely arcs greater than 180
degrees), the conversion from I,J values to R values is more
complex because of the need to establish the sign of R. It is
not possible to simply take the hypotenuse of the I and J
vectors, because that would always result in a positive radius.

Some (and nowhere close to all) CNC controllers established the
use of G74 and G75 to signal to the controller whether the
simple hypotenuse conversion of I,J values to R values was
applicable or not.

Now, of course, none of this has any bearing on anything but
antique photo-plotters. However, from the CNC controller (or
GERBVIEW) point of view, when G74 is active, the following
should be the approach to plotting the arc:

 1. Calculate the radius by taking the hypotenuse of the I and J
    vectors.

 2. Find the two points equidistance from the start and end
    point where the distance is that calculated in (1).

 3. When the command is G02 (CW), select the point to the right
    when looking at the end point standing at the start point.
    When the command is G03 (CCW), select the point to the left.
    When the start and end points are the same, it does not
    matter which center is to be used (the arc is of zero
    length).

 4. Plot the arc rotating CW (G02) or CCW (G03) around the
    selected center point from start to end. When start and end
    point are the same, the arc is of zero length (which is
    effectively the same as a flash).

Does it matter whether this single-quadrant arc crosses a
quadrant or not, or whether it is between 90 and 180 degrees?
Probably not (unless we need to support antique photo-plotters:
non-multiple quadrant capable CNC controllers used to generate
an alarm when this happened). But the important thing is to
ignore the sign on I and J vectors and to ignore round-off
errors or sign errors in the specification of I and J.

When G75 is active, a slightly different approach must be taken.

 1. Calculate the radius by taking the hypotenuse of the I and J
    vectors.

 2. Find the two points equidistant from the start and end point
    where the distance is that calculated in (1).

 3. Select the point nearest the center point described by the
    vectors I and J relative to the start point. (The
    difference between the two points should simply be one of
    round-off error.)

 4. Plot the arc rotating CW (G02) or CCW (G03) around the
    selected center point from start to end. When the start and
    end points are the same, plot a full circle.

Does it matter whether this multiple-quadrant arc crosses a
quadrant or not, or whether it is less than 90 degrees?
Probably not. The important thing was to ignore round-off
errors in the specification of I and J.

If one really wanted to be complete, GERBVIEW would also accept
R-coded G02 and G03 commands, as well as G12 and G13 canned
circle commands.

If the wrong quadrant mode is active, it is possible that some
single-quadrant arcs (e.g. 45-degrees) will become
multiple-quadrant arcs with the wrong center (e.g. 315-degrees
instead of 45-degrees) if the I,J values were expressed as
absolute values. There are reports of just that happening
(Mickey Mouse ears). However, this would violate the RS274-D
(NC standard) specification of arcs which always uses signed
values for I and J regardless of what quadrants are involved.
So, when generating G02 and G03 commands likely one should
simply always supply the proper and signed values of I and J to
avoid this.

So, I now stand corrected and find myself agreeing with the OP:
G75 arcs should be plotted properly regardless of the included
angle.

Nevertheless, the specific example of Gerber code given by the
OP is still better plotted as a G74 arc than a G75 one (less
part program, easier to read).

--brian