Hello. This is my first post here.

For one of my applications, I need help figuring out how to manipulate few equations that I have to graph and pivot a single 3D line (using an electronic sketchbook called Processing). Here the syntax of the line:

line(x1, y1, z1, x2, y2, z2)

The above expression is a Processing function that allows me to graph a line. Where:

x1, y1 and z1 are float coordinates of the first point.

x2, y2 and z2 are float coordinates of the second point.

I am getting the xyz coordinate values from a real gyroscope that I can rotate freely.

For the purpouses of my application, the first point of the line is fixed to the origin.

For simplicity, let's make x2=x, y2=y, z2=z, thus, my line function is now:

line(0, 0, 0, x, y, z)

What I really need is to graph my line in a manner that can pivot in all possible position.

Let's start mentioning the formula of the distance 'd' that I am using:

d = sqrt(x*x + y*y + z*z)

I want to clarify something very important here regarding how I am reading the x, y and z coordinates from the gyroscope.

Each coordinate contains circular values between 0 to 360 degrees. In other words, if I pivot the gyro 360 laying on my table,

the z coordinate will change from 0 to 360. Similarly for the other two axis.

So far I can graph correctly the line but pivoting (or rotating) one axis at a time. I.e.

For the axis z:

x = d * cos(radians(z))

y = d * sin(radians(z))

For the axis y:

z = d * cos(radians(y))

x = d * sin(radians(y))

For the axis x:

y = d * cos(radians(x))

z = d * sin(radians(x))

So far so good. My problems start when I try to put them together:

I have tried the following:

y1 = leng * sin(radians(zin));

x2 = leng * cos(radians(zin));

x1 = leng * sin(radians(yin));

z2 = leng * cos(radians(yin));

z1 = leng * sin(radians(xin));

y2 = leng * cos(radians(xin));

x = (x2+x1);

y = (y1+y2);

z = (z1+z2);

When I graph the above equations, the line looks like pivots correctly but a some positions the lenght starts to change or even becomes zero.

Again, what I just need is to find a way to generate x, y and z that permits the line pivots freely (with the distance fixed of course).

Thank you very much for any comment. Regards!