## Drawing a Line with an Angle.

### Drawing a Line with an Angle.

Hi All, is there a way to draw a line with a angle value?

Here is what i've gotten so far but haven't been able to get it to work.

Thanks for any and all advice..

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
CenterX, CenterY, VectX, VectY: integer;
X1: integer;
DX,DY,Angle,Dis:Real;
Cx,Cy,Xd,Yd:Real;
begin
Cx:=ClientWidth div 2;Cy:=ClientHeight div 2;
Xd := Cx-X;
Yd := Cy-Y;
Dis := ARCTAN2(Yd, Xd);
Dx := Cos(Dis*Pi/180);
Dy := Sin(Dis*Pi/180);
For X:= 0 to 100 do
begin
Cx:=Cx-Dx;Cy:=Cy-Dy;
Form1.Canvas.Pixels[Round(Cx),Round(Cy)]:=clwhite;
end;
end;

### Drawing a Line with an Angle.

You want to draw non horizontal line ?

image1.canvas.pen.color:=clbalck;
image1.canvas.moveto(x1,y1);
image1.canvas.lineto(x2,y2);

If you don't want to use the line proc, I have an algorithm on
one of my delphi pages.

Rene
--
Ing.Buero R.Tschaggelar - http://www.ibrtses.com

### Drawing a Line with an Angle.

> Hi All, is there a way to draw a line with a angle value?

Assume you're at the point (X1,Y1) and want to draw a line of
a given length (R) at a specified angle (theta) with the X-axis.

The second point,  (X2,Y2), on the line would be:

X2 = X1 + R*COS(theta)
Y2 = Y1 + R*SIN(theta)

Remember that theta needs to be in Radians.  You can use the
math library routine DegToRad to convert Degrees to Radians.
You will also need to use TRUNC or ROUND, e.g.,
ROUND(R*COS(theta)), since the trig computations involve
floating point.

The points [ R*COS(theta), R*SIN(theta) ] would give you
points around a circle of radius R as a function of theta.

--
efg

Overland Park, KS  USA

efg's Computer Lab:  http://www.efg2.com/Lab

### Drawing a Line with an Angle.

How can you set the origin point (0,0) from the upper left corner of the
TImage to the lower right corner?  Such that positive x-values increase to
the left and positive y-values increase upward like a normal coordinate
system.

I am trying to plot an image and it is displayed upside down, not to mention
the scale is completely off.  I am able to do this in Visual Basic using a
Picture control with a minimum of fuss.

TIA,

Norb

Quote:> You want to draw non horizontal line ?

> How about :
>  image1.canvas.pen.color:=clbalck;
>  image1.canvas.moveto(x1,y1);
>  image1.canvas.lineto(x2,y2);

> If you don't want to use the line proc, I have an algorithm on
> one of my delphi pages.

> Rene
> --
> Ing.Buero R.Tschaggelar - http://www.ibrtses.com

Gordon Whittam contributed a very interesting "Snappy Line" project to my Computer Lab.

With the SnappyLine program you can draw "free" lines, which are lines that snap to each other and measure angles.  Lines can be
highlighted with a trackbar and erased when the trackbar is released. SnappyLine also demonstrates the creation of a LogFont for
drawing the text dimensions at any angle.

Take a look at the Snappy Line Lab Report at
www.efg2.com/lab/Graphics/SnappyLine.htm

efg
_________________________________
efg's Computer Lab:       www.efg2.com/lab
Delphi Books:  www.efg2.com/lab/TechBooks/Delphi.htm

Overland Park, KS  USA