We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, How can i do to move each point by sphere in movement for example? Thank you so much.
void setup() {
size(800, 800, P3D);
}
void draw() {
background(255);
for (int i = 0; i < width; i+= 10) {
for (int j = 0; j < height; j+=2) {
point(i, j);
}
}
}
Answers
I'm not sure what that means. Can you explain what you want to happen?
I would like deform this grid of point by some object like a sphere.
You are thinking 3D? You will need to work with the equation of a sphere so to lay points on its surface. Any point that is not in your sphere's surface intersecting the plane, then must be drawn on the plane surface.Here is an idea using points.
Kf
oh god, it's spreading...
iterate through the dots, like you are doing.
if the x,y distance from the centre of the sphere is < radius of the sphere then the z value can be found from the implicit definition of a sphere
x^2 + y^2 + z^2 = r^2
so
z = sqrt(r^2 - x^2 - y^2)
Here are two examples of different approaches:
...and some discussion here:
The approach given by @koogs (and @kfrajer) is interesting because this will solve for two points each time -- a positive point (positive z half-sphere), and a negative point (negative z half-sphere).
Thank you to all guys! ;)
Looking back I realized that I wrote a sketch about this and never posted it, so I'm sharing it here.
Keep in mind that in Processing you can get shapes like spheres automatically as meshes (if you don't need points specifically).
That said, here is a demo sketch that demonstrates two different point spheres. The fibonacci spiral approach is a bit more involved, gives relatively even coverage of the surface -- unlike z-projection of a plane of points, which is simpler to implement, but gives dense points at the pole (center) and creates unusual curved artifacts at the equator (edges).
NOTE: For performance, you don't want to recalculate every single draw loop the way that this example -- it is written simply for demo clarity. Instead, it is much more efficient to calculate the point locations once, then store those locations in an array, then loop through that array at draw time. See Jim Bumgardner's original fibonacci sphere code for an example of that.