This question / bug is directly related to this Angle Measurer in C#. The problem seems to be that the theta is wrong in angles greater than 180 (I'm working in degrees, not radians).
Here's a helpful screen shot. This picture represents an overhead view of three dinosaurs. The body of the dinosaurs are in gray. The heads are a white dot. The 'angle of vision' for each dinosaur (not the same for all species) are the blue lines.
As you can see the facing of each dinosaur is correct. The theta for the angle between John and Julie looks correct. However, the angles from Julie to John and Muffie to John are quite wrong. Each should be > 180 degrees.
Here's the code snippet:
double DinoAFacing = FindAngle(
Dinosaurs[DinoA].Head.X,
Dinosaurs[DinoA].Head.Y,
Dinosaurs[DinoA].Location[Dinosaurs[DinoA].Location.Count - 1].X,
Dinosaurs[DinoA].Location[Dinosaurs[DinoA].Location.Count - 1].Y);
int Specie = ReturnDinosaurSpecie(DinoA);
double x = 50 * Math.Cos((DinoAFacing - 90) * (Math.PI / 180.0));
double y = 50 * Math.Sin((DinoAFacing - 90) * (Math.PI / 180.0));
x += Dinosaurs[DinoA].Head.X;
y += Dinosaurs[DinoA].Head.Y;
System.Windows.Point A = new System.Windows.Point();
A.X = x - Dinosaurs[DinoA].Head.X;
A.Y = y - Dinosaurs[DinoA].Head.Y;
System.Windows.Point B = new System.Windows.Point();
B.X = Dinosaurs[DinoB].Head.X - Dinosaurs[DinoA].Head.X;
B.Y = Dinosaurs[DinoB].Head.Y - Dinosaurs[DinoA].Head.Y;
double ALen = Math.Sqrt(Math.Pow(A.X, 2) + Math.Pow(A.Y, 2));
double BLen = Math.Sqrt(Math.Pow(B.X, 2) + Math.Pow(B.Y, 2));
double dotProduct = A.X * B.X + A.Y * B.Y;
double Angle
= Math.Abs(((180 / Math.PI) * Math.Acos(dotProduct / (ALen * BLen))));
slug = Dinosaurs[DinoA].PersonalName
+ " is facing: "
+ string.Format("{0:f2}", string.Format("{0:f2}", DinoAFacing))
+ "\nThe angle between "
+ Dinosaurs[DinoA].PersonalName
+ " and "
+ Dinosaurs[DinoB].PersonalName
+ " is "
+ string.Format("{0:f2}", Angle)
+ "\n"
+ Dinosaurs[DinoA].PersonalName
+ " CAN see "
+ Dinosaurs[DinoB].PersonalName;
System.Windows.MessageBox.Show(
slug,
"Dino vision",
System.Windows.MessageBoxButton.OK);
Can any of you math boffins see the error of my ways?
Thanks!
Edit: Screen capture showing that the projection of a point 50 meters in front of the dinosaurs along their axis is correct:
Screen shot after the last changes:
This is 'my definition' of 'dinosaur angles' and what I would expect:
- Muffie is facing almost east (108 degrees). John is almost directly behind her and little to the left. I would expect that the angle between Muffie and John would be about 195 degrees.
- Julie is facing southwest (235 degrees). John is almost directly to Julie's right. I would expect that the angle between Julie and John would be about 87 degrees.
- John is looking almost directly at Julie (Julie is a little to the right of 'head on'). I would expect that the angle between John and Julie would be about 7 degrees.
I wonder if the numbers are correct but we need to 'normalize' them to the direction that the 'viewer dinosaur' is facing? The 'angle between dinosaurs' that I want is relative to the respective dinosaur.
In essence, I'm trying to determine which dinosaurs can see which dinosaurs based on their species 'angle of vision'.