# Array generated path

Hello,

recently I found the tubeBuilder and I love it. Since I want to make it more easy for me to create tubes I try to use a function that calculates the paths for me.

https://playground.babylonjs.com/#MQJMAR#15

I was able to use angles but I am stuck with following the path with straight lines after a curve.

Do you have an idea how I can solve the issue?

Best

Do you need another direction?

i.e. you have left and straight, but straight can be vertical or horizontal?

With straight I mean the path should just go forward in the given direction. So I would be able to use:

• left: 90Â°
• straight: 5
• right: 180Â°
• straight: 10
âŚ

If the path would go up 90Â° (align with y-axis) the path should go vertical if using âstraightâ. Direction change is only possible with âleftâ ârightâ âŚ

I understand what youâre trying to achieve, but with the code you have straight is âonlyâ vertical at the moment, not horizontal. The vector you describe only has two components, so it will only ever be in a single plain.

Yes, youâre right. I want to take care of vertical paths after solving the horizontal problems. It is easier to think in a 2d matrix

Adding and using this works - so think thereâs just a bit of odd maths involved in the âzâ part which is your yâŚ

``````const createStraightHoriz = (lengthPlain, options) => {
//const length = options.degrees < 90 ? -lengthPlain : options.degrees <= 180 ? -lengthPlain : options.degrees <= 225 ? lengthPlain : options.degrees <= 270 ? -lengthPlain : lengthPlain
//const add = options.degrees < 90 ? 0 : options.degrees <= 180 ? -1 : options.degrees <= 225 ? 2 : options.degrees <= 270 ? 3 : 2
//const theta = options && options.degrees ? BABYLON.Tools.ToRadians(options.degrees) * (options.degrees/90+add) : 0

const length = -lengthPlain
const theta = options && options.theta ? options.theta : 0

const thetaDelta = options && options.theta ? options.theta : 1
const startVector = options && options.startVector ? options.startVector : new BABYLON.Vector3.Zero()

const newVector = new BABYLON.Vector3(
startVector.x - length * (Math.cos(theta) - Math.sin(thetaDelta)),
0,
startVector.z
)

return {
path: [newVector],
lastVector: newVector,
theta: options.theta
}
}``````

Thank you! Unfortunately this doesnât solve my problem. With this code the tube align with the x-axis. I try to achieve that the tube can be create completely dynamically: e.g. a form like this https://playground.babylonjs.com/#MQJMAR#18

EDIT:

Finally I got it Itâs beautiful: https://playground.babylonjs.com/#MQJMAR#19

1 Like

Cool. I was going to say itâs all in the maths and vectors at that, but I didnât have time to go over it fully.