Article View: comp.windows.x
Article #24265Re: Help! My arc has fallen, and it can't get up!
From: der Mouse
Date: Sun, 30 Jun 1991 21:42
Date: Sun, 30 Jun 1991 21:42
77 lines
3597 bytes
3597 bytes
In article <1991Jun28.062319.11565@eng.umd.edu>, stripes@eng.umd.edu (Joshua Osborne) writes:
> I am trying to draw the outline of a pie wedge. I (think I) am using
> the formula from the Digital Press "X Windows System, C Library and
> protocall reference" by Scheifler, Gettys & Newman.
I assume this is the same one that appears in the online Xlib
documentation:
| width |
skewed-angle = atan | tan(normal-angle) * ------ | + adjust
| height |
First, I think you're using it backwards, and second, you shouldn't be
using it. When you draw the lines, you do
> sincos(ella(xa->angle1/RPI, xa->width, xa->height), &s, &c);
> pts[0].x = pts[1].x + xa->width/2 * c;
> pts[0].y = pts[1].y + xa->height/2 * s;
> sincos(ella((xa->angle1+xa->angle2)/RPI, xa->width, xa->height), &s, &c);
> pts[2].x = pts[1].x + xa->width/2 * c;
> pts[2].y = pts[1].y + xa->height/2 * s;
and the multiplication by width/2 and height/2 is performing the
skewing already.
The formula is used if you want to find the angle the final line makes
on the screen. That is, if you want to find the angle a such that you
could write
pts[0].x = pts[1].x + (len * cos(a));
pts[0].y = pts[1].y + (len * sin(a));
for some len (the computation of which I shall ignore), *then* you want
to call ella. (Except you don't; you'd want to call the inverse of
ella, which amounts to simply interchanging width and height.)
Of course, if you do keep ella, you really should use atan2 instead of
mucking about with that silly "adjust" thing, which was introduced
simply to allow them to write the function in terms of a mathematical
one-argument atan instead of a computer's two-argument atan2.
There is one other thing wrong: you forgot that you need to write
pts[0].y = pts[1].y - xa->height/2 * s;
and similarly for pts[2].y, because the angles are measured in a
mathematician's coordinate system on the screen, but the y coordinate
to XDrawLines is measured in a graphics coordinate system - and the y
axes go in opposite directions.
When I fixed the y-axis direction and changed ella to simply return its
first argument, the lines worked just fine for me.
Note that you really should be dividing width and height by 2.0,
because you could lose a pixel in integer division roundoff with what
you have.
> I compiled the program, ran it, and it failed. Miserably. It's
> output was hideous. Women fainted. Small children ran away.
:-)
> Worst of all, the lines that should have connected the arc endpoints
> had very little to do with the arc endpoints.
I suspect you may have forgotten to #include something crucial. My
first attempt had similar problems, but once I remembered to #include
<math.h> they went away, and I had only the above two problems.
(Eliminating the tan and atan calls in ella removes the need for
math.h, except that I changed the #defines to use M_PI instead of
3.14159.)
der Mouse
old: mcgill-vision!mouse
new: mouse@larry.mcrcim.mcgill.edu
Technical Details
Message-ID:
<1991Jun30.214203.5882@thunder.mcrcim.mcgill.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!mouseReferences:
<1991Jun28.062319.11565@eng.umd.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!mouse From: mouse@thunder.mcrcim.mcgill.edu (der Mouse) Newsgroups: comp.windows.x Subject: Re: Help! My arc has fallen, and it can't get up! Message-ID: <1991Jun30.214203.5882@thunder.mcrcim.mcgill.edu> Date: 30 Jun 91 21:42:03 GMT References: <1991Jun28.062319.11565@eng.umd.edu> Organization: McGill Research Centre for Intelligent Machines Lines: 78