Comment 9 for bug 611907

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

DJ,

On Tue, 31 Aug 2010, DJ Delorie wrote:

> 1) How do gerbers indicate the difference between a 135 degree
> arc and a 225 degree arc? The start/end/center points are
> the same for both.

Direction of rotation determines the difference: G02 code for CW
about the pivot (centre), G03 code for CCW about the pivot.

> What about 45 vs 315 degrees?

Well, that's part of the issue...

45 has two arcs for the same start/end/centre using a G74
(one-quadrant interpolation): one is a G02 CW arc (convex to the
left when looking at "end" from "start"), the other is a G03 CCW
arc (convex to the right when looking at "end" from "start").

315 has one arc for a given start/end/centre and is either a G75
(multiple-quadrant interpolation): CW G02 or CCW G03. The
questionable point is whether the complementary G75 command (G03
and G02 respectively) represents a 45 degree are or is simply
invalid. The OP felt that the command was valid and this is the
behaviour you would need to accommodate.

> 2) How do you do a 10 degree arc that happens to cross into a
> different quadrant?

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.

> 3) If you can support the above, why is a 45 degree arc that
> happens to start and end in the same quadrant a special case?

I think you will see in the answer to (2) why question (3) does
not apply.

Handling abnormal values in these commands becomes an exercise
in how to treat invalid data.

Consider that G74 (single-quadrant) G02 and G03 commands are
part of RS274D. G75 (multiple-quadrant) G02 and G03 commands
are not part of RS274D, and were only added for RS274X.

G74 (single-quadrant) commands G02 and G03 take two points
(start and end) and a distance to a centre point. The x- and y-
distance to the centre point is described with unsigned numbers.
This means that there are as many as 4 possible centre points.
The start and end point are presumably on a circle centered
about one of these 4 possible centre points. G02 specifies a CW
rotation about the centre and G03 specifies a CCW rotation.

By definition the start point exists on a circle centered about
one of the 4 possible centre points; however, the end point can
be specified in such a way as to be located off of the circle
(i.e. an different distance from all possible centre points than
the radius defined by the start point and possible centre point,
even considering integer round-off). How does one plot this?
Invent an ellipse perhaps that transfixes both points? Perhaps
invent an obround (oval) segment? Adjust the centre point in
some way so that it is equidistant from the start and end
points? Or does one just consider the command invalid and warn
the user of this before she sends this undefined command to a
plotter?

Now, say that the end *is* on a circle defined by the start
point and a possible centre point, but that it actually defines
a circular arc greater than 90-degrees (even so large as
180-degrees). How does one plot this? The RS274D G02 and G03
commands are only defined for angles from zero to 90-degrees.
Does one go ahead plotting arcs up to 180-degrees? Or does one
just consider the command invalid and warn the user of this
before she sends this undefined command to a plotter?

Now, G75 (multiple-quadrant) commands were added to RS274X as a
more compact form for multiple G74 (single-quadrant) commands
necessary to draw arcs greater than 90-degrees. RS274D files
used to have to use 4 90-degree arc command blocks to generate a
circle. G75 permits circles to be drawn with one command block.
When clearing out anti-pads on a ground plane using %LPC*% and
G37 contours for BGA break-out fields, layer data can be reduced
by up to a factor of 4 (remember this stuff used to be on paper
tape).

G75 (multiple-quadrant) G02 and G03 command blocks describe the
start point, centre point and end point. In this case, the
centre point is represented as the offset using signed numbers,
so only one possible centre point exists. However, it is still
possible to specify an end point that does not exist on the
circle defined by the start and centre point. How does one plot
this invalid command? Ellipses? Ovals? Move the centre point?
Or does one just consider the command invalid and warn the user
of this?

The same is true when the end point is on the circle
(considering round-off) described by the start and centre point,
but describes a circular arc of less than 90-degrees. Does one
just plot it or warn the user that it is invalid?

This last case is the case of the OP. In fact the OP wants to
*intentionally* generate this data. I say garbage in, garbage
out.

Note that at one time many plotters were incapable of handling
circular interpolation altogether and needed arcs converted to a
sequence of chords using linear interpolation to plot them at
all: so much so that modern CAM systems detect and convert
chords back to arcs when importing RS274D or RS274X data.
PCBNEW and GERBVIEW currently *always* plot arcs with linear
chords (for Gerbers).

I think that drawing ugly little hooks is far better than
pretending that garbage data is cool and plotting it nicely so
that the user has no idea that the Gerber plot is indeed junk.
The only improvement I can see is to make Gerbview barf on the
whole file and refuse to display it.