I'm working on creating a curved 3D arrow using three.js. My approach involves using a Tube along a curved path and a Cone shaped cylinder. Here's how they currently look:
https://i.sstatic.net/jmVB6.png
https://i.sstatic.net/P756z.png
My goal is to position the Arrow Head (Cone) at the end of the Tube, as shown in this Photoshopped image:
https://i.sstatic.net/DWfWB.png
Since I'm not very strong in math and new to three.js, I would really appreciate some guidance on how to connect the two elements. Here's the code I currently have:
import T from 'three';
var findY = function(r, x)
{
return Math.sqrt((r * r) - (x * x));
}
var radius = 25;
var x = 0;
var z = 0;
var numberOfPoints = 10;
var interval = (radius/numberOfPoints);
var points = [];
for (var i = numberOfPoints; i >= 0; i--)
{
var y = findY(radius, x);
points.push(new T.Vector3(x, y, z))
x = x + interval;
}
x = x - interval;
for (var i = numberOfPoints - 1 ; i >= 0; i--)
{
y = findY(radius, x) * -1;
points.push(new T.Vector3(x, y, z));
x = x - interval;
}
var path = new T.CatmullRomCurve3(points);
var tubeGeometry = new T.TubeGeometry(
path,
10,
radius / 10,
8,
false
);
var coneGeometry = new T.CylinderGeometry(
radiusTop = 0.1,
radiusBottom = radius/5,
height = 10,
radialSegments = 10,
heightSegments = 10,
openEnded = 1
);
var material = new T.MeshBasicMaterial( { color: 0x00ff00 } );
var tube = new T.Mesh( tubeGeometry, material );
var cone = new T.Mesh( coneGeometry, material );
// Translate and Rotate cone?
I would really appreciate some guidance on the mathematical and programmatic steps needed to:
- Find the normal at the end of the tube
- Move the Cone to the correct position
Any help would be greatly appreciated!