Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=========================================================================
- // Draw arrow head procedure
- procedure Form1.DrawArrowHead(n1, n2: TImage);
- var
- halfX, halfY, vecX, vecY, sideAX, sideAY, sideBX, sideBY: integer;
- unitX, unitY, orthX, orthY, backX, backY, mag: real;
- begin
- // get the vector from one node to the next
- vecX := n2.Left - n1.Left;
- vecY := n2.Top - n1.Top;
- // calculate magnitude of the vector and use it to get a unit vector
- mag := sqrt(vecX*vecX + vecY*vecY);
- unitX := vecX/mag;
- unitY := vecY/mag;
- // get a point halfway between the nodes, and moved up half the length of
- // the arrowhead so the arrowhead is centered
- halfX := ((n1.Left - 5) + (n2.Left - 5))/2 + aHeadLength*unitX*0.5;
- halfY := ((n1.Top - 5) + (n2.Top - 5))/2 + aHeadLength*unitY*0.5;
- // get a vector orthogonal to the unit vector
- orthX := -unitY;
- orthY := unitX;
- // move back from the halfway point a distance equal to the arrow head length
- backX := halfX - aHeadLength*unitX;
- backY := halfY - aHeadLength*unitY;
- // move orthogonally (sideways) a distance equal to the arrow head width
- // we calculate "sideA" and "sideB" for both sides of the arrow head / and \
- sideAX := backX + orthX*aHeadWidth;
- sideAY := backY + orthY*aHeadWidth;
- sideBX := backX - orthX*aHeadWidth;
- sideBY := backY - orthY*aHeadWidth;
- // draw the arrowhead lines
- Image2.Canvas.MoveTo(halfX, halfY);
- Image2.Canvas.LineTo(sideAX, sideAY);
- Image2.Canvas.MoveTo(halfX, halfY);
- Image2.Canvas.LineTo(sideBX, sideBY);
- end;
Advertisement
Add Comment
Please, Sign In to add comment