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.

Thanks for your time in Advanced

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?

Thanks for your time

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

commented: Quickly solved! +2

Thanks Emilo,

You were very helpful

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.