Questions tagged [atan2]

A function in many programming languages for computing the arctangent with two arguments

A function in many programming languages for computing the arctangent with two arguments

152 questions
2
votes
1 answer

Python angle calculation for image rotation

I am working on an application which first needs to rotate an image slightly in order to deskew it. I have detected a vertical line down the image between two points (x1, y1) and (x2,y2). The vertical line is not entirely vertical - the second x…
user1022788
  • 419
  • 8
  • 18
2
votes
1 answer

Signed Char ATAN2 and ATAN approximations

Basically, I've been trying to make two approximation functions. In both cases I input the "x" and the "y" components (to deal with those nasty n/0 and 0/0 conditions), and need to get a Signed Char output. In ATAN2's case, it should provide a range…
user3303504
  • 525
  • 3
  • 20
2
votes
1 answer

How to find clockwise angle in degree between two vector in java

First I want to call this following vector as: Vector M1 = [O → M1]; Vector C1 = [O → E]; Vector M2 = [A → M2]; Vector C2 = [A → C]; Vector M3 = [B → M3]; Vector C3 = [B → G]; every M vector is main vector or base vector. My problem is how to find…
Zen3515
  • 309
  • 4
  • 12
2
votes
1 answer

Loop for atan2 function by year in R

I have an artificial data set that I created: x<-rnorm(100,10,10) y<-rnorm(100,20,10) Location<-c((rep("AB", 40)),(rep("TA", 30)),(rep("OP", 30))) Year<-c((rep("1999", 10)),(rep("2000", 9)),(rep("2001", 12)),(rep("2002", 9)),(rep("1999",…
KL2014
  • 37
  • 5
2
votes
2 answers

how to redefine atan2 function from -inf to inf in matlab?

I have a rotating vector R(x(t), y(t)) and I want to find an angle as a function of time. The atan2 is determined between -pi and pi, however it is inconvenient for me to analyse all dynamics. So, is there any way to expand atan2 from -inf to inf?
anatoly
  • 327
  • 2
  • 13
1
vote
3 answers

Limiting atan2 to specific angle ranges

I want my Player sprite to rotate following the position of the mouse cursor. I'm using atan2 to set up a 360 degree rotation action script for my Player sprite. atan2(XMouse-XPlayer,YMouse-YPlayer) - 90 Using this, 90 degrees is straight up, 0 is…
1
vote
2 answers

Weird behavior from Octave's atan2

I'm trying to port some Octave code to Java. I'm trying out atan2 so I have the following tries octave3.2:53> m1 = [1,2;3,4] m1 = 1 2 3 4 octave3.2:54> m2=[5,6;7,8] m2 = 5 6 7 8 octave3.2:55> atan2(m1,m2) ans = 0.19740 …
skytreader
  • 11,467
  • 7
  • 43
  • 61
1
vote
2 answers

atan2 with CGPoint Iterator

vector::iterator i; vector* bp = bicyclePad.bikePathPoints; for(i = bp->begin(); i != bp->end()-3; i++){ angle = atan2((*i).y/(*i).x) * 180/ PI; } I guess atan2 can only be used with floats and doubles. but I am trying to do…
John Riselvato
  • 12,854
  • 5
  • 62
  • 89
1
vote
1 answer

VBA Atan2 function returns incorrect result

I was trying to solve a problem over on Math Stackexchange (https://math.stackexchange.com/questions/4752547/3d-transformation-matrix-to-euler-angles) and I found that my problem seems to be related to VBA's execution of the Atan2 function. Here's a…
G.H.
  • 199
  • 10
1
vote
1 answer

how to map atan2() to only positive radian?

atan2(y, x) has that discontinuity at PI (180°) where it switches to -PI..0 (-180°..0°) going clockwise. if i apply the solution from this // rust (y.atan2(x).to_degrees() + 360.0) % 360.0 doesn't quite work with radians (y.atan2(x) + PI*2.0) %…
Bob
  • 23
  • 6
1
vote
2 answers

How to rotate rectangle toward mouse position on translated canvas? Javascript

—————————————————————————————— How do I rotate the gun (the gray rectangle) around the player toward the current mouse position? (preferably using vectors or Math.atan2()) Vanila Js I have tried but it doesn't stay on the player and doesn't rotate…
Pete21
  • 102
  • 11
1
vote
1 answer

How to get enemies to turn continuously using atan2()

I am trying to build a game where you control a pirate ship and other computer pirate ships try to attack you. I'm currently working on code that gets the enemies to turn to face the player, and I am running into an issue when atan2() returns a…
Alex Savic
  • 11
  • 1
1
vote
1 answer

Numerical evaluation of arctangent functions

I am having difficulties to interpret results of arctangent functions. This behaviour is consistent for all implementations I came across, so I will here limit myself to NumPy and MATLAB. The idea is to have circle of randomly placed points. The…
rad
  • 157
  • 1
  • 9
1
vote
1 answer

Math.Atan2(double.NegativeInfinity, double.PositiveInfinity) - bug, or undocumented breaking change?

Consider double result = Math.Atan2(double.NegativeInfinity, double.PositiveInfinity);. In .net 4.8 this returns NaN. In .net Core 3.1 or later this returns -0.7853981633974483. The documentation for Math.Atan2() states: If x or y is NaN, or if x…
Matthew Watson
  • 104,400
  • 10
  • 158
  • 276
1
vote
2 answers

Phase angle from FFT using atan2 - weird behaviour. Phase shift offset? Unwrapping?

I'm testing and performing simple FFT's and I'm interested in phase shift. I geneate simple array of 256 samples with sinusoid with 10 cycles. I perform an FFT of those samples and receiving complex data (2x128). Than I calculate magnitude of those…