Created
June 5, 2016 15:15
-
-
Save greenlion/7d4cdc403759ad4ce7426c00f6b1323e to your computer and use it in GitHub Desktop.
start of the physic library for a universal simulator based on 'different physics'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.measure.*; | |
import javax.measure.converter.*; | |
import javax.measure.quantity.*; | |
import javax.measure.unit.*; | |
import javax.realtime.*; | |
import javolution.*; | |
import javolution.context.*; | |
import javolution.io.*; | |
import javolution.lang.*; | |
import javolution.testing.*; | |
import javolution.text.*; | |
import javolution.util.*; | |
import javolution.xml.*; | |
import javolution.xml.sax.*; | |
import javolution.xml.stream.*; | |
import javolution.xml.ws.*; | |
import org.jscience.*; | |
import org.jscience.economics.money.*; | |
import org.jscience.geography.coordinates.*; | |
import org.jscience.geography.coordinates.crs.*; | |
import org.jscience.mathematics.function.*; | |
import org.jscience.mathematics.number.*; | |
import org.jscience.mathematics.structure.*; | |
import org.jscience.mathematics.vector.*; | |
import org.jscience.physics.amount.*; | |
import org.jscience.physics.model.*; | |
import org.opengis.metadata.*; | |
import org.opengis.metadata.citation.*; | |
import org.opengis.metadata.extent.*; | |
import org.opengis.referencing.*; | |
import org.opengis.referencing.crs.*; | |
import org.opengis.referencing.cs.*; | |
import org.opengis.spatialschema.geometry.*; | |
import org.opengis.spatialschema.geometry.geometry.*; | |
import org.opengis.util.*; | |
/* | |
import javax.measure.quantity.*; | |
import javax.measure.unit.SI; | |
import javax.measure.unit.Unit; | |
*/ | |
/* | |
import peasy.PeasyCam; | |
PeasyCam cam; | |
int scale; | |
*/ | |
class UnifiedPhysics { | |
/* Universal constants */ | |
Amount<Duration> B = Amount.valueOf("0.879").to(SI.SECOND); // braking force (fractional seconds) | |
Amount<Dimensionless> SIDEREAL = Amount.valueOf("86169.09").to(Unit.ONE); | |
Amount<Dimensionless HALF_SIDERIAL = SIDEREAL.divide(2); | |
Amount<Length> C = Amount.valueOf("9.174E15").to(SI.METER); // c_prime | |
Amount<Dimensionless> PI = Amount.valueOf("3.1415926535897932384626").to(Unit.ONE); | |
/* These are the Unified Physics equations */ | |
Amount<Velocity> omega(Amount<Length> r) { | |
//(2 pi r)/86400 = (pi r)/43200 | |
return r.times(PI).divide(HALF_DAY).to(SI.METERS_PER_SECOND); | |
} | |
Amount<Velocity> vel_orb(Amount<Length> r1, Amount<Length> r2, Amount<Length> d) { | |
return B.times(r1.times(r2)).divide(d).to(SI.METERS_PER_SECOND); | |
} | |
Amount<Duration> period(Amount<Length> r1, Amount<Length> r2, Amount<Length> d) { | |
return B.times(12).times(d).divide(omega(r1).plus(omega(r2))).to(SI.SECOND); | |
} | |
Amount<Velocity> c(Amount<Duration> p) { | |
return C.divide(p).to(SI.METERS_PER_SECOND); | |
} | |
Amount<Acceleration> dt(Amount<Duration> vr, Amount<Length> d) { | |
return d.divide(vr.pow(2)).to(SI.METERS_PER_SQUARE_SECOND); | |
} | |
Amount<Velocity> g(Amount<Duration> vr) { | |
return c().divide(vr.pow(2)).to(SI.METERS_PER_SQUARE_SECOND); | |
} | |
/* returns degrees */ | |
Amount<Angle> refraction(Amount<Duration> p) { | |
return Amount.valueOf(360,Unit.ONE).divide(86400).times(B).divide(p).to(NonSI.DEGREE_ANGLE); | |
} | |
Amount<Angle> refraction_radians(Amount<Duration> p) { | |
return Amount.valueOf(360,Unit.ONE).divide().times(B).divide(p).to(SI.RADIAN); | |
} | |
/* Morgan-Keenan stellar classification */ | |
/* Sequence */ | |
static final int MK_MS = 13; | |
static final int MK_SC = 14; | |
static final int MK_Y = 12; | |
static final int MK_O = 11; | |
static final int MK_B = 10; | |
static final int MK_A = 9; | |
static final int MK_F = 8; | |
static final int MK_G = 7; | |
static final int MK_K = 6; | |
static final int MK_M = 5; | |
static final int MK_L = 4; | |
static final int MK_T = 3; | |
static final int MK_D = 2; | |
static final int MK_C = 1; | |
/* Luminosity classification */ | |
static final int MKL_0 = 0; | |
static final int MKL_Ia = 1; | |
static final int MKL_Ib = -1; | |
static final int MKL_II = 2; | |
static final int MKL_III= 3; | |
static final int MKL_IV = 4; | |
static final int MKL_V = 5; | |
static final int MKL_VI = 6; | |
static final int MKL_VII = 7; | |
class Body { | |
int mk_seq=0; | |
int mk_i=0;/* Intensity 0 = hottest, 9 = least hot*/ | |
int mk_l=0; | |
long scale = 1024; // move 1km at a time | |
Real density; | |
// 1 Muon neutrino radius is 1/3 that of an electron | |
Amount<Length> MR = Amount.valueOf("2.81794033×10^-15 m").divide(3).to(SI.METER); | |
private LargeInteger x; | |
private LargeInteger y; | |
private LargeInteger z; | |
// 1 for right spin, -1 for left spin | |
Amount<Dimensionless> spin = Amount.valueOf(1,Unit.ONE); | |
Amount<Length> radius; | |
Amount<Length> distance = Amount.valueOf(0, SI.METER); | |
void Body(Amount<Length> radius,Amount<Length> distance, long scale, Real density) { | |
radius = r; | |
distance = d; | |
this.scale = scale; | |
this.density = density; | |
} | |
void add_density(Real radius, Real distance) { | |
this.density.add(radius.divide(distance.pow(2))); | |
} | |
void Body(Amount<Length> r,Amount<Length> d) { | |
radius = r; | |
distance = d; | |
} | |
void set_scale(long scale) { | |
this.scale = scale; | |
} | |
void move(long ticks) { | |
for(long tick=0;tick<ticks;++tick) { | |
Amount<Angle> a = refraction(this.density); | |
x += spin * scale/density; | |
y += spin * scale/density; | |
z += spin * scale/density; | |
this.density = density.divide(this.spin * this.scale); | |
} | |
pushMatrix(); | |
translate(x,y,z); | |
sphere(radius); | |
popMatrix(); | |
} | |
} | |
/* Particles */ | |
class Muon extends Body { | |
Amount<Dimensionless> spin = Amount.valueOf(1,Unit.ONE); | |
Amount<Length> radius = MR; | |
} | |
class Antimuon extends Body { | |
Amount<Dimensionless> spin = Amount.valueOf(-1,Unit.ONE); | |
Amount<Length> radius = MR; | |
} | |
class Antiphoton extends Body { | |
Amount<Dimensionless> spin = Amount.valueOf(-1,Unit.ONE); | |
Amount<Length> radius = MR.times(2); | |
} | |
class Photon extends Body { | |
Amount<Dimensionless> spin = Amount.valueOf(0,Unit.ONE); | |
Amount<Length> radius = MR.times(2); | |
} | |
class Posiphoton extends Body { | |
Amount<Dimensionless> spin = Amount.valueOf(1,Unit.ONE); | |
Amount<Length> radius = MR.times(2); | |
} | |
class Electron extends Body { | |
Amount<Dimensionless> spin = Amount.valueOf(-1,Unit.ONE); | |
Amount<Length> radius = MR.times(3); | |
} | |
class Positron extends Body { | |
Amount<Dimensionless> spin = Amount.valueOf(1,Unit.ONE); | |
Amount<Length> radius = MR.times(3); | |
} | |
class Proton extends Body { | |
Amount<Dimensionless> spin = Amount.valueOf(1,Unit.ONE); | |
Amount<Length> radius = MR.times(5); | |
} | |
class Antiproton extends Body { | |
Amount<Dimensionless> spin = Amount.valueOf(-1,Unit.ONE); | |
Amount<Length> radius = MR.times(5); | |
} | |
class Neutron extends Body { | |
Amount<Dimensionless> spin = Amount.valueOf(-1,Unit.ONE); | |
Amount<Length> radius = MR.times(8); | |
} | |
class LargeBody extends Body { | |
void LargeBody(Amount<Length> radius, Amount<Length> distance) { | |
this.radius = radius; | |
this.distance = distance; | |
} | |
void LargeBody(Amount<Length> radius) { | |
this.distance = Amount.valueOf(0, SI.METER); | |
} | |
int type=0; | |
} | |
} | |
void setup() { | |
/* | |
int accuracy = 30; // 20 decimal zeros for integer values. | |
Real x = Real.valueOf(10864); | |
Real y = Real.valueOf(18817); | |
Real z = x.pow(4).times(9).plus(y.pow(4).opposite()).plus(y.pow(2).times(2)); | |
System.out.println("Result : " + z); | |
*/ | |
} | |
//<>// | |
class Body { | |
float energy = 0; | |
float radius = 0; | |
int x, y, z = 0; | |
int spin = 0; | |
Amount<Length> r; // radius (meters) | |
Amount<Length> d; // distance (meters) | |
// how many meters in 1 "pixel" | |
int scale = 1800; | |
int total_distance; | |
int total_time; | |
//vector<Body> sats; | |
// mass=kg radius=meters spin = -1, dist=meters | |
public Body(Body primary, float mass, float radius, int spin) { | |
this.add_mass(mass); | |
this.spin = spin; | |
} | |
// Return gravitional acceleration in m/s^2 | |
float gravity() { | |
return 299792000 / energy; | |
} | |
/* return straight-line distance between bodies (in meters) | |
c^2 = a^2 + b^2 | |
*/ | |
float distance(Body n) { | |
float a = abs(n.get_x() - this.x); | |
float b = abs(n.get_y() - this.y); | |
return sqrt(pow(a,2) + pow(b,2)); | |
} | |
/* get the increase in density at a distance */ | |
float project(int distance) { | |
return energy * 1/(distance * distance); | |
} | |
/* pretty self explanatory, add | |
the energy and fixup the mass */ | |
void add_e(float j, int spin) { | |
if(spin == 1 || spin == -1) { | |
this.spin = spin; | |
} else { | |
this.spin = 1; | |
} | |
energy += j; | |
} | |
// e=md^2 | |
void add_m(float m) { | |
energy += (m * pow(energy,2)); | |
} | |
void remove_e(float j) { | |
energy -= j; | |
} | |
void set_pos(int x, int y, int z) { | |
this.x = x; | |
this.y = y; | |
this.z = z; | |
} | |
int get_x() { | |
return this.x; | |
} | |
int get_y() { | |
return this.y; | |
} | |
int get_z() { | |
return this.z; | |
} | |
/* energyeft spin has negative energy | |
*/ | |
float get_e() { | |
return spin * energy; | |
} | |
/* Return angular momentum of the body | |
After it has been acted on by the | |
energyeft spin has negative angular momentum | |
*/ | |
float get_a() { | |
return spin * this.energy; | |
} | |
void add_mass(float m) { | |
energy += m * pow(energy,2); | |
} | |
// m = e/d^2 | |
float get_mass() { | |
return this.energy / pow(energy,2); | |
} | |
// move ahead one tick of the global clock with | |
// respect to the given object, and update | |
// the given object based on the movement | |
void tick(Body b) { | |
/* move the body over the number of meters in time scale */ | |
int dx =0, dy =0, dz = 0; | |
for(int i=0;i<scale;++i) { | |
// 1s/L | |
int contracted = spin * floor(1/energy); | |
/* refraction and pressure from D creates curvature | |
/z | |
|/ | |
---+--- x | |
/|y | |
/ | |
*/ | |
if(x>=0 && y>=0) { | |
dx += contracted; | |
dz -= contracted; | |
dy -= contracted; | |
}else if(x<=0 && y>=0) { | |
dx -= contracted; | |
dz -= contracted; | |
dy += contracted; | |
} else if(x<=0 && y<=0) { | |
dx += contracted; | |
dz -= contracted; | |
dy -= contracted; | |
} else if (x>=0 && y<=0) { | |
dx += contracted; | |
dz += contracted; | |
dy -= contracted; | |
} | |
} | |
} | |
} | |
class system { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment