Saturday, January 1, 2011

Angle between 2 points in a 2D space

Q. How can we find the angle between two points in a 2D space as shown in the figure if the
positions are given


take this care
Point Ax = 2.8
Point Ay = 3.2

Point Bx = 5.2
Point By = 6.2

say you are doing this calculation in python here it goes in python

import math

angle = math.atan2(Bx-Ax, By-Ay)
ie
angleR = math.atan2(5.2-2.8, 6.2-3.2)
0.6747094222355274
since this result is in radians u neet to convert it to degrees using

math.degrees(angle)
38.659808254090095

1 comment:

  1. Hi, one thing to take into account (to get the desired result):
    atan2(y,x)

    ReplyDelete