# Accurate Raycastingin Three.js Geometry

Hello, I am using three.js and I want to add a setback to my geometry. I use the plane of this geometry and the setback value to calculate the new x and y coordinates. After that, I want to raycast this point on the plane to get the z coordinate according to the slope of the mesh. However, the z coordinate deviates from the original position. Does anyone have any suggestions for this?

the green line presents the plane, its made from buffer geo of the purple geo
the pink lines are after setbacks, i want the point to be on purple line but we can see both points (above and below )deviates.

I don’t think there is enough information to understand what the issue is.
Raycasting a plane should work and be pretty accurate.

Perhaps you are creating the ray incorrectly? or perhaps you are processing the wrong hit record in the raycast result?

yes, i am pretty confused as to how shall i raycast the ray (the direction) right now what i do is take the actual cords add the setback to it, i get the position of the new point, to get the z for that point i ray cast from this formula
let planeNormal = plane.normal.clone(); // Clone the normal vector of the plane

``````let pointRelativeToPlane = plane.distanceToPoint(updatedPoint1);
let direction;

if (pointRelativeToPlane > 0) {
direction = planeNormal.negate(); // Point is above the plane, cast ray downwards (along negative normal)
} else {
direction = planeNormal; // Point is below the plane, cast ray upwards (along positive normal)
}

const rayCaster = new THREE.Raycaster();
rayCaster.set(updatedPoint1, direction);

const intersectionPoint = new THREE.Vector3();
const isIntersecting = rayCaster.ray.intersectPlane(plane, intersectionPoint);
``````

and get the intersection point.
Without ray casting my upadatedPoint1 is correct, but only that the z is not according to the slope for which i am performing the raycasting