Not really sure if it is correct, but you would need to know the equation of a sphere ((x - a)^2 + (y - b)^2 + (z - c)^2 = r^2), and plot it with particles.

First of all, we need to know your parameters. For example, how do you specifiy the density of particles? Remember, particles are points, and we are making an area, so density is definitely a concern. I am not very good with spheres (I had never learnt anything about it except the formula of its surface area and volume, as well as definite integration for calculating volume of solid of revolution with equations of circles), so I am not sure how to provide parameters properly. With my limited knowledge, I would consider using $t, the number of dots per revolution. So, from a cross section from top view (assuming "north pole" is top and "south pole" is bottom), we will see longitudinal lines going vertically, and from a cross section from front view, we will see latitudinal lines running. We will be drawing points on the intersecting points of the longitudinal and latitudinal lines. PHP: /*** @param Vector3 $center the central point of the sphere* @param float $radius the radius of the sphere* @param int $t number of latitudinal lines. This can be a decimal number, but it will work strangely, won't it?* @param callable $spawnParticle a callable that accepts three parameters: $x, $y, $z. It is called per dotted point*/function(Vector3 $center, $radius, $t, callable $spawnParticle){ /** * This is the angle formed by longitudinal lines from the top view. * Use your imagination to think how it works with latitudinal lines. * * @var float $delta */ $delta = M_PI * 2 / $t; // now, for every longitudinal line // $ry is the angle EOP, where O is center of sphere, E is the horizontal equator and P is one point on the longitudinal line // M_PI_2 radian is 90 degrees for($ry = -M_PI_2; $ry < M_PI_2; $ry += $delta){ $y = $center->y + $radius * sin($ry); // draw the picture yourself to understand why sin /** @var float $xz the radius of the longitudinal line's circle */ $xz = $radius * cos($ry); // $rh is the angle PO'P', where P and P' are points on the longitudinal line, and O' is the center of the longitudinal line's circle for($rh = 0; $rh < M_PI * 2; $rh += $delta){ $x = $center->x + $xz * cos($rh); $z = $center->z + $xz * sin($rh); $spawnParticle($x, $y, $z); } }}

Have you tried actually reading the code to adapt into your use case? Please note that PHP code isn't charcoal that you can put into any furnace to smelt any items. They should be treated like enzymes, handled with care at proper conditions (air pressure, temperature, pH), and only used to catalyze a limited amount of reactions, but not all. Using code snippets without checking whether they work would be like trying to increase the rate of a reversible exothermic reaction by increasing the temperature. Indeed increasing the temperature can increase the rate of reactions, but while it makes the exothermic reaction faster, it makes the endothermic reverse reaction even faster, thus reducing the yield of the exothermic reaction's product. Have you thought clearly enough before putting in any code? It is just like putting `rm -rf ` in front of a directory name can remove a directory properly, but if you use it wrongly and put it in front of a slash, you will be trying to delete the whole filesystem.