1

I implemented a method in javascript to compute the angle between 2 vectors. But I don't know how to compute the angle that lies in the polygon.

example For example, in this image I want to compute the red angle but in the left one I need to go from AC to AB while in the right one I need to do it from AB to AC.

Thank you for your response

  • can you add give the code? – Roland Starke Aug 15 '17 at 11:21
  • 2
    https://stackoverflow.com/questions/28821329/interior-angles-of-irregular-polygon-with-angles-180 – stark Aug 15 '17 at 11:26
  • here explains how to compute the angle of two vectors https://stackoverflow.com/questions/21483999/using-atan2-to-find-angle-between-two-vectors – Alex villey Aug 15 '17 at 11:42
  • The code I used to compute the angle is the one sent by @Alexvilley. I can compute the angle but I have no information to know if the angle lies in the polygon or not. – user1241025 Aug 15 '17 at 12:34
  • @user1241025 Do you know vertex order (CW or CCW)? And why do you need an angle? – MBo Aug 15 '17 at 13:52
  • An extremely trivial way of the top of my head is that if you know if a point is inside the polygon, you can figure out if you have the angle you want or if it is 2pi-angle you have. To find if a point is in the polygon or not, google gave me this: http://www.geeksforgeeks.org/how-to-check-if-a-given-point-lies-inside-a-polygon/ – Shawn Aug 15 '17 at 16:50
  • @MBo Yes I know the vertex order and I need to create a vector that contains all the angles of a vertex between 2 consecutive vertices that are visible from this vertex. I don't know if my english is clear so in the left image, The point A need to return a vector that contains 2 angles; the angle from B to the bottom left vertex and an angle from C to the bottom left vertex. In the right image, the point A returns a vector with 4 angles : angle from B to the bottom right vertice, from the bottom right to the top right, from the top right to the top left and from the top left to C. – user1241025 Aug 15 '17 at 17:21

1 Answers1

1

From the question I understand that you need values of red (internal) angles. It is easy to get them knowing order. For CCW order find directed angle between two consecutive edge vectors. In the first case vectors are BA/AC, in the second CA/AB

To get directed angle in full 2*Pi (360 degrees) range, you can use atan2 function

Fi_left = atan2 (crossproduct(BA, AC), dotproduct(BA, AC))    
Fi_right = atan2 (crossproduct(CA, AB), dotproduct(CA, AB))
MBo
  • 77,366
  • 5
  • 53
  • 86