[SOLVED] 90 degree vector

I am having troubles creating a 90 degree vector from a point. Here is my current attempt, showing the vectors parallel to the ground plane:

I am struggling to achieve a 90 degree between vectors a and b. Basically, I need blue and yellow vectors be parallel to each other, both at 90 degree to a. My current code:

left = new pc.Vec3(-0.5, 0.4, 0);
right = new pc.Vec3(0.5, 0.4, 0);
        
var dir1 = right.clone().sub(left);
var dir2 = left.clone().sub(right);
        
var leftSide = new pc.Vec3().cross(dir2, pc.Vec3.UP);
leftSide.y = left.y;
        
var rightSide = new pc.Vec3().cross(dir1, pc.Vec3.DOWN);
rightSide.y = right.y;

How are you rendering the blue and yellow lines?

I removed yellow for now, to isolate the issue:

// just adding to array
array.push(left);
array.push(right);
array.push(leftSide);

// then in update method rendering by
this.app.renderLine(array[0], array[1], this.blue, this.yellow);
this.app.renderLine(array[0], array[2], this.blue);

Got it, thank you @yaustar, your question made me think of the problem from another perspective :slight_smile:

The converging point of blue and yellow vectors was only an intermediate result. To get the final vectors, I had to add it to the left and right vectors:

Final code:

var left = new pc.Vec3(-0.5, 0.4, 0);
var right = new pc.Vec3(0.5, 0.4, 0);
        
var dir1 = right.clone().sub(left);
var dir2 = left.clone().sub(right);
        
var leftSide = new pc.Vec3().cross(dir2, pc.Vec3.UP);
leftSide.add(left);
        
var rightSide = new pc.Vec3().cross(dir1, pc.Vec3.DOWN);
rightSide.add(right);
1 Like