1
votes

I'm trying to create a function for extruding a face along a normal by dragging the mouse. For the purpose of the question, I've simplified things to 2D vectors, so that the view is looking down onto a cube, with the normal being that of the face to extrude.

I can limit the movement of the mouse by the direction of the face normal easily, my question is how to work out the correct distance along the normal direction that the mouse has travelled.

I have two vectors (A & B1). A is the starting point and B1 is the current mouse position (see image Vector Normal Projection). I need to project B1 so that it points along the face normal direction from point A. So B1 becomes B2. This will also be the case for a mouse position of Bx (Bx needs to be projected from A along the normal so that it becomes B2). This will mean that whether the mouse is at B1, B2 or Bx they will all give the same distance along the normal direction (2 in this case).

I may be approaching the problem incorrectly, so please let me know if there is a better way to tackle this.

Thanks. 

1

1 Answers

0
votes

Length of projection of w=AB1 vector onto line AB2 having normalized (unit length) direction vector e is very simple using dot product:

L = (w.dot.e) 

perhaps you already have e if you know angle - in 2D it's components are:

e = (cos(fi), sin(fi))