atan2 will return a value in the range [−π,π]. If θ ≥ 0, i.e. θ ∈ [0,π] then π − θ ∈ [0,π]. Likewise, if θ < 0, i.e. θ ∈ [−π,0) then π + θ ∈ [0,π). So your second computation will never result in negative values. The first...

c++,math,matrix,rotation,atan2

Just a hunch, but is the localTransform matrix completely recomputed each time step? Or could you be adding a rotation to a matrix that's already been rotated in the previous iteration. This could explain the continuous rotation. ...

Update: Complete working code added Here is some pseudocode to help you figure out where you tapped. This is with reference to the topmost figure. (I'm assuming your circle's center coincides with the view's center): (1) Find the direction of the line-segment from the center of the circle to the...

python,opencv,geometry,atan2,radians

I believe you're finding the angle that's complementary to the one you want. A nearly vertical line will have a very small angle with respect to the y-axis, but a near 90-degree angle with respect to the x-axis. Consider your line segment to be the hypotenuse of a right triangle....

python,trigonometry,angle,atan2,cartesian-coordinates

The easiest and most logically way to get at this problem is using the dot-product. Try this code (I've commented practically everything): import math def dot(vA, vB): return vA[0]*vB[0]+vA[1]*vB[1] def ang(lineA, lineB): # Get nicer vector form vA = [(lineA[0][0]-lineA[1][0]), (lineA[0][1]-lineA[1][1])] vB = [(lineB[0][0]-lineB[1][0]), (lineB[0][1]-lineB[1][1])] # Get dot prod dot_prod...