Search code examples
vector3dnormals

Calculating tangent pointing in a specific 2D Direction


I need to calculate the tangent pointing in the same (x,y)-direction as a 2D vector from a given normal. Here is a visualization:

Directed Tangent From Normal Viz

The red plane with the cyan ray is the surface and it's normal, the green 'Arrow' represents the 2D direction and the blue one the tangent of the normal with the (x,y)-direction of the green arrow. So when viewing from top (in object space, not surface space) to project onto 2D the green and blue are the same direction.

So if this was too abstract, here is the context: I'm making a GPU erosion simulation and in order to calculate dissolvation, I need the 3D water velocity vector to test for collision with the terrain normal. But the simulation is in 2D, so I have only a 2D velocity vector. The paper I'm referencing only notes the program should calculate this 3D vector from the terrain surface tangent and the 2D velocity vector.

Given this information, the normal and the 2D Vector, what is the math to calculate said matching tangent?


Solution

  • To calculate the surface tangent, first project the vector onto the normal.

    enter image description here

    enter image description here

    Then just add to get the un-normalized tangent.

    enter image description here

    To rebuild the reflected velocity, do

    enter image description here

    Where e is the coefficient of restitution (assuming particles).