Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!hellgate.utah.edu!csn!bernard@cs.colorado.edu From: bernard@cs.colorado.edu (Bernie Bernstein) Newsgroups: comp.sys.mac.programmer Subject: Re: Arrowheads anyone? Message-ID: <1991Mar5.190538.778@csn.org> Date: 5 Mar 91 19:05:38 GMT References: <2867@krafla.rhi.hi.is> Sender: news@csn.org (news) Organization: University of Colorado, Boulder Lines: 58 Nntp-Posting-Host: csgator1.colorado.edu 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 | / '' \