So, I thought to start playing with vertices positions in the hope of finding some good mesh shape.
I came up with this weird idea of using a starting point in the space, then adding to it a distance and an angle to find a second point, then doing the same to the second point to find the third one and so on.
I wanted to know if I would ended up drawing a circle by using this algorithm and, surprise, it kinda worked.
I don't know how but, no matter the angle and the distance, as long as they are constants those segments always close the ring shape as long as they are enough in number.
This is the function I use to find the next point based on the previous one:
fn get_next_3d(p: [f32; 3], distance: f32, theta: f32, gamma: f32) -> [f32; 3] {
[
p[0] + distance * theta.sin() * gamma.cos(),
p[1] + distance * theta.sin() * gamma.sin(),
p[2] + distance * theta.cos(),
]
}
It's using spherical coordinates, where p[0] is the old x, p[1] the y and p[2] the z.
distance is the distance from the previous point, theta is the angle between the z axis and the x axis, and gamma is the angle between the x axis and the y axis.
So, if I call the above function in a loop (let's say ranged between 0 and 50) where the radius is constant and z is always 0., then I get a closed ring.
If, instead, I slowly increase the distance from 0 to 25 and then decrease it again from 25 to 50. And if I also constantly increase z from 0 to 1, then I get two cones (as in the second attached gif).
This is how the distance is increased and decreased at each loop (num):
if num < iterations_f32 / 2.0 {
d = distance * (num / iterations_f32);
} else {
d = distance * ((iterations_f32 - num) / iterations_f32);
}
Is it possible:
To get a flat ring instead of circles?
To get a sphere instead of cones?
To apply triangulation to create a mesh out of these vertices?
How?