Hi Everyone,

I am trying to creale an application which is supposed to display some line trace.What I have is the lenght of lines and the angle
(Azimut) degree of the Line for example 45 degree.
Can you please let me know how I can do this? I also have the Start point location.

2
Contributors
5
Replies
10
Views
6 Years
Discussion Span
Last Post by Behseini

x1 = startx
y1 = starty
x2 = x1 + cos(angle) * length
y2 = y1 + sin(angle) * length

Regards,
Emil Olofsson

Hi Emilo,

Thanks for your reply but How I can use thses in C# ?!

Hi again Emilo

I trired the method that you sujested byt It seems there is something wrong with angle! here is the code which I create

`````` double length = 350;
double angle = 50;
double x1 = 200;
double y1 = 200;
double x2 = x1 + (Math.Cos(angle) * length);
double y2 = y1 + (Math.Sin(angle) * length);

int intX1 = Convert.ToInt32(x1);
int intY1 = Convert.ToInt32(y1);
int intX2 = Convert.ToInt32(x2);
int intY2 = Convert.ToInt32(y2);

System.Drawing.Graphics graphicsObj;
graphicsObj = this.CreateGraphics();
Pen myPen = new Pen(System.Drawing.Color.Red, 5);
graphicsObj.DrawLine(myPen, new Point(intX1, intY1),new Point(intX2, intY2));
``````

Can you please take a look at code and let me know if this correct ot not?

Edited by Behseini

Hi!

`Math.Sin` and `Math.Cos` takes angles measured in radians and not degrees. Try this:

``````double angleRadians = (Math.PI / 180.0) * angle;
``````

Then use `angleRadians` instead.

Regards,
Emil Olofsson