ebth@rhi.hi.is (Eggert Bjarni Thorlacius) (03/05/91)
Hello everybody. OK, here is the situation. I've got two points on screen, and I want to draw an arrow between them. Does anyone hvae any code that does something remotely like this? I can read anything but assembler and Cobol, but I would prefer Pascal. Thanks Eggert Thorlacius University of Iceland ebth@rhi.hi.is Disclaimer of the week: This letter contains no opinions, so I might just as well say they are mine (even though they aren't).
bernard@cs.colorado.edu (Bernie Bernstein) (03/06/91)
In article <2867@krafla.rhi.hi.is>, ebth@rhi.hi.is (Eggert Bjarni Thorlacius) writes: > > Hello everybody. > > OK, here is the situation. I've got two points on screen, and I want to draw > an arrow between them. Does anyone hvae any code that does something remotely > like this? > /*** * ArrowPoints * * This function sets two points which can be used to construct * an arrowhead. The arrow will be on the end of the line. To * draw a line made with this function, one would: * MoveTo(start.h, start.v); * LineTo(end.h, end.v); * LineTo(new1.h, new1.v); * MoveTo(end.h, end.v); * LineTo(new2.h, new2.v); * or you can create a polygon connecting the end point and the two new * points and fill or frame it. In any case, it works well enough for * my application. I wouldn't do this at update time. Do it once when * the line points change and save the arrow points. * * Point start; starting point for the line * Point end; ending point for the line * Point *new1; endpoint of half of arrowhead * Point *new2; endpoint of other half of arrowhead ***/ void ArrowPoints(Point start, Point end, Point *new1, Point *new2) { double theta, theta1, theta2; short tx, ty; double pitch = .3; /* angle of the arrow lines from the mail line */ short length = 8; /* length of the arrow lines */ tx = end.h; ty = end.v; theta = atan2((start.v - ty), (start.h - tx)); theta1 = theta + pitch; theta2 = theta - pitch; new1->h = (short)(tx + (length * cos(theta1))); new1->v = (short)(ty + (length * sin(theta1))); new2->h = (short)(tx + (length * cos(theta2))); new2->v = (short)(ty + (length * sin(theta2))); } I wrote this in Think C a long time ago. I would be interested in hearing from others who have faster ways to do this. o, ,, , | Bernie Bernstein | , ,, L>O/ \,/ \ ,| University of Colorado at boulder |/ \,,/ \ O./ ' / . `, / | office: (303) 492-8136 | / ` \ ,. ,/ / , ' | email: bernard@cs.colorado.edu | / '' \
smoke@well.sf.ca.us (Nicholas Jackiw) (03/09/91)
In article <1991Mar5.190538.778@csn.org> bernard@cs.colorado.edu (Bernie Bernstein) writes: > * ArrowPoints >I wrote this in Think C a long time ago. I would be interested in hearing >from others who have faster ways to do this. > o, ,, , | Bernie Bernstein | , ,, This Pascal frag cuts down on all the trig (or rather, delegates it to the Toolbox): procedure DrawArrow (fromPt, toPt: Point); {Given two points, DrawArrow draws an arrowhead pointing to toPt.} {The pixel-length of the arrowhead is specified by ELineInset.} const ELineInset=10; var myAngle, dX, dY: integer; aRect: Rect; begin with fromPt do begin with aRect do begin left := h - 100; top := v - 100; right := h + 100; bottom := v + 100 end; PtToAngle(aRect, toPt, myAngle) end; with toPt do with aRect do begin dX := ELineInset; top := v - dX; right := h + dX; bottom := v + dX; left := h - dX; end; PaintArc(aRect, (myAngle + 180) - 24, 49) ; Total Arrow Arc=50 degrees end; -- --- * --- Nicholas Jackiw Smoke@well.sf.ca.us | Jackiw@cs.swarthmore.edu Key Curriculum Press, Inc. Applelink: D3970 | (415) 548-2304 --- * ---