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
0
votes
2 answers

Why is −π < atan2(y, x) ≤ π while for lines we really need only from 0 to π?

Possible Duplicate: what is the difference between atan and atan2 in c++ ? Why is −π < atan2(y, x) ≤ π while for lines we really need only from 0 to π and what has api like atan2 but would return from 0 to pi?
Rella
  • 65,003
  • 109
  • 363
  • 636
0
votes
1 answer

Why is Math.atan2 not working correctly for me?

I'm trying to create a simple game where the rectangle in the center always points towards the mouse. For some reason, when I use Math.atan2 I get weird values that never go above 3 for the angle... Here's the sketch with my code function…
Evan Wild
  • 31
  • 3
0
votes
1 answer

how does atan2 work? which angle is actually calculated?

As you can see in the picture, I have a line and two points(p1 and p4). what I need to do is to get snapped point of p1/p4 on the line and then use atan2 to calculate the angle between (p1 and p2) and (p3 and p4). Now, I have two formulas: var…
Maryam Koulaei
  • 750
  • 2
  • 9
  • 17
0
votes
1 answer

Computing phase angle in fft matlab

I am trying to compute the phase angle in the frequency domain (after computing fft) of the second component of the Fourier spectrum of a synthetic signal constructed by me in the workspace of Matlab. I am sure that the phase is equal to 0 (as you…
0
votes
1 answer

atan2f() doesn't work

I try to change the orientation of my objects towards the center with atan2f but it's give me the wrong value. Am I wrong somewhere ? glm::vec3 center = glm::vec3(0.4f, 0.4f, 0.0f); for(int i = 0; i < num; i++){ float rel = i / (float) num; …
Vitge
  • 49
  • 1
  • 5
0
votes
0 answers

How to move character with keys and mouse, together?

I'm attempting to move a character so that they face the mouse when I move it; I understand the concept but am completely at a loss at how to code it. At the moment, I understand how to rotate the character separately and how to move the character…
Student
  • 39
  • 1
  • 11
0
votes
1 answer

Math.atan2 and cos sin angle not intersecting canvas

I need the circle to always be intersecting the line. I'm new to math functions and trying to get a solid grip on them. I think it has to do with sin and cos, but I could be wrong. Why isn't it behaving as…
Philip Bell
  • 75
  • 1
  • 6
0
votes
1 answer

C++ Creating Atan2 from Atan

How would i go about taking my atan function and make it into atan2? For example float myAtan2(double a, double b) { float atan2val = //calculate atan2 using atan return atan2val; } Sorry I'm not the best at trigonometry!
coddding
  • 333
  • 1
  • 6
  • 15
0
votes
2 answers

Having trouble calculating direction for particle explosion

I'm trying make a particle explosion system, where each particle explodes directly away from a central point. But I'm getting some really funky behavior. I'm using Math.atan2(y2 - y1, x2 - x1) * 180 / Math.PI; to calculate the direction to the…
0
votes
0 answers

Atan2 strange output when calculating angles c++

I am trying to calculate the angle from a Point in based in a quadrant, but I am getting strange values for some quadrants and Its resulting in a incomplete operation for me. Basically what I need to know is at what angle a object that has the…
Xabirau
  • 41
  • 9
0
votes
1 answer

Issue when rotating an object through the atan2 method

I'm trying to have an image follow my cursor, smoothly moving where it is located and turning to face it. When i'm near the origin, it works flawlessy: the image will flip completely without issues, however the further i go from the origin of the…
iv2b
  • 33
  • 8
0
votes
1 answer

Rotating a circle with mouse with direction

I am rotating a circle with a mouse but I want there to be a limit on how far the circle can be rotated. (Lets say 3 full times). When it reaches it's limit it can no longer be turned in that same direction, but the opposite direction it can be. I…
Nolemonpledge
  • 139
  • 1
  • 2
  • 11
0
votes
1 answer

Parameters for atan2() are incorrect in VS2005?

There seems to be a mistake in the math.h header provided with Visual Studio 2005. double __cdecl atan2(__in double _Y, __in double _X); inline float atan2f(__in float _X, __in float _Y) {return ((float)atan2((double)_X, (double)_Y)); } The…
James
  • 77
  • 1
  • 1
  • 6
0
votes
1 answer

Extended Kalman Filter - error in update step

I have to implement EKF without actually having good mathematical understanding of it. (Great... not...) So far I have been doing well but since I tried to implement the prediction step things started going wrong. The agent that uses EKF (red)…
Vetaxili
  • 609
  • 5
  • 12
  • 22
0
votes
1 answer

Using aTan2 to face an object to its destination

I've created an object that moves towards its destination with inertia. I am having alot of trouble getting the object to face its destination. My code is simple, it calculates the angle, converts it to degrees and passes that angle to the Matrix4…
user3906336