Creating a line dynamically in 3D space

mannitou

New member
Joined
Nov 6, 2020
Messages
1
Hello guys,

I try to code a program that draws a line in a 3D space by setting its path initially. To accomplish that I have to calculate the points in my space. I was able to deal with 2 dimensions already and I can create a line going straight forward, left and right. Unfortunately I can’t deal with heights. My formula has to be tweaken especially with more complex directions.

I want to state the path like this:
  • direction: left
    angle: 90 (degrees)
    points: 10
  • direction: forward
    length: 5
  • direction: up
    angle: 45 (degrees)
    points: 10
  • direction: forward
    length: 5

To make this clear, forward means that the line follows exactly the direction it has to this moment. So it can be in any direction of the 3D space. Direction changes are only possible with the command “direction: …”. Points means how many vectors should be created to visualize a smooth curve.

The line starts always at (0, 0, 0). In the code environment I am using this vector follows (x, y, z) where y is the height => (width, height, length)!

Every function passes the horizontal theta (hTheta) to the next function. Also the last vector will be passed, therewith the next function is able to continue at the same point.

My functions look like this right now:
  • To achieve a smooth curve the “angle” in radians is divided by “points” and the function will be repeated as often as “points”, so in my example path above it runs 10x. Every run the theta will be increased/decreased by the ratio.
Left:
x: startVector-X + (cos(hTheta) - sin(hTheta))
y: 0,
z: startVector-Z + (cos(hTheta) - sin(hTheta))
==> INCREASE hTheta by the ratio (angle in radians / points)
==> Start over “points” times

Right:
x: startVector-X - (cos(hTheta) - sin(hTheta))
y: 0,
z: startVector-Z - (cos(hTheta) - sin(hTheta))
==> DECREASE hTheta by the ratio (angle in radians / points)
==> Start over “points” times

Forward:
x: startVector-X + length * sin(hTheta)
y: 0,
z: startVector-Z + length * cos(hTheta) * -1

This are the working formulas for drawing the line on a plane (left, right, forward).

How am I be able to integrate the height (y)? Of course my current formulas have to be tweaken as well to achieve that.

Thank you very much!!

Best
 
Top