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
3
votes
1 answer

What is the difference from atan(y/x) and atan2(y,x) in OpenGL GLSL

I've some problems in understanding the result of the function atan in glsl. Documentation is also lacking. For example I need to convert a vertex to spherical coordinates, transform the radius of the spherical coordinate and then convert it back to…
linello
  • 8,451
  • 18
  • 63
  • 109
3
votes
3 answers

Angle between 2 points with atan2

I was reading this post about getting an angle between 2 points and was wondering. I thought atan2 is defined for atan2(y,x) here it is atan2(deltaX, deltaY), why is x first now? public float getAngle(Point target) { float angle = (float)…
vuvu
  • 4,886
  • 12
  • 50
  • 73
2
votes
1 answer

What is the logic behind this nvidia 's arctan2?

Nvidia has some functions in Cg 3.1 Toolkit Documentation arctan2 is implemented as follows float2 atan2(float2 y, float2 x) { float2 t0, t1, t2, t3, t4; t3 = abs(x); t1 = abs(y); t0 = max(t3, t1); t1 = min(t3, t1); t3 = float(1) / t0; …
balu
  • 1,023
  • 12
  • 18
2
votes
2 answers

Shifting angles while using Atan2

I am currently using Atan2 to calculate the player heading angle. however after some trial and error I discovered that the in-game angle's are rather different to that of a "normal" lay out : ReturnedAngle = Math.Atan2(Y2 - Y1, X2 - X1); …
MrClear
  • 129
  • 1
  • 6
2
votes
2 answers

Is there a way to reverse the effect of atan2?

I have a specific question about reversing atan2, I will write my code example in PHP. $radial = 1.12*PI(); $transformed = -atan2(cos($radial)*2, sin($radial)*1.5); $backToRadial = ? Is there a way to reverse the transformed value to the start…
Tim
  • 23
  • 1
  • 5
2
votes
1 answer

At what point will the atan2 function reach a domain error for a zero value in c++?

If I have a function similar to this: c=atan2( a, 0 ) I am trying to figure out what the a value should be limited to in order to ensure atan2() does not result in any domain errors. So the question is how close to zero can a get before a domain…
masked
  • 81
  • 7
2
votes
2 answers

arctan2 discrepancy in NumPy

I have come across a puzzling issue when using arctan2 in Numpy. Searching for atan2 errors did not answer the question, but someone might know the reason for this. f = np.arange(0,100) w = 2*np.pi*f/50 x = np.arctan2(sin(-w*d/2)*cos(w*d/2),…
vlazzarini
  • 31
  • 2
2
votes
0 answers

Rotate clock hand to correct angle when dragging - Vanilla JS

I have implemented an analog clock with a minute hand and an hour hand. The purpose of this exercise is to rotate the clock hands to the corresponding angle of the hour label when dragging; i.e., when the mouse is being move around. Some examples…
Morfinismo
  • 4,985
  • 4
  • 19
  • 36
2
votes
1 answer

Using atan2() to find the intersection point of objects in a Brick Breaker game

I am looking at a source code of a brick breaker game created by r3ticuli(an user of GitHub). The below method checks whether two objects intersect each other or not, and if they do, the method checks and returns which part of the main object is…
Tom_the_cat
  • 159
  • 12
2
votes
1 answer

sympy's atan2 not full numerical evaluation

I am using sympy's atan2 and for certain values it isn't giving me the full numerical evaluation but giving me a (value + pi) from sympy import atan2 print(atan2(0.0037, -0.056)) gives the following output: -0.0659755361339305 + pi I want the…
GilMe
  • 23
  • 3
2
votes
1 answer

calculate anti clockwise angle between 2 points

I have a robot with red led and green led mounted at the front and back respectively. I want to calculate the head direction of the robot as in which direction is the greenLEd - redLed vector pointed to. How can I code it such that the points marked…
deathracer
  • 305
  • 1
  • 20
2
votes
2 answers

I´m getting the error, "atan2() takes exactly 2 arguments (1 given)"

I´m new to programing so I have no idea what went wrong. please help from math import atan2, pi x = int(input("value of x")) y = int(input("value of y")) r = (x**2 + y**2) ** 0.5 ang = atan2(y/x) print("Hypotenuse is", r, "angle is", ang)
2
votes
1 answer

Rotating an image to face mouse point using ATAN instead of ATAN2

In order to better understand how trigonometry works in game development, I've been creating little javascript snippets on CodePen. I managed to create an example that uses Math.atan2() to point a pixel-art shotgun at the mouse cursor. Now, I am…
Doug Beney
  • 310
  • 2
  • 13
2
votes
2 answers

Using atan2 for delayed rotation

I have been trying to create a delayed rotation effect with the right analog sticks. The code below takes the angle based on the right analog stick's input and brings the object steadily closer. Due to atan2 being a range of -pi to pi the changing…
2
votes
2 answers

How to get back from atan2 angle back to Coordinate

I calculated the angle of (-6/35) by using atan2(-6/35). The result is -9.7275785514016047. Now to get back I used the formula from Wikipedia distance = sqrt(6*6+35*35); angleRelativeToPatternOrigin = -9.7275785514016047; double x1 = distance *…
TruckerCat
  • 1,437
  • 2
  • 16
  • 39
1 2
3
10 11