Can someone solve this vector / constraint problem for me?

I’m trying to calculate how an object would be constrained along a single axis - relating to where the user is pointing at in x y space around the object. I made a crude diagram to help explain - the 2 red contact points are random positions the user might pick. the object begins at the origin, and is only allowed to move in the direction of the normal, keeping it’s position matched to the contact points in one axis.

this is easy enough to do when the normal is facing 1,0 (simple x,y) but i’m getting confused when how to do it when say the normal is at 30 degrees for example.

thanks, going through this now…

Pay especially close attention to anything about the dot product.

i’m still struggling to be honest.

i’ve worked it out in theory,

if i rotate the contact point back as quaternion by the angle between the normal and world space, and then get the difference in the x position of the contact point and world space - and multiply this with the origin normal to get the ‘constrained’ position… or something like that…

i see what you mean about the dot product - i need to get the theta value though i think still,

sorry still confused generally…

can’t do the math on this i’m afraid,

trying alternate method by creating a quad plane aligned to the normal using lookat method - and then raycasting back from the contact points in the reverse normal direction back to plane - getting that distance and offsetting the objects position with it.

the keyword is “Lotfußpunktverfahren” in german… but i cant find the english analogy to be honest.

But well: the images should be of help

The dot product is exactly what you describe in your first post. It gives you the projection length of one vector along another vector.

Vector v = contact point - origin

dist = normal dot v

constrained point = normal * dist

I’m trying to provide clues instead of the exact answer because this is some of the most basic spatial math. Try to figure it out from the above and try to understand why it works.

The dot product is one of the most handy and fundamental tools in the 3D programmer’s toolbox and it’s good to understand it. (For example, even a 3x3 rotation matrix is just three axis vectors and a 3D transformation just three dot products against those vectors.)

…and it is so extremely rare that you ever need to know actual angles for anything even remotely like this. And those paths are fraught with peril anyway.

thanks all - looking into dot stuff now…

yep figured it out thanks :slight_smile:

and importantly i learned about it,

this is a processing sketch i made to help me visualize and learn this,

void setup() {




void draw() {


PVector mouse = new PVector(mouseX,mouseY);

PVector center = new PVector(width/2,height/2);

PVector nrm= new PVector(1,1);



float dst =;