Raycast to find the lenght of the VertexNormal towards another mesh


I have 2 objects one is a sphere and another is a cylinder. But these may be dynamically changes as cube and a plane and so on .

So what I want to acheive get the distance from the vertex towards the outer mesh .

How can I achieve this .
I found a case where they find distance between 2 vertex points : Distance between vertex points

I saw raycaster as a tool to find the intersecting objects and its distance . How can I use it in my case?

Any help would be much appreciated.
Still learning the basics would love to learn from even a small reference.

you can try this function. point - point of your sphere.
intersectObjects - this is your cylinder

function getIntersectionFromPointbyNormal ( point, normal, object, intersectObjects ){


	const localVertex = point.clone();
	const globalVertex = localVertex.clone().applyMatrix4( object.matrix )
	const directionVector = localVertex.clone().add( normal.clone().multiplyScalar(1))
	let directionVectorGl = directionVector.clone().applyMatrix4( object.matrix )
	directionVectorGl = directionVectorGl.sub( globalVertex ).normalize() ;
	raycaster.set( globalVertex, directionVectorGl.clone().normalize() );
	let collisionResults = raycaster.intersectObjects( intersectObjects )

	return collisionResults;


But I think it will work very slow. Too many rays will be

1 Like

I’m not sure I understand what you want.

First, you can find coordinates of vertices of face in world space https://threejs.org/docs/index.html#api/en/core/Object3D.localToWorld

Normal of face you can find so:

	function getNormal( pointA, pointB, pointC ){

	let normal = new THREE.Vector3();

	let planeSideA = new THREE.Vector3();
	let planeSideB = new THREE.Vector3();

	planeSideA.subVectors( pointC.clone(), pointA.clone() );
	planeSideB.subVectors( pointB.clone(), pointA.clone() );

	normal.crossVectors( planeSideA.clone(), planeSideB.clone() ).normalize();

	return normal;

1 Like

Thankyou so much that helped…