Does anyone know how to create an algorithm capable of making the figure just like in the picture, when given a set of specific points (3D array)
Does anyone know how to create an algorithm capable of making the figure just like in the picture, when given a set of specific points (3D array)
답변:
Coming here after the battle, but since there are no accepted answer yet and seeing that @Luke refuses to get the rep he deserves, here is a quick summary of the link he provided.
So the full algorithm is available here:
http://blog.andreaskahler.com/2009/06/creating-icosphere-mesh-in-code.html
The idea is to bootstrap your mesh with a simple method which gives you a sphere with 20 faces, and then refine it until you are satisfied.
You start with an icosahedron. As the wikipedia article says, you can obtain the vertices by drawing three identical and orthogonal rectangle. You have 3 rectangles with 4 corner each --> 12 vertices.
Wikipedia illustration:
For example, the Z plan points are (a, b are the rectangle lengths):
Now you still have to find the 20 faces. This is left as an exercise to the reader :p
Now that you have a basic sphere, you may want to add polygons. You do so with this simple algorithm:
for each iteration:
# each iteration multiplies by 4 the number of faces
for each edge at the current iteration:
split the edge in two
replace the middle point on the sphere
To find the middle point, we suppose that we wish to create the unit sphere (center (0, 0, 0), radius 1).
middlePoint(p1, p2):
middle = Point((p1.X + p2.X / 2), # same for y, z)
radius = sqrt(middle.X^2, middle.Y^2, middle.Z^2)
return Point(middle.X / radius, # same for y, z)
At each iteration, we may have to reconstruct the faces, but it is fairly easy. Each face is divided into four: