Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Method:
- 1. Construct spherical lattice that will be contained within
- another larger sphere that we will be testing the gravity at -
- at different points.
- 2. Move the point from the centre of the large, containing sphere
- to an outside location of any choosing.
- 3. Display the results at the test points on a graph.
- 4. Win.
- Method for constructing spherical lattice:
- 1. inputs, radius of the larger sphere (a: large whole number, preferably a multiple of 10), radius of the interior
- spheres (b: small whole number that should evenly and naturally divide the radius of the larger sphere in whole number ratios)
- 2. A valid internal sphere is one whose surface (radius) does not exceed the boundaries of the larger containing sphere, and does not over lap with any other spheres. For the sake of simplicity (not accuracy, this is an estimate), I am going to treat the interior spheres as cubes (mainly because I am going to be constructing a cubic lattice), this is because using pythagoras' theorem to test whether the corners of the cubes exceed the distance from the center of the sphere to the surface of the larger containing sphere. (pythagoras' theorem in 3 dimensions r^2 = (x1 - x2)^2 + (y1 - y2)^2 + (z1 - z2)^2
- 3. Build the sphere using a top down view (treating the XY plane as the top view), start at position (b, b, sqrt(a^2-(2*b)^2))
- then copy this location into the other 3 quadrants. These points will be loaded into an array and given unique identifiers.
- 4. Move to the next level down, (b, b, [start y]-b*2*1), the times by 1 indicates where the level itteration number goes, this will cause the level to decrement down (I know it's a tautology) by a diameter each time. Copy this result to the other 3 quadrants once more.
- 5. Move to the other test points on that level. Do this by using the simple pixel mapping that I used in the image printer. Move to the next X value (curPx + 2b), and then test the 8 points around the cube, (x+b, y+b, z+b), (x-b, y+b, z+b), (x-b, y-b, z+b)... etc. If the distance to any of these points from (0, 0, 0) is greater than the radius of the larger containing circle, the sphere will not be created and the testing will move to the next Y row, also testing this cube's points. When the Y test fails, move down to the next level. Copy these results to the other 3 quadrants.
- 6. Note, when initial testing of the next level fails, end constructing the cube lattice.
- How to move the point (easy):This is basic modulus and common factors. The crests of each of the frequencies line up
- 1. Start at (0, 0, 0). Work out the force vectors (F = GM/r^2), and split this into the X, Y, Z values (so each X, Y, Z value will be true for F^2 = X^2 + Y^2 + Z^2), load these values into array. Force[testpoint][x] = F.
- 2. Once the array has been filled, work out the sum of the X, Y, Z values for force, the result will be the next force. Return F = X^2 + Y^2 + Z^2.
- GRAPH RESULTS:
- 1. X-axis is the distance from the centre of the sphere, Y-axis is the resultant net force.
- Now I gotta write this son of a bitch...
- */
- function cubeLatticeArray($a, $b){
- //$a is the radius of the larger sphere, $b is the radius of the smallers spheres that are fitting into the larger sphere.
- //This function will only solve for one eighth of the cube. I will later have this function copy these results over
- //to the other 7 parts of the sphere.
- $points[0] = array('x' => $b, 'y' => $b, 'z' => sqrt(pow($a, 2)-pow(2*$b, 2))); //I solved this line for myself, stfu
- $radius = pow($a, 2);
- $pass = true;
- for($i = 1; $pass == true; $i++){
- $current = end($points);
- if($radius > (pow($current['x']+$b, 2)+pow($current['y']+3*$b, 2)+pow($current['z']+$b, 2))){
- //Move to the next Y cube relative to the last exact position
- $points[$i] = array('x' => $current['x'], 'y' => $current['y']+2*$b, 'z' => $current['z']);
- }elseif($radius > (pow($current['x']+3*$b, 2)+pow(2*$b, 2)+pow($current['z']+$b, 2))){
- //Move to the next X cube relative to the last Z and X position (not Y)
- $points[$i] = array('x' => $current['x']+2*$b, 'y' => $b, 'z' => $current['z']);
- }elseif($radius > (pow(2*$b, 2)+pow(2*$b, 2)+pow($current['z']-3*$b, 2)) && $current['z']-3*$b >= 0){
- //Move to the next Z cube relative to the last Z value (not x or y)
- $points[$i] = array('x' => $b, 'y' => $b, 'z' => $current['z']-2*$b);
- }else{
- $pass = false;
- }
- }
- return $points;
- }
- $i = cubeLatticeArray(100, 10);
- var_dump($i);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment