I’m trying to build a simplified CAD where you can tie 2 wood logs as the scouts do (with square lash) and I’m stuck.
How can I programatically “tie” 2 cylinders in the scene?
I’m thinking that I need to detect the exact point of collision between those 2 cylinders, then inserting a knot object at that location in the scene. But more exactly, how can I find this precise collision information?
Hi!
Think of your logs as of 3D-lines with some radii. When the distance between these logs is equal or less than the sum of their radii, then their collided.
Three.js has Line3 class, but AFAIK, there is no methods for finding the distance between lines.
You can start from here: geometry - Find shortest distance between lines in 3D - Mathematics Stack Exchange
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)
Maybe need temporary set default matrix4 for geometry, computeBoundingBox, compute average point of min x,y,z for first point, compute average point of max x,y,z. and then apply matrix4 of wood.
Or if default geometry pivot is placed at center of coordinates, then first point will be 0,0,0 second point will 0,here height of geometry 0, and then apply to points the matrix4 of mesh.
@Pop_John are the logs meshes made from cylinder geometry? I’m assuming you know the size, position, rotation. You could get the initial lines to intersect by creating lines with the same length as the logs, then copying the center and rotations.