Questions tagged [vectormath]

Vectors are a geometric elements having both direction and magnitude. Vector math is the set of operations on a vector combining it with another vector or with a scalar value.

Vector math can involve the combination of a vector and either a scalar or another vector.

A simple addition operator, for example:

(1, 2, 3) + (10, 20, 30) = (11, 22, 33)

Or a multiplication with a scalar:

(1, 2, 3) * 13 = (13, 26, 39)

The standard list of operations can vary by the space in which the vector is defined, but in the general case the basic operations are:

  • Addition
  • Subtraction
  • Multiplication by a Scalar
  • Magnitude
  • Dot Product
  • Cross Product
75 questions
10
votes
1 answer

STL algorithm for Vector Add

Say I have two vectors: vector foo{1, 2, 3}; vector bar{10, 20, 30}; Now I want to do a vector add on them such that the result would be: 11 22 33 Is there an STL algorithm that will handle this, or do I need to use a for…
Jonathan Mee
  • 35,107
  • 16
  • 95
  • 241
6
votes
1 answer

Easiest way to multiply vector values together?

I've got a silly question. I took a vector math class about 10 years ago and could've sworn I remembered an operation that allowed me to multiply the values of a vector together like so: Vector3 v1 = new Vector3(1, 0, 2) Vector3 v2 = new Vector3(5,…
SemperCallide
  • 1,629
  • 2
  • 21
  • 37
4
votes
4 answers

How to find closest point on line?

I have a point (A) and a vector (V) (suppose it's infinite length), and I want to find the closest point (B) on the line to my original point (A). What's the simplest expression using Unity Vector2's or Vector3's to get this?
Semimono
  • 504
  • 5
  • 11
4
votes
4 answers

How to calculate vec4 cross product with glm?

Why this throws an compilation error: no matching function for call to ‘cross(glm::vec4&, glm::vec4&)’ glm::vec4 a; glm::vec4 b; glm::vec4 c = glm::cross(a, b); but it works fine for vec3?
Kimi
  • 11,963
  • 7
  • 49
  • 79
3
votes
3 answers

Math programming help for a gimble-based painting machine

I'm an artist involved with building various sorts of computer controlled machines. I've started prototyping a gimble-based XY painting machine and have realized that the maths needed are out of my reach. I'm a decent enough programmer but not…
user104382
3
votes
1 answer

Rotating a 3D direction vector upwards with `glm::rotate` and quaternions

Given the following coordinate system1, where positive z goes towards the ceiling: I have a glm::vec3 called dir representing a (normalized) direction between two points A and B in 3D space2: The two points A and B happen to be on the same plane,…
Vittorio Romeo
  • 82,972
  • 25
  • 221
  • 369
3
votes
1 answer

color points based on what side of line they are on

I am trying to make a little algorithm that colors a point a certain color based on what side of a line the point is on. This is what i have at the moment. The code doesnt give any errors, but the colors also arent correct for the dots.. Could…
FutureCake
  • 2,108
  • 16
  • 43
3
votes
0 answers

Faster tetrahedron-tetrahedron intersection

For one project of mine I require reliable detection of intersection between two tetrahedrons in 3D space. I do not need the points/lines/faces just to know if intersection is present or not. Touching is considered intersection too but common…
Spektre
  • 41,942
  • 8
  • 91
  • 312
3
votes
2 answers

Calculate target angle given current angle and target position?

I've been struggling with what I think should be a very simple problem: . I know the current heading angle (say 15 deg), and given a target gameObject's transform, I want to calculate the angle that I should rotate towards to face the target. In the…
Murkantilism
  • 855
  • 1
  • 12
  • 31
3
votes
4 answers

SIMD Sony Vector Math Library in OS X with C++

I'm currently writing a very simple game engine for an assignment and to make the code a lot nicer I've decided to use a vector math library. One of my lecturers showed me the Sony Vector Math library which is used in the Bullet Physics engine and…
Jon Hocking
  • 219
  • 3
  • 11
3
votes
2 answers

Simulating planet orbit with vectors

To better understand how vectors work, I'm trying to create a very simple simulation of the earth orbiting the sun. Currently, all I want is for the earth to go around the sun in a circle. No laws of physics are taken into account. I thought that…
RaptorDotCpp
  • 1,375
  • 12
  • 25
3
votes
1 answer

Finding Shortest Distance Between Two Parallel Lines, With Arbitrary Point

I need to write a reliable method to retrieve the answer to the following scenario... Given a line segment AB and an arbitrary point C, how would I find the closest point to A on a line parallel to AB that passes through point C? (Reliable mentioned…
Swivel
  • 2,226
  • 23
  • 34
3
votes
2 answers

Understanding velocity and implementing Boids algorithm?

So I'm working on porting Boids to Brightscript, based on the pseudocode here. I'm trying to understand the data structures involved, for example is Velocity a single value, or is it a 3D value? (i.e. velocity={x,y,z}) It seems as if the pseudocode…
alphablender
  • 2,011
  • 4
  • 25
  • 40
3
votes
4 answers

One class for math vectors of arbitrary dimension

I want to write a class for mathematical Vectors (holding real numbers). I figured that Vector operations are pretty much the same regardeless of the dimension of the vector, so instead of writing classes like Vector2D, Vector3D, Vector4D, ... I…
IchBinKeinBaum
  • 1,434
  • 2
  • 17
  • 24
2
votes
1 answer

How to rotate a square around x-axis in a 3D space

So i have been trying to learn how 3D rendering works. I tried write a script with the goal to rotate a flat (2D) square in 3D space. I started by defining a square in a normalised space (-1, 1). Note that only x and y is normalised. class Vec3: …
user12291970
1
2 3 4 5