Want to find intersecting angle (3D position) of two 3D points or Y distance

Viewed 210

I have point A (x,y,z) and point B (x, y, z) in ARWorld. I want to keep point A horizontally parallel to B or let's say both should be on the surface. See the image to get a better idea.

I am planning to get Y direction height or vertical height from A to B and then I will push down A by height. But how to find the height.

I want to keep A's x and z the same as it is.

Not sure how to articulate the issue, But aY - By does not work. NOTE: A and B both are different Anchor in ARKit. Box/Mesh is on the anchor. Seems like I need global absolute world positions. Is there any other way to get a rounded position in the image?

enter image description here

enter image description here

2 Answers

You say you want to get the positionA mapped down to the same "height" (Y axis) level as positionB

positionA.y = positionB.y;

it is simple as that.

Be aware that I am talking about absolute world space positions ... the values will of course be different in the Inspector since there you see only the local positions relative to the parent.

So when we are talking about GameObjects what you want to do is

var positionA = objectA.transform.position;
var positionB = objectB.transform.position;

positionA.y = positionB.y;

objectA.transform.position = positionA;

I would make an horizontal plane in B find the closest point in that plane to A and move A to that point.

Create horizontal plane: Taking the constructor into account Plane(Vector3 inNormal, Vector3 inPoint);.

Plane myPlane = new Plane(Vector3.up, <Bpositon>)

Then with Plane.ClosestPointOnPlane you can find the closest point to A in your horizontal plane.

Vector3 closestPoint = myPlane.ClosestPointOnPlane(<APosition>);

Then you can move A to that point.

APosition = closesPoint;

Conviniently the closest point in the plane to one point is the one perpendicular to the plane, so the one "horizontally parallel" I believe you are after.

Related