The past few evenings I’ve been trying to solve quite a complexing mathematical / pathfinding conundrum… I am trying to find a path and create a TubeGeometry
between 2 points with 2 independent directions, lets say
{ positionA: Vector3(x,y,z)), directionA: (Vector3(x,y,z)) }
{ positionB: Vector3(x,y,z)), directionB: (Vector3(x,y,z)) }
the path should ideally never exceed a minimal / maximal bend angle ( 1.5 * the diameter of the resulting TubeGeometry
radius ) and therein follow the least resistant / shortest path from pointA to pointB outside of this turn angle threshold…
so far I have been trying to apply some simple equations to the curve to go from pointA to pointB, to then maybe apply some further mathematical concepts later on, yet this has lead to outcomes with little to no useful results eg… adding the lerped directional vector between directionA and directionB to the lerped positional vector between positionA and positionB with a Math.sin coeff to generate a half sine between points, which generate a curve that does not reflect what i imagine to be a smooth curve with a minimal / maximal turning angle ( derived from the resulting TubeGeometry
’s radius ) between points.
in the latest approach, i have been experimenting with calculating the cross product of the directional vector between positionA and positionB ( let’s call this “globalDirection”) and the lerped directional vector between directionA and directionB ( let’s call this “tangentialDirection” ), then using an Object3D() to traverse along the length between positions, using…
object3D.rotateOnAxis(globalDirection.cross(tangentialDirection), directionA.angleTo(directionB) / distance)
object3D.translateOnAxis( new Vector3( 0, 0, 1 ), ( distance / 2 ) / ( (Math.PI * 2) - aTo ) )
however this yeilds some varied and unexpected results in practice…
I’ve prepared a minimal demo that reflects the state of the function from the images above…
the function in question where the curve is currently being calculated is generateSmoothCurve()
on line 271 which pushes the iterative positions to the CatmullRomCurve3.points = []
…
I’m wondering, if anyone has any ideas on how this could be achieved, or if you’ve seen something similar implemented before, it’d be great to hear your thoughts on an approach to this that can be performative in three!
To Note:
the randomly distributed spherical positions / directions are just for testing random / extreme edge cases where the function should hold true.
I think I’ve seen some sort of tutorial for this type of thing using blender geometry nodes where procedural tubes can have physics applied and dragged from outlet to inlet like a soft body almost…