# Tag Info

## Hot answers tagged linear-algebra

### Benefit of using Vector2 data type over separate x & y variables

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, ...
• 14.9k
Accepted

### How can I rotate an object based on another's offset to it?

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 ...
• 3,126
Accepted

### How do game engines avoid recalculating normals upon mesh rotation?

They don't. When you rotate a mesh, the normals in memory are not changed in any way. All that changes is the object's transformation matrix is updated. The raw mesh vertex and normal data remains ...
• 135k

### How does a 4x4 matrix represent an object in space and matrix lore?

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 ...
• 135k

### What are some good examples of the practical usages of cross product in game development?

Generating Normals As Maximus Minimus notes in the comments, when we have a mesh without normal vectors (say just raw vertex positions from a procedural generator or 3D scanned point cloud), we can ...
• 135k

### How do game engines avoid recalculating normals upon mesh rotation?

DMGregory's answer explains how this is actually handled, but I'd like to point out a couple of misconceptions: Assume that a face of a mesh is defined by vertices ...
• 5,498

### Benefit of using Vector2 data type over separate x & y variables

Compare the function signatures of both RotatePoints versions. Lone variables: ...
Accepted

### Why does a unit vector show direction?

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: ...
• 3,241

### Benefit of using Vector2 data type over separate x & y variables

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. ...
• 1,476

### How can I find the perpendicular to a 2D vector?

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

### What does a linear transformation preserve?

Linear transformations preserve: Collinearity. If three points are collinear before the transformation, they remain collinear afterwards. Parallelism. If two lines are parallel before the ...

### Benefit of using Vector2 data type over separate x & y variables

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, ...
• 20.2k
Accepted

### How to mirror/reflect/flip a 4D transformation matrix

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 ...
• 27.2k
Accepted

### 2d Scale width and height based on distance

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 ...
• 14.9k
Accepted

### Is it possible to calculate a direction vector without sqrt?

If you want a correct mathematical result (correctly rounded to within floating point precision), a square root is the way to go. It's true that it's more expensive than a multiply, but it's still ...
• 135k
Accepted

### Need help with getting a direction vector between two given points

In your situation you need a simple subtraction, with a normalization. vectDistance = B - A vectDirection = vectDistance / lenght(vectDistance) This will give ...
• 16.3k
Accepted

### How to project a Vector3 onto the xz plane?

You can 0-out the Y coordinate. This is called an orthographic projection: ...
• 5,295

### How to determine whether the direction of rotating a 2D vector to another one is counter-clockwise or clockwise using the cross product?

I think the book means if a.Cross(b).z > 0 then ... else ... which translates to if (a.x * b.y - a.y * b.x > 0) (...
• 2,035
Accepted

### How to scale major and minor radius of a quarter torus

To my knowledge, this is not possible using a transformation matrix since matrices represent linear transformations and the transformation you are asking for isn't linear. The answer in this SO ...
• 589
Accepted

### Difference between World matrix and Model matrix?

The names "world matrix" and "model matrix" are just terminology, and are not 100% standardised, so depending which source you read you may see them being used to refer to a number ...
• 20.2k

### How can I rotate an object based on another's offset to it?

You could also use a more general approach: The math for your problem already exists in the form of the scalarproduct (or dot product). You only need to get the directions of your weapons forward ...
• 131
Accepted

### Convert global 3d coordinate system to a local one with specific direction

Construct a matrix like so, where each vector is one column of the matrix: [ House's X+ direction | House's Y+ direction | House's Z+ direction | House's position] The fourth row should be [0, 0, 0, ...
• 135k
Accepted

### How to set rotation of object using angle between two points?

You should always question whether an angle is actually necessary, or if a vector would suffice. Here, all we need is the vector from the start to the end: ...
• 135k
Accepted

### Should 3D transformations be represented by a 4x4 matrix or a 3x4 matrix?

Since 3D transformations are represented by 4x4 homogeneous matrices Correction: Might be represented by 4x4 matrices ;) Now I can see how this would be a great optimization at first as it ...
• 589
Accepted

### LibGDX Efficient way to reduce a vector's value gradually until it reaches 0,0

If you don't need the deceleration to be the same fixed amount each frame, you can instead apply a "drag multiplier". This is used in many games as a crude approximation of air resistance, ...
• 135k
Accepted

### Invert parent transform (doesn't work for combination of rotation and scale)

A 4x4 homogeneous matrix can represent any affine transformation. That is, any combination of: Translation by any offset Rotation around any axis by any angle Scale along multiple arbitrary axes by ...
• 135k
Accepted

### How to fix diagonal velocity being greater than axis-aligned?

Is there a fix for this so no matter what of the 8 I travel its the same speed? Yes... You want to apply a total force and split it between x and y To do this for any angle, you apply ...
• 1,278