0
$\begingroup$

I have 2 lines that i draw like this:

PointF PitCenter = new Point(150, 186); PointF p = new PointF(PitCenter.X - 20, PitCenter.Y - 250); PointF p2 = new PointF(PitCenter.X + 20, PitCenter.Y - 250);  DrawLine(PitCenter, new PointF(     (p.Y - PitCenter.Y) * Math.Sin(Alpha * Math.PI / 180) + p.X),     PitCenter.Y + (p.Y - PitCenter.Y) * Math.Cos(Alpha * Math.PI / 180));  DrawLine(PitCenter, new PointF(     (p2.Y - PitCenter.Y) * Math.Sin(Alpha * Math.PI / 180) + p2.X),     PitCenter.Y + (p2.Y - PitCenter.Y) * Math.Cos(Alpha * Math.PI / 180)); 

New X calculation: (p.Y - PitCenter.Y) * Math.Sin(Alpha * Math.PI / 180) + p.X)

New Y calculation: PitCenter.Y + (p.Y - PitCenter.Y) * Math.Cos(Alpha * Math.PI / 180)

Here are the lines when Alpha = 0;

enter image description here

And here are the lines after 90 degrees rotation..

enter image description here

As you see the lines somehow meets.. i really cant understand why.. Any ideas?

1 Answers 1

3

Looks like you got the parentheses mangled in your line drawing commands -- the PointF constructor has only one argument and the DrawLinemethod has three; presumably that should be two and two? But that would lead to an error at compile time, so I presume you just didn't copy the code that you're actually using (which is a bad idea).

The reason the lines don't come out right is that you're applying the rotation to the $y$ coordinate but not to the $x$ coordinate. For instance, the first line drawing command should read

DrawLine(PitCenter, new PointF( PitCenter.X + (p.X - PitCenter.X) * Math.Cos(Alpha * Math.PI / 180) + (p.Y - PitCenter.Y) * Math.Sin(Alpha * Math.PI / 180), PitCenter.Y + (p.Y - PitCenter.Y) * Math.Cos(Alpha * Math.PI / 180) - (p.X - PitCenter.X) * Math.Sin(Alpha * Math.PI / 180)));