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?