Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

algorythm or suggestion for add arrows to Line

Posted on 1998-04-03
3
Medium Priority
?
149 Views
Last Modified: 2010-04-06
I'm creating a mapping program that will allow users to
link(via a line), drag/drop, and move them at runtime.  I would like to draw a small arrow at one or both ends.  As the control moves, the arrow is correctly positions.  

Any Suggestions or agorhythms????
0
Comment
Question by:blitz051697
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 3

Expert Comment

by:altena
ID: 1361268
I wrote a small app once where users were allowed to drag & 
drop stuff all over the place.

Make your control a "normal" delphi control. Read all the stuff
about creating components in the manuals, and practice them a little. It will all fall into place.

Best advice i can give you: You will not need to do anything
"tricky" to get this working.
0
 
LVL 5

Accepted Solution

by:
inter earned 600 total points
ID: 1361269
Hi,

Try the following, I think this is what you want. If have taken a geometry(or computer graphics course before it is self explanatory). There may be more efficient way but I can code this at this time:

To DO

1 - Create a new form. Add a button
2 - Paste the following code over implentation
3 - Link Button1 to the Button1Click below run and enjoy

Note: You only need the function DrawArrow

implementation

{$R *.DFM}
uses
  Math;
//Draws an arrow give angles in degrees in to specified canvas
procedure DrawArrow(C : TCanvas;
  O,P :TPoint; //start and end of line
  ALen : integer;//length of each arrow tip line
  AAngle:integer);//angle between arrow small lines with base line
var
  M_PI_DEG : real;
  function Rotate(P : TPoint;Angle:Integer):TPoint;
  begin
    Result.X := Round(P.X*Cos(M_PI_DEG*Angle)-P.Y*Sin(M_PI_DEG*Angle));
    Result.Y := Round(P.X*Sin(M_PI_DEG*Angle)+P.Y*Cos(M_PI_DEG*Angle));
  end;
  function PolarToCartesian(R:Integer;Angle:Integer):TPoint;
  begin
    Result.X := -Round(R*Cos(M_PI_DEG*Angle));
    Result.Y := Round(R*Sin(M_PI_DEG*Angle));
  end;
var
  BAngle : Integer; //angle between our line and X axis
  Arrow  : TPoint ; //storage for our small lines
begin
  M_PI_DEG := Pi/180; //for degree to radian conversion
  try
    // determine base angle(note that screen Y is negative of
    // cartesian Y
    BAngle := Round(ArcTan2(-(P.Y-O.Y),(P.X-O.X))/M_PI_DEG);
    // Draw base line
    C.MoveTo(O.X,O.Y);
    C.LineTo(P.X,P.Y);
    // Rotate tip line 1 to correct position and draw
    Arrow := Rotate(PolarToCartesian(ALen, BAngle), AAngle);
    C.MoveTo(P.X,P.Y);
    C.LineTo(P.X+Arrow.X,P.Y+Arrow.Y);
    // Rotate tip line 1 to correct position and draw
    Arrow := Rotate(PolarToCartesian(ALen, -BAngle), AAngle);
    C.MoveTo(P.X,P.Y);
    C.LineTo(P.X+Arrow.X,P.Y-Arrow.Y);
  except
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  O, P : TPoint;
begin
  O := Point(100,100);
  P := Point(200-Random(140),200-Random(140));
  DrawArrow(Canvas, O,P, 15,15);
end;

initialization
  Randomize;
end.

0
 

Author Comment

by:blitz051697
ID: 1361270
Great Example.   This helps--I failed Geometry.

blitz
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question