CompuServe Thread

QD Geometry

3 messages in this thread
#163803From: Patrick D. ParkerMar 14, 1994 2:13 AM
Given 2 points in global QuickDraw coordinates (originPt, terminalPt), I would like to draw an arrow. For a simple line, I would do the following: MoveTo(originPt.h, originPt.v); LineTo(terminalPt.h, terminalPt.v); Getting the correct angle in QuickDraw coordinates for the "head" is what I'm wondering about… The terminalPt is the origin for the "head", whose angles should be 40 degrees from the main line; the "length" of the head lines should be about one fifth as long as the main line. In "ASCII art", the lines would look something like this: <— —> /\ | | | /\ / / / Horizontal and vertical arrows are not a problem; I'm just wondering what the best way is to handle drawing when the arrow is not horizontal or vertical. Do I need to resort to trig. functions, or is there a better way? Thanks for any help, Patrick
#163911From: Peter MarxMar 14, 1994 3:53 PM
Patrick: What many drawing programs do is draw a filled arc at the end of the line. The arc belongs to a circle whose center is "after the end of" your line. For example, when drawing line AB below, the arc belongs to a circle centered on C: A————-B C The arc is filled, and runs from angle 140 to 210 (with zero to the right, increasing counterclockwise). So it looks something like this: D x A—————-BxxxxxC x E The arc is centered on "C", and is swept from "D" to "E". And it's filled as it is swept from CD through CB to CE. See? However, for large arrowheads it becomes obvious that this is an arc, and it doesn't look as nice. To do it "right", yes you will have to calculate the coordinates of points C,D, and E. But it's not hard, and it doesn't involve any trig functions. Calculate the slope of the line AB; the slope of DE is -1/m, where m is the slope of AB. Then you can use point-slope formula to find the coordinates of D and E. Consult your local high-school analytical geometry text….. -Peter
#164105From: Patrick D. ParkerMar 15, 1994 4:57 PM
Thanks for the advice, Peter. I ended up implementing something similar to what you suggested, using arctan to find the angle of the main line. Works great… Patrick