# Tag Info

45

Radians are used in math because They measure arc-length on the circle, i.e. an arc of angle theta on a circle of radius r is just r * theta (as opposed to pi/180 * r * theta). When trig functions are defined in terms of radians, they obey simpler relationships between each other, such as cosine being the derivative of sine, or sin(x) ~= x for small x. If ...

20

I believe your intuition was correct, just not your formula. atan(4 / 3) = 53.1301024 degrees This ratio can be useful because it forms a Pythagorean triangle, meaning that the length of the diagonal is an exact integer value.

17

Here's my simplified, branchless, compare-free, no min/max version: angle = 180 - abs(abs(a1 - a2) - 180); Removed the modulo, as the inputs are sufficiently constrained (thanks to Martin for pointing that out). Two abs, three subtracts.

10

Although they compare properly, the difference between them is 315 degrees instead of the correct 45 degrees. What makes you think 315 is incorrect? In one direction, it is 315 degrees, in the other direction, it's 45. You want to choose whichever is the smallest of the 2 possible angles and this seems to intrinsically require a conditional. You can't ...

8

The industry standard for first-person view simulation in most shooters is to have character models and animations distinct from those used for third-person view. There are several reasons for this: The player has a much smaller field of view upon the world than a real person in the character's situation would, and he lacks other forms of input such as ...

7

Calculate a vector from B to A, normalize it (divide by the vector's length), then multiply by the circle size: vx = A.x - B.x vy = A.y - B.y length = sqrt(vx*vx + vy*vy) C.x = vx / length * size + A.x C.y = vy / length * size + A.y For the angle you can use the atan2 function, if your language has it.

6

Normally I store all objects as 4x4 Matrices (you could do 3x3 but easier for me just to have 1 class) instead of translating back and forth between a 4x4 and 3 sets of vector3s (Translation, Rotation, Scale). Euler angles are notoriously difficult to deal with in certain scenarios so I would recommend using Quaternions if you really want to store the ...

6

This " answer " is to add some visual information to the answers already given. 2: We first create a vector ( 2D in this case with component x and y ) by taking the difference from both positions ( mouse - player ). 3: We then Normalize it to create a so called " unit vector ". Which means to bring the length of our vector to 1. This is done by ...

6

You do not need to know the angle, because the difference in X and Y already gives you the desired orientation of the enemy. The only thing that remains to be done is normalise that direction vector (if possible -- otherwise it means the player and the enemy are exactly at the same position), and multiply it by the enemy’s speed: dx = player_x - enemy_x; dy ...

6

That vector can be obtained simply by summing up the normals of the boxes faces and normalize. The normal vector even point outside the box so the sum vector points toward the direction where the boxes exit from the intersection. along with the vector you need the intersection segment too (if you still don't have it)

6

Two parts: 1. coordinate systems for angles can be...finicky. 2. You don't really need degrees for anything, with the possible exception of outputting their value to the user interface. Coordinate system angles So you want an angle from "North", and judging from your example math, that means the -Y direction (in sprite coordinates with the origin in the ...

6

I'm a bit skeptical of using atan here, because the tangent ratio shoots off to infinity at certain angles, and may lead to numerical errors (even outside of the undefined/divide by zero case for shooting straight up/down). Using the formulae worked out in this answer, we can parametrize this in terms of the (initially unknown) time to impact, T, using the ...

5

First figure out the direction based on where the particle is in reference to where it came from (the explosion). Then you take the arc-tangent of that to get the angle. Vector2 direction = particlePosition - explosionPosition; float angle = Math.Atan2(direction.Y, direction.X);

5

The sign of the dot-product of C with AB will be positive when the vector component of CD parallel to vector AB is in the direction AB, and negative when it is in the direction BA. The sign of the (z-component of the) cross-product of vector CD with vector AB will indicate which side of AB the agent is approaching from. Depending on your sign conventions, ...

5

When people refer to an isometric perspective in the context of pixel art or video games, they are usually talking about a dimetric projection where the z-axis is vertical and the x and y axis go diagonal with a vertical:horizontal ratio of 1:2. The reason is that this is much easier to pixel than a "true" isometric projection: Alternatively there are ...

4

Simple? NewPos = new Vector2(825 * sin(85 degrees), 825 * cos(85 degrees)); Most libraries use radians not degrees, so: radians = degrees * PI / 180 If you want the coordinates in the world reference frame, you will need to get the direction of the Tank, subt add the centre Tanks origin to the result: NewDir = TankDir + 85; NewPos = new Vector2(825 * ...

4

double angle = Math.atan2(y,x); // Note: keeping angle in radians for cos & sin. dx = enemy.speed * Math.cos( angle ); dy = enemy.speed * Math.sin( angle ); This will work fine with negative angles. See also: What are atan and atan2 used for in games?

4

GLM's rotation function uses Euler's rotation theorem, which implies that any rotation or sequence of rotations of a rigid body in a three-dimensional space is equivalent to a pure rotation about a single fixed axis. However consecutive calls to GLMs rotate function just multiply the rotation so rotating a rigid body by Yaw, Pitch, Roll is as simple as this:...

4

Nathan's answer is very concrete. I'd like to supply a more general view: The most complex mathematical concept that is natively implemented in most processing units are floating point numbers as models for the field of real numbers ℝ. Visual geometriy is based on the three dimensional real vector space ℝ³. Coordinates are real numbers. Geometric quantities ...

4

As I found out later here isometric in video games in game development it is better to have tiles with a 1/2 height/width ratio, which displays better and is nice for calculations. As I measured, having those ratios also means having a 127 degrees angle. Later, I found this answer on gamedev : What is the view perspective angle of most 2.5D isometric games ...

4

Others have pointed out how you can use the sign of the dot product to broadly determine the angle between two arbitrary vectors (positive: < 90, zero: = 90, negative: > 90), but there's another useful geometric interpretation if at least one of the vectors is of length 1. If you have one unit vector U and one arbitrary vector V, you can interpret the ...

3

"dot" is a cosin not an angle, can not be compared to "fovRad" that is an angle You can get angle of "dot" with an arccosine function, or get the cosine of "fovRad" to compare them.

3

You are trying to fire an arrow from point a(player) to b(mouse position) in 2d space? you can simply do the following formula to get the direction. (rather than degree) v1 = ( Player.x, Player.y ); v2 = ( Mouse.x, Mouse.y ); dir = v2 - v1; dir.normalize(); arrow.xy += dir * speed; hope this helps you achive what you want.

3

Since your particles have a velocity you must have a velocity vector. Let's call the components vxand vy. You can then get the angle using: atan2(vy, vx)

3

When working with floating point values it's usually not a good idea to use the comparison operator, as even slight inaccuracies will result in inequality. That's why a comparison of floats usually incorporates some sort of "epsilon".. a margin of error. Example: if(Math.abs(floatA - floatB) <= epsilon){ // equal } Epsilon is the desired accuracy.....

3

Let b be the angle between vectors p1p2 and p1p3. Its value can be computed as: b = pi - atan2(p1p3.y, p1p3.x) The angle between p1p4 and p1p3 is b-a. Since p1p3p4 is a right-angled triangle, we know that cos(b-a) is the distance p1p4 divided by the distance p1p3. The answer is then: a = pi - atan2(p1p3.y, p1p3.x) - acos(r / length(p1p3)) Replacing ...

3

you can use atan2. for example: float radians = Math.atan2(object2.y - object1.y, object2.x - object1.x); and then if you want the degrees its like this: float degrees = radians * 180 / PI

3

The Red is: atan2(vectorA.y - vectorB.y, vectorA.x - vectorB.x) The Green is: atan2(vectorB.y - vectorA.y, vectorB.x - vectorA.x) The Blue which I think is what you are looking for: atan2(vectorA.y, vectorA.x) - atan2(vectorB.y, vectorB.x) You can use abs() if you want the absolute value like I think you do. Sometimes you will get a value that is ...

3

If the resulting scalar is 0; then it means the 2 vectors are perpendicular to each other (angle difference 90 degrees) . If the resulting scalar > 0; then the angle difference between them is less than 90 degrees. If the resulting scale is < 0; then the 2 vectors are facing opposite directions ( or angle difference > 90 degrees). This can be useful in ...

3

You get the path the same way you'd move the object when you shoot it. Just have a tight loop that simulates the movement of the object and keep track of the position every so often. Now you have a list of positions, if you draw a dot at each position, you have a dotted line the represents the path of the object if it were to be shot from that angle.

Only top voted, non community-wiki answers of a minimum length are eligible