# Binding 2 wood logs like scouts

Hi,

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

@Immugio Can the set of utilities for lines help in this case? 1 Like

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

2 Likes

Thanks @prisoner849 , @Immugio
This is clear now, how to find the exact point of intersection of 2 cylinders

And how exactly can we get from a cylinder the lineStartPosition and lineEndPosition ?

• lineStartPosition - center of the top face of the cylinder
• lineEndPosition - center of the bottom face of the cylinder

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. 1 Like

@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.

yes, they are made of cylinder geometry

yep, managed to find the intersection line between 2 cylinders exactly as you and @Chaser_Code mentioned