-1

I am having trouble getting an accurate angle measurement and converting it to degrees.

I first calculated the distance with:

double distance = Math.Sqrt(deltax + deltay);
Console.WriteLine("Distance :" + Math.Round(distance, 3));
Console.WriteLine("");

Then tried to calculate the angle:

double angle = Math.Atan2(deltay, deltax);
double RadiantoDegree = (angle * 180 / Math.PI);
Math.Round((decimal)angle, 3);
Console.WriteLine("Angle :" + angle)

With inputs such as x1=2, y1=2, x2=1, y2=1, the angle should measure -135.000 degrees.

andand
  • 15,638
  • 9
  • 48
  • 76
  • 1
    What were the inputs, and what output did you get, and what output were you expecting? – Carlos May 28 '16 at 18:02
  • Your conversion from `double` to `decimal` could introduce precision and rounding variances in the output. Is your calculation off by a small amount, or is it completely wrong? – gmiley May 28 '16 at 18:06
  • With inputs such as 1x=2, 1y=2, 2x=1, 2y=1, the angle should measure -135.000 degrees. However I got 0.785 degrees. – Ashley Lauren May 28 '16 at 18:10
  • Okay now your input is confusing me. Are these two different input sets? – Keiwan May 28 '16 at 18:15
  • What are the values that are going into `deltay` and `deltax`? – gmiley May 28 '16 at 18:19
  • 1
    Are you still having a problem or did you get it resolved? If the answer below solved the issue for you, could you accept it as the answer so that the question is marked as solved? – gmiley May 28 '16 at 19:06

1 Answers1

2

The problem is that you are not using your converted value of angle.

You could do:

angle = (angle * 180 / Math.PI);

instead of defining RadiantToDegree but never using it. So what happens is right now you are basically just printing your angle in radians.

Keiwan
  • 7,331
  • 5
  • 31
  • 48