Tag Info

Hot answers tagged

43

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 ...


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.


4

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, ...


3

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 ...


2

A possible solution is to use the Dot Product. Of course, you need two vectors and not two angles, but I guess you're using them (otherwise I wouldn't explain how you're having 3D angles). Quoting Van Verth & Bishop from the book Essential Mathematics for Games & Interactive Applications, page 30-31: A more common use of the dot product is to ...


2

to complete the answer: angle = atan2((C-A).y, (C-A).x) + PI/2;


2

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 ...


2

It looks like your code to mirror the bullet's angle just flips the sign of the angle. This works great for reflecting an angle about the x-axis. 45 degrees becomes -45 degrees, etc. Now imagine reflecting off a wall that itself has an angle of 90 degrees. In this case, 85 degrees is reflected to 95 degrees; 45 degrees becomes 135 degrees, etc. Basically ...


2

If I understand what you're asking, the vector CD is just a vector, not a ray, so only the direction matters, not location. However, AB is a line segment, not just a vector, so its location matters. Your tests have one 'if' test to make two cases, but I think you actually have four cases. Let's look at the diagram in AB's reference frame: If you can ...


1

atan2(y1-y2, x1-x2) or maybe atan2(-(y1-y2), x1-x2), depending on the coordinate system.


1

The white vector is the correct vector with the code you have. If you're only ever adding integers to your position, the movement is going to be at increments of 45 degrees. That's restricted to orthogonal and diagonal movement only. If you want free movement you should be normalizing the movement vector. Check to see if the libraries you're using have a ...


1

No conditions, you don't need normalised vectors, a single trig function: Vector2 pc = p - c; float crossp = pc.x * ray.direction.y - pc.y * ray.direction.x; float dotp = pc.x * ray.direction.x + pc.y * ray.direction.y; return Math.atan2(crossp, dotp); Here is the explanation. A fast summary: Cross product between two vectors is the same as sin(theta) * ...


1

We find the vector from c to p (p - c), and compute its angle with the x-axis. Then we subtract, and put it into the right range. theta2 = atan2(p_x - c_x, p_y - c_y) alpha = theta2-theta if (alpha > pi) alpha -= 2pi if (alpha <= -pi) alpha += 2pi This assumes that theta is in the range (-pi, pi], and atan2 gives its result in the range (-pi, pi] ...


1

A solution that would work in all cases would be inverse kinematics. You may want to look it up, but that is quite a complex topic. Here is a general solution for your special problem: I don't really understand how the TopDondur and Berrels are related (or even what TopDondur is supposed to be) so I will for sake of simplicity assume only on "character". ...


1

As it says: // Angle adjustment to make 0 up to match how our sprite was drawn. var angleAdjustment = -90; Likely that means the sprite was created with the plane facing right. This adjusts it to face "up". The angle doesn't have any thing to do with the coordinates system. Remember that you can always use the coordinate system you're familiar with and ...


1

This depends on your camera. So if the camera is directly facing the object, you can do this. The surface normal is lets say (x,y,z). z meaning the depth. Then just make z = 0, as if you are projecting it in to plane. Then angle is simply atan2(y,x). This is for the simplest case though. IF the camera is not aligned with the object then you have to figure ...


1

Changing your camera, like the other fellows said, is probably the best, but if you still need the Camera to have perspective projection, you can use LookAt(), like this: 3dGameObject.transform.LookAt(camera.transform); Basically it makes your game object to rotate in order to look at something. Take a look at the documentation for more information on ...


1

First off, you probably want to switch your camera to orthographic, so that you don't get perspective distortion in the image. Then I wouldn't put the image on the ground like that, but rather a plane perpendicular to and linked to the camera. Then rather than rotating the player around, I'd be orienting the camera so that the player looks correct. The ...


1

If you know which direction the characters are facing, you calculate the dot product of those directions. If the characters only move on the ground plane it is pretty staightforward to decide which side are you on. If the dot product is 0 then you face exactly the side of the opponent. Then you check for some interval against zero and decide if you are on ...


1

Instead of an approach that relies heavily on trig (ie. your Atan2) as a means to solve the problem, 3d lends itself to a more linear algebra approach. float v1ComponentAlongD = Vector3.Dot(v1, d); // look ma, no angles Check out the last two paragraphs in Shawns blog here: http://blogs.msdn.com/b/shawnhar/archive/2010/02/12/doing-math-in-2d-vs-3d.aspx ...


1

For FPS cameras, there is no technical reason why the pitch needs to be smaller than +/- 90 degrees; the reasons for limiting it are purely gameplay-related, and it's obvious if you've encountered it. When you are looking straight up or down, attempting to look left or right will not move your reticle with respect to the game world, instead you simply ...


1

I don't think there's a standard value. Some games let you go all the way to 90 degrees; some cut you off at somewhere around 85 degrees, I'd guess. I don't think the precise value is a big deal. Regarding the point about Euler angles, gimbal lock, etc. - there's actually no particular reason to limit the pitch to strictly less than 90 degrees, aside from ...


1

While I use radians too, for all the reasons specified, there's at least one good reason why degrees are preferred: Precision and accumulation of errors. Rotating through a full circle 1 degree at a time is exact. Rotating through a full circle 2PI/360 radians at a time is not. Performing a 90 degree rotation 4 times on a pixel grid gets you back to ...



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