Ok let me explain again. I know how to do the transformations using the typical d3d_transform AND matrix_build as well... but I cant use those for what Im doing because I need to get the xyz position of the final transformation of these points when applied. Basically, what I am looking for is exactly a raw calculation on doing xyz axis rotation so not only I can apply the transformation but I can also get the xyz value base on the transformation with the relative position. Yal showed me online on matrices but I still cant get my head on properly doing the math for this.

The closest I could get was this but its still doesnt work. Im not a total genius on calculus tbh,

Code:

```
dz = 0;
var rx1 = 1;
var rx2 = cos(dx)-sin(dx);
var rx3 = sin(dx)+cos(dx);
var ry1 = cos(dy)+sin(dy);
var ry2 = 1;
var ry3 = -sin(dy)+cos(dy);
var rz1 = cos(dz)-sin(dz);
var rz2 = sin(dz)+cos(dz);
var rz3 = 1;
for(i = 0; i<360; i+=360/8)
{
xx = lengthdir_x(16,i);
yy = lengthdir_y(16,i);
zz = 20;
// ll = point_distance(0,0,xx,yy);
var vx = xx * (rx1*rx2*rx3);
var vy = yy * (ry1*ry2*ry3);
var vz = zz * (rz1*rz2*rz3);
d3d_draw_ellipsoid(vx-1,vy-1,vz+1,vx+1,vy+1,vz-1,-1,1,1,20)
}
```

Still no explenation of your own code.

Matrices will probably be the easiest method, although quaternions might be even slightly better.

The idea behind matrices is the following.

Suppose you've got the following 2 vectors in 3D space: (1, 0, 0) and (0, 1, 0).

Before rotation, the centers of every sphere in your ring can be described as a linear combination of these 2 vectors: (X, Y, 0) = X * (1, 0, 0) + Y * (0, 1, 0)

You now want to perform an euclidean transformation (a rotation) on your space.

Every euclidean trasformation can be proven to be the combination of a linear transformation on a finite vector space and a translation.

Every linear transformation on a finite vector space can be shown to be equivalent to a matrix multiplication with the column matrix containing the coordinates of the vector.

The center of your ring has coordinates (0, 0, 0) and after the transformations, it will still be (0, 0, 0).

From this, you can conclude that the translation part can be skipped in your case and all you're left with is a matrix multiplication.

Since the z-coordinate is initially always 0, it suffices to work with a 3 x 2 matrix, one that maps 2 coordinates onto 3 coordinates.

You're now looking for a transformation that looks like:

Code:

```
[a b] [x]
[c d] * [y]
[e f]
```

When you let x = 1 and y = 0, the result of this transformation is (a, c, e).

This is what the vector (1, 0), the one going to the right in 2D should get mapped to in 3D.

Analogously, when you let x = 0 and y = 1, the result is (b, d, f), which is what the vector (0, 1) gets mapped to.

We now consider a rotation around the x-axis (like you've already done) over an angle of theta.

The vector (1, 0) then gets mapped to (1, 0, 0), so a = 1, c = 0 and e = 0.

The vector (0, 1) gets mapped to (0, cos(theta), sin(theta)), so b = 0, d = cos(theta) and f = sin(theta).

For our euclidean transformation, we need to map 3 coordinates to 3 coordinates however.

This means we'll have to determin a 3 x 3 matrix transformation of the form:

Code:

```
[a b u] [x]
[c d v] [y]
[e f w] [z]
```

We only need to determin u, v and w.

Since we are working with euclidean transformations, there is a property stating that the transpose of the matrix, multiplied with the matrix itself must be the identity matrix.

We thus get the following equations:

Code:

```
a*a + c*c + e*e = 1
a*b + c*d + e*f = 0
a*u + c*v + e*w = 0
b*b + d*d + f*f = 1
b*u + d*v + f*w = 0
u*u + v*v + w*w = 1
```

Getting back to the transformation around the x-axis over an angle theta, these equations become:

Code:

```
1*1 + 0*0 + 0*0 = 1 (OK)
1*0 + 0*cos(theta) + 0*sin(theta) = 0 (OK)
1*u + 0*v + 0*w = 0 (So u = 0)
0*0 + cos(theta)*cos(theta) + sin(theta)*sin(theta) = 1 (OK)
0*u + cos(theta)*v + sin(theta)*w = 0 (So v = -tan(theta)*w)
u*u + v*v + w*w = 1 (So w² = 1 / (1 + (tan(theta))²) = (cos(theta))²)
```

This has as solution u = 0, v = -sin(theta) and w = cos(theta).

(there is also a property of rotation matrices stating that their determinant must be 1, which makes the above signs (- for sin and + for cos) the only correct ones).

We've now got the complete rotation transformation around the x-axis.

Analogously for the rotation around the y-axis, you'd get:

a = cos(theta), c = 0, e = sin(theta),

b = 0, d = 1, f = 0,

u = -sin(theta), v = 0, w = cos(theta)

Here's an example of the implementation of all of the above in GML:

http://www.mediafire.com/file/e23btb0b25adkd1/GMC_ring_rotation.gmz
PS:

I got called away for a couple of hours, just before sending this message.

I've seen you've gotten a solution in the meanwhile, but I still wanted to send this.