# Determining the Correct Direction to Move a Point for Accurate Pitch Calculation

I’m working on a three.js project where I need to calculate the pitch of a surface, but I’m running into a problem with aligning two points in 3D space. Here’s the situation:

• I have two points, represented as a green circle and a red circle.red reprenst point with higest y while green lowest y
• The goal is to move the green circle directly under the red circle while maintaining the distance between them, forming a triangle that can be used to calculate the pitch accurately.
• However, the highest and lowest points in the `y` direction are appearing at opposite corners, causing the pitch calculation to be incorrect.
• When the green and red circles are aligned properly, the pitch calculation is correct. But I’m struggling to determine the correct direction of movement for the green circle to achieve this alignment.

The challenge is that the direction of movement can vary between projects. It could be an `x` or `z` movement, but not `y` since the slope is crucial. Additionally, depending on the scenario, `x` and `z` may interchange places, which makes it hard to standardize the approach.

it calculates incoorect pitch for this case

but for this one it gaves accurate pitch, i diberatle draw the corner up so y is lowest for the point under red.

i want no matr how the shape is irrrgular or further the points are they align so that the pitch is accurate
How can I determine the correct direction to move the green circle to achieve the proper alignment under the red circle for accurate pitch calculation, considering the potential for different axis movements in different projects?

It looks like you’re evaluating 2D photographs. Where to you derive x, y and z.coordinate values for the red and green circles from?

Looks like a 3d drone scan. I think they’re writing a solar panel installation assistant/tool.

yes, basically its a 3d modal, i am getting 3d points for house roof’s by mouse click while drawing now to get the accurate picth i need the point right under red one that is the heighest and lowest y valued cordinates beneath each other for the formula to work.

take your 2 points… call them a,b

``````let lineNormal = b.clone().sub(a).normalize();
let up = new Vector3(0,1,0);
let faceNormal = lineNormal.clone().cross( up ).normalize()
let faceHNormal = faceNormal.clone().cross(up).normalize();
let faceVNormal = faceHNormal.clone().cross(faceNormal).normalize();
let obj = new Object3D();
obj.matrix.makeBasis(faceHNormal,faceVNormal,faceNormal);
obj.matrix.decompose(obj.position,obj.quaternion,obj.scale);
let pa = obj.worldToLocal(a.clone())
let pb = obj.worldToLocal(b.clone())
let slope = (pb.z-pa.z)/(pb.y-pa.y);
``````