I would like to apply this formula equation-of-a-plane-passing-through-3-points to my javascript code.
I have three points p1, p2, p3
const a1 = p2[0] - p1[0];
const b1 = p2[1] - p1[1];
const c1 = p2[2] - p1[2];
const a2 = p3[0] - p1[0];
const b2 = p3[1] - p1[1];
const c2 = p3[2] - p1[2];
const a = b1 * c2 - b2 * c1;
const b = a2 * c1 - a1 * c2;
const c = a1 * b2 - b1 * a2;
const d = (-a * p1[0] - b * p1[1] - c * p1[2]);
console.log(p1);
console.log(p2);
console.log(p3);
console.log(" formula π: " + a + "x +" + b + "y + " + c + "z + " + d + "= 0");
Then I get the plane
new THREE.Plane(new THREE.Vector3(a, b, c), d)
It looks nice but…the d value looks bad. As you can see in my attached image the helper of the plane (clipPlanes) used to cut off my object has a gap.
Can you help me to fix it?
Try it with Plane.setFromCoplanarPoints(). Just pass in your three points and let the plane class do the math for you.
2 Likes
Thanks a lot!!! It looks much more simple than my formula!! THANKS!
But I got an error, can you help me to use it correctly?
p1 = [0, h1, l];
p2 = [0, h1, 0 ];
p3 = [w, h2, 0];
let v1 = new THREE.Vector3( p1 );
let v2 = new THREE.Vector3( p2 );
let v3 = new THREE.Vector3( p3 );
let cutPlane = new THREE.Plane();
const pl = cutPlane.setFromCoplanarPoints(v1,v2,v3);
//clipPlanes.push(new THREE.Plane(new THREE.Vector3(a, b, c), d));
console.log(pl)
clipPlanes.push(pl);
Then I apply the plan to cut the object as
materialPlanes = new THREE.MeshLambertMaterial({
color: new THREE.Color().setHSL(0, 0.5, 0.5),
side: THREE.DoubleSide,
clippingPlanes: clipPlanes,
clipIntersection: params.clipIntersection,
});
I got a generic error but in the console the plane looks missing constant
Plane {normal: Vector3, constant: NaN}
constant: NaN
normal: Vector3
Thanks again!!
Set it directly:
let v1 = new THREE.Vector3( 0, h1, l );
let v2 = new THREE.Vector3( 0, h1, 0 );
let v3 = new THREE.Vector3( w, h2, 0 );
1 Like
Right!!! Lol!! I’m done!! Thanks!!!
1 Like