How to calculate the Angle between 2 lines?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,
I have done my application with Drawing an Angle. But now i need to calculate the Angle(Degree) of the Line. I have pasted my code below. Please any can help me to sort out this problem.

<pre>public void calcTopAngle()
{
int vert1 = 0;
int horiz1 = 0;



if (pt1.X < pt2.X && pt2.X < pt3.X)
{

if (pt1.Y > pt2.Y)// will calculate angle from gray horizontal line to pt2
{
vert1 = pt1.Y - pt2.Y;
horiz1 = pt1.X - pt2.X;
double angle = Math.Abs(Math.Atan2(vert1, horiz1) * (180 / Math.PI) - 180);
label1.Text = Convert.ToString(angle);

}

}
}[/code]

<hr class="sig farooque

View the full article
 
Back
Top