# Tag Info

48

To get the 2D vector perpendicular to another 2D vector simply swap the X and Y components, negating the new Y component. So { x, y } becomes { y, -x }.

39

First of all, it's way less clutter. If you have a position, a velocity and an acceleration, that's already 6 variables you have to deal with, 9 in 3d. Secondly, and this is the most important part, it grants you access to many ways to use or change them. For instance, getting the length of the vector, normalizing it, adding them together, dot product, ...

31

The answer is actually pretty easy if you do the math. You have a fixed distance of Y and a variable distance of X (See Picture 1). You need to find out the angle between Z and X and turn your turret that much more. Step 1 - Get distance between the turret line (V) and the gun line (W) which is Y (this is constant but doesn't hurt to calculate). Get ...

23

Yes, To name a few: Pannini Mercator Fisheye Miller The Pannini projection, for example, can capture wide fields of view in nice ways. (totally just my opinion) I think implementation details would be beyond the scope of this specific question. EDIT: Thanks for the comment, I did misspell Pannini. And to make this edit worthwhile here are a few more: ...

17

I always forget how to do this when I need it so I wrote a couple of extension methods. public static Vector2 PerpendicularClockwise(this Vector2 vector2) { return new Vector2(vector2.Y, -vector2.X); } public static Vector2 PerpendicularCounterClockwise(this Vector2 vector2) { return new Vector2(-vector2.Y, vector2.X); ...

15

It depends on what you mean by "that could be used in a 3D system such as OpenGL". :) Narrowly speaking, 3D graphics hardware and APIs like OpenGL only deal correctly with linear projections - projections that map straight lines in world space to straight lines on the image. They never distort something into a curved shape (unless it was curved to begin ...

15

Compare the function signatures of both RotatePoints versions. Lone variables: void RotatePoints( float *out_x, int x_interleave_out, const float *in_x, int x_interleave_in, float *out_y, int y_interleave_out, const float *in_y, int y_interleave_in, float angle, int count ) { float s = sinf(angle); float c = cosf(...

11

First we get a vector from B to A, as in the following picture: Now we have a vector that tells us how to get exactly from B to A. In code it looks something along these lines: var BtoA = A - B; In the above image's case, the resulting vector is X:15 Y:-20. At this point we actually already know the direction, as it is included in the information of how ...

11

Readability > Writeability I feel like it's just slow me down and barely has any benefit other than organizing your code. You are correct in that it (slightly) slows you down writing that code. However, you write it once in the beginning and from then on everytime you come back you are going to read it. So optimizing the reading speed will do much more ...

10

Vector3 vT = v2 + headingNorm * 3; Be careful though, if v2 and v1 happen to be closer than 3 units away this will put you on the far side of v1. Maybe you want this to make the unit step back to make room for the attack. But then again be careful, because that means as you approach that attack point you will overshoot then correct and overshoot the ...

9

A 2D vector has two values (x and y), and it basically says how far you go from the point of origin in the x- and in the y-direction. For example, a vector of (3,4) goes 3 units in x direction and 4 units in the y direction, resulting in an angled line with a length of 5 (3² + 4² = 9+16 = 25, root of that is 5). So the vector basically gives you two pieces ...

8

Ahh yes. I threw my math at it and I think I hit it. You're correct it does involve the Pythagorean theorem and some scaling. You start with your normalized vector that represents your ray. It has an x component and a y component. First we want to see how long it is when it travels one unit in the x direction. So what do we do? We want to scale the entire ...

8

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.

8

How is Matrix Multiplication a Transformation? A matrix is just a big grid of numbers with rules that define how we can multiply it with other grids or lists of numbers. In games, we usually want to construct a matrix so that, when multiplied with a list of numbers representing a source position (say, the position of a vertex in a mesh) we get a list of ...

8

Operator overloading. Vector v3 = v2 + v1; There is now only one place in your code where you have to write, test and debug vector addition, as opposed to tens, hundreds or thousands. Obviously vector addition is an overly simplistic example, but there are more complex vector operations and the same applies to those too.

6

Mathematically, the quantity you're asking about is called the operator norm. Unfortunately, there's no simple formula for it. If it's a fully general affine transformation - for instance, if it could have an arbitrary combination of rotations and nonuniform scales, in any order - then I'm afraid there's nothing for it but to use singular value ...

6

I thought this would be an interesting challenge to test some of the math I learned in school, so here's what I figured out. This approach assumes each object can be considered a circle for collision purposes. Naturally a car isn't a perfect circle, but it could be used as an approximation. You could use more circles to fill the area of the car better if ...

6

To get a transformation matrix equivalent to the one you have, but reflected across a major axis you can compose it (multiply it by) a reflection matrix. That is, if you have your input matrix M and you multiply by a matrix N that has the reflection. To create the reflection matrix based on the major axis, you take the identity matrix and flip signs ...

5

This answer still ignores the attempt to use matrix rotation, but I realized that there was a simple yet general solution. First, assuming that the shape is encoded as coordinates of blocks in a grid, you have an arbitrary shape containing blocks with coordinates in the X and Y axes from 0 to n, where n+1 is the maximum size of a block (traditional Tetris ...

5

Assuming you've benchmarked this and are sure this is a bottleneck keep reading. If not stop. Don't worry and be happy :). It's true that you will need to run the collision check algorithm every time you fire a bullet. And depending on how long it takes the bullet/laser to disappear you will have to do it multiple frames. However when you implement a solid ...

5

Here is my suggestion. You just need two vectors. in the first triangle, choose the normal vector, n1 in the second triangle, choose a vector e2 from a point on the shared edge to the point not on the shared edge. Then compute their dot product: n1 . e2. If it’s positive, the angle is acute. If it’s negative, the angle is obtuse.

5

If , then a-perp obtained by a counterclockwise rotation by 90 degrees, i.e., See this link :)

5

If your transformation matrix is a rotation matrix then you can simplify the problem by taking advantage of the fact that the inverse of a rotation matrix is the transpose of that matrix. If your transformation matrix represents a rotation followed by a translation, then treat the components separately. The inverse is equivalent to subtracting the ...

5

A coder's guide to spline-based procedural geometry is a video from Unity event Unite 2015. In the video, the presenter gives visual explanation of how splines can be created and modified. Then, he goes on to give code examples for the same. Very informative. The video is for Unity3D, but the algorithms presented can be adapted to any platform.

5

In your situation you need a simple subtraction, with a normalization. vectDistance = B - A vectDirection = vectDistance / lenght(vectDistance) This will give you the direction. In LibGDX, you can use the sub method from the Vector2 class, along with the nor from the same class: vectDirection = b.sub(a).nor(); To help figure out if you need to ...

5

The very complex and hard to understand calculation people do to get an object's size at a specific distance is: divide by Z. Even the big APIs, like DirectX and OpenGL are basically just rasterizing APIs with a depth buffer. The 3d aspect comes from this. So: Given a width, a height and a distance from the camera Z, the new width and height of the object ...

5

Linear transformations preserve: Collinearity. If three points are collinear before the transformation, they remain collinear afterwards. Parallelism. If two lines are parallel before the transformation, they remain parallel afterwards. This implies that a grid will remain a grid after the transformation. The Origin. The origin point will be the origin ...

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

you can concatinate 3 matrices first a translation to put 1,1 at 0,0, then the rotation and then translate 0,0 back to 1,1 if you use affine transformation matrices this is easy [1,0,-1][0,1,-1][0,0,1] * rotationMatrix * [1,0,1][0,1,1][0,0,1] if you don't use affine transformations then just subtract 1,1 on each point then rotate around 0,0, then re-add ...

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