Hi @Pop_John ,
As @prisoner849 suggested, you could use this set of utilities for lines to solve this
Example
const line1 = new Line3D(new Vec3(0, 5, 20), new Vec3(10, 5, 20));
const line2 = new Line3D(new Vec3(5, 0, 0), new Vec3(5, 10, 0));
const intersection = line1.intersect(line2);
// The resulting "intersection" is a line with the start at Vec3(5, 5, 20) and the end at Vec3(5, 5, 0)
You can either install the library via npm
npm i @immugio/three-math-extensions
Or just grab the method from the source code
* Move this line by the given vector.
* @param p
*/
public translate(p: Vector3): this {
this.start.add(p);
this.end.add(p);
return this;
}
/**
* Calculates the intersection between this and `other` line. The lines are assumed to be infinite.
* In a lot of cases an actual intersection cannot be calculated due to rounding errors.
* Therefore, the intersection calculated by this method comes in a form of the shorted possible line segment connecting the two lines.
* Sources:
* http://paulbourke.net/geometry/pointlineplane/
* https://stackoverflow.com/questions/2316490/the-algorithm-to-find-the-point-of-intersection-of-two-3d-line-segment/2316934#2316934
* @param other
*/
public intersect(other: Line3D): Line3D {
const p1: Vec3 = this.start.clone();
const p2: Vec3 = this.end.clone();
2 Likes