Reputation: 4942
I have a 3D vector and a 3D face normal. How do I go along to move this vector along the given face normal using Python (with or without numpy)?
Ideally, I'd build a matrix using the face normal with the x
and y
and multiply it by the original vector or something like that, but I can't get my head around on how to build it. It's been a while since Linear Algebra.
EDIT:
Thanks for pointing out that my question was too broad.
My goal is to get a new point, that is x
and y
units away from the original point, along the face defined by its normal.
Example: If the point is (0,0,0)
and the normal is (0, 0, 1)
, the result would be (x, y, 0)
.
Example 2: If the point is (1, 0, 0)
and the normal is (0, 1, 0)
, the result would be (1+x, 0, y)
.
I'd need to extrapolate that to work with any point
, normal
, x
and y
.
Upvotes: 1
Views: 1424
Reputation: 157
def give_me_a_new_vertex_position_along_normal(old_vertex_position, normal):
new_vertex_position = old_vertex_position + normal
return new_vertex_position
There is a difference between affine spaces (your normals) and euclidean/linear spaces (your vertices).
Vectors in linear space have coordinates associated with them, while vectors in affine space do not.
Adding an affine-spaced vector to a linear-spaced vector is called projection and that is what you are looking to do.
Upvotes: 0
Reputation: 375475
The projection of a vector
to a plane defined by its normal
is:
def projection(vector, normal):
return vector - vector.dot(normal) * normal
Presumably this means you want something like:
x + projection(y, normal)
Upvotes: 2