# Questions tagged [linear-algebra]

Linear algebra is the branch of mathematics concerning vector spaces and linear mappings between such spaces. The tag is generally used for questions regarding calculations over vectors.

255 questions
Filter by
Sorted by
Tagged with
37 views

### Is this gimbal lock I'm hitting even with rotation matrices / quaternions?

I'm spawning a trigger box relative to another object using local offset. The engine I'm using does not provide a native function to make that conversion (at least in a way accessible to me), so I am ...
25 views

### Getting the scalar speed from an X and Y velocity [duplicate]

Given a Vector2(x,y) that represents an object's velocity, like so: ...
119 views

### Inconsistent Speed Of A Projectile Traveling On A Bezier Curve

What I'm doing: I'm moving a projectile to it's target along a Bézier curve with one control point. The projectile moves from Transform A to ...
188 views

### How do I use these Unity math functions in Godot C#?

Here's a list of math functions I'm having trouble finding a direct function match for in Godot C#: ...
8k views

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

Assume that a face of a mesh is defined by vertices A, B, C and that the normal of the face ...
78 views

### Generating tris for concave polygon 2D

I have an arbitrary array of points that describe vertices of the polygon 2D, they ar in order. To generate plane mesh for that, I need to generate tris. For something like circle/hexagon/square it is ...
101 views

### Finding the closest point on a circle to end of a ray in 3D

I have a circle in 3D space, so we have center C with radius r, and the normal of plane the circle lies on, N. There is also a normalized vector V that I am modifying to go far past the circle's ...
67 views

### How to calculate shadow position below arcing projectile in Isometric 2d tilebased grid?

I have an Isometric 2D grid-based tilemap, and am firing a projectile (at Vector P1 in image below) from the player (at Vector A) to a location "above" a target location (at Vector B). This ...
46 views

### Calculate direction to push player away from wall

I'm trying to write a common 2D game and using vectors for physics. I have 1 wall and 1 player object that can move diagonally (both are squares without rotation). When the player object collides with ...
85 views

### Convert terrain vertex position to global position

I am trying to set the terrain's heights data at runtime with a simplex noise function, while stumbling with converting the local position of the vertices to global position to use as input to keep ...
1 vote
129 views

### Deflecting projectiles back towards enemies

I am working on a 2D side scroller. I have created an enemy character that shoots at my player randomly within a specific time interval. So, I want to deflect the projectiles back toward the enemy ...
145 views

### How to set up view and model matrices for 3D rendering?

For various reasons I am building a very simple graphics engine. I have a pretty good 2D thing using plain SDL2 and C that essentially boils down to a single "putpixel" function. I can ...
30 views

### Error in directional light shadow projection matrix

I have VC++ code for DX9 that draws shadows perfectly. ...
107 views

### How to find the distance to the middle of the road from the car's current position?

I have the car's current position Vector3 and an API that gets me the closest point on the middle of the road to any Vector3 ...
1 vote
149 views

### What's the purpose of this cross product and dot product in triangle clipping code?

I have this code that inserts a triangle into the drawing list. The PHD_VBUF structure stores one x,y,z vertex. If the vertex is behind the front plane, then ...
35 views

### Predict whether projectile is coming at a teammate

Related to this question How to project a Vector3 onto the xz plane? ...
1 vote
600 views

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

I have this code that tries to check whether a lobbed grenade will head toward a teammate: ...
301 views

### How to set a position relative to my player's direction?

Currently I am setting my Player's position with: transform.position = new Vector3(target.x, target.y, target.z); However, the X and Z of this do not work the same ...
67 views

### Align two meshes given 2 faces

I have two meshes (A and B) and I know that a triangle in A has the same size and same angles as a triangle in B. For simplicity, suppose A is an octahedron and B is a tetrahedron. And suppose the ...
67 views

### How to snap placed blocks to closest snap point?

I am making a snapping building system in Ursina Engine (Python3). How should it work? Create an the world (ground, a and b entities) Add a FirstPersonController Detect if left mouse button was ...
70 views

### Find where two (mirrored) 2d vectors intersect a rectangle bounds

I've created a 2d gradient shader which uses an absolute start/end point to determine how an arbitrary amount of colors are positioned along the gradient line. I now am creating an api to create a ...
46 views

### How to encode homogeneous transformations on the root node of a gltf

Let us say we have a gltf asset. Let us say we want to apply an arbitrary linear transformation to the root node. We will say that the root node has a rotation, translation and scaling components. For ...
683 views

### Aim projectile to intercept moving target from a moving ship

So I have created spaceship shooter game where ships have turrets on them . Now I want those turrets to shoot a moving target meaning I want the projectile to intercept and hit the target that is ...
849 views

### Using atan2 vs dot product to get an angle in 2D games

I have some confusion that I need to be cleared up about the atan2 function. I am making a game in Godot where a 2D ship rotates to face some object in space by ...
155 views

### 2D turret aiming at the player, but only within a certain arc and with a defined angular velocity

I have a turret game object and a player game object, say it's a spaceship. Right now, every frame the turret updates its rotation, so it's always pointing at the player, giving it potentially ...
247 views

### Cue ball direction after collision

I am trying to figure out the velocity of ball A after collision, which is V2.A as seen in the figure. I know that the velocity of ball A is perpendicular to the line connecting centre of ball A and B ...
1 vote
924 views

### How to divide a Vector3 to recover a scale factor?

I have object I'm scaling by setting its localScale to (1, 1, 1) multiplied by a float size. ...
1 vote
108 views

### Given a quad in 3D space with two diagonally opposite points and normal, how would I find the other two points?

Image attached below for clarification: So here we have a plane with a random rotation in 3D space, and we have the values for P1, P2, and the plane normal. How do I find the points X1 and X2? This ...
95 views

### Move object on World's XYZ axes

I'm trying to move my Character on the world's XYZ Axes, but how do I get them? I'm trying to do this because my Player is sort of a Sphere and is rolling around, so its xyz directions are rotating. I ...
54 views

### Compute thrust applied to ship's sails depending on sailSize, sailState and relative angle of wind

I'm trying to calculate the speed of a ship, depending on many factors. the speed of the wind the relative angle between the sails forward and the wind forward. transformed into ...
87 views

### Get component of velocity parallel to a normal

I would like to transform a rigidbody's world velocity into a local velocity based on a normal direction. When the rigidbody is moving towards and within a range of a object, I use a raycast to ...
64 views

### 2D Vector local to global space without trig/sqrt

Per this answer to this question, a cheap way (i.e., without trig/sqrt) to convert from global to local space, given LocalOrigin, LocalI, LocalJ, and GloablPoint is (in rough pseudo code) ...
1 vote
49 views

### How to insert a new control point on 3D cubic Bézier spline, without deforming current shape?

I have a spline generation system using a cubic Bézier algorithm. I created a tool that splits the spline and adds a new point where the user clicked on the spline, but it causes the spline to deform ...
509 views

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

I'm not using Unity or any other library for making game logic. I'm making a basic game logic that needs to do basic vector math on the backend side. I just wrote a direction function that needs to do ...
1 vote
910 views

### Calculate normal and plane orientation using 4 3D points

I have 4 points as Vector3 in 3D space that shape a plane. How can I calculate the plane normal direction these four points create together, and express it as a <...
84 views

### I cannot understand this change of basis problem

I know we need to get the inverse of transformation matrix first to get the coordinate relative to other frames. Explanation is in this video. I am reading directx11 book. And the following ones are ...
109 views

### How does this 4 by 4 matrix (about 4 points are coplanar) come up with this equation?

I have just begun learning some 3d mathematics and OpenGL (trying to implement skeleton animation). I am stuck here when reading a book(Advanced Methods in Computer Graphics). I understand the first ...
359 views

### How to find vector representing altitude of a triangle?

I'm trying to find this green vector and I've got three points A, B, C. How can I find that vector in Unity code-wise?
230 views

### How to navigate a moving 2d spaceship under newtonian mechanics to a point in space?

I am creating a real-time game where ships move through space using basic laws of motion. The ships move by rotating (instantly for our purposes) to an angle and then firing their engine to accelerate....
180 views

### X axis intersection with inverted Y axis coordinates

I'm making a visual clue for the player to know where (and more or less when) an asteroid is going to enter the screen. For this I'm using a triangle pointing at the incoming object and color ...
1 vote
186 views

### Why does this obstacle avoidance steering behaviour get stuck going left and right?

I am studying obstacle avoidance steering behaviour. So far I got arrive seek flee, and wander behaviours working, so the math should be right. Why doesn't this avoid steer behaviour work, though? It ...
98 views

### Draw a plane in fragment shader using determinant?

I'd like to use the determinant of a matrix to draw a plane in the fragment shader. But I don't understand how to come up with the matrix. Let's say that I have 3 points that lie on the plane: A, B, ...
548 views

### Calculate the angle of rotation between two vectors relative to the first vector

I'm trying to get the angle between two 2D vectors relative to the first vector input. Every method I've tried has given me a value between 0-180 degrees but doesn't tell me whether it was a clockwise ...
1 vote
478 views

### How to slide along a wall at full speed?

I was reading this answer, and while it works for that use-case, mine is slightly different (simpler?), but I can't figure out how to do it. What I'm looking for is a way for the player to retain ...
74 views

### writing a custom Quaternion.FromTo

I'm using the new Unity.Mathematics library. I'm trying to to replace Quaternion.FromTo(Vector3 from, Vector3 to) which returns a quaternion with what it would take ...
1 vote
296 views

### What is the correct way to combine transforms together?

I have a type called transform in my game engine: ...
99 views

### Torque orientation when changing the coordinate system

I have some Unity application, where the user can input a torque that will be apply to a given rigidbody. Nonetheless, the sophistication comes from the fact that the input from the user is in a given ...
1 vote
296 views

### How to solve for the angle of a axis/angle rotation that gets me closest to a specific orientation

I’m using a 3D affine transform (a 4x4 matrix of floats) to represent a combination of translations and rotations in 3D space doing a sort of 3D turtle graphics kind of thing. From this state I know ...