private static SciNumber Combine(SciNumber a, SciNumber b, Func <double, double, double> combine) { int expDif = a.exponent - b.exponent; double bMan = b.mantissa * Math.Pow(10, -expDif); return(new SciNumber(combine(a.mantissa, bMan), a.exponent)); }
public T Scale <T>(T quantity) where T : QuantityN { SciNumber scaler = SciNumber.One; quantity.units.unitExponents.ForEach(x => scaler *= (unitScales.FirstOrDefault(y => y.unit == x.unit)?.scale ?? SciNumber.One)); return(QuantityN.CreateQuantityInstance <T>(quantity.values.Select(x => x * scaler).ToList(), quantity.units)); }
public void SetTimeScale(float timeScale, bool setSlider = true) { SimulationManager.Instance.timeScale = timeScale; timeScaleLabel.text = "Time Scale:\n" + timeScale + " Seconds Per Second"; if (setSlider) { slider.value = SciNumber.EstimateLog(timeScale); } }
private SciNumber SqrtStep(SciNumber s, SciNumber x, int stepCount) { SciNumber nextX = 0.5 * (x + (s / x)); if (stepCount >= SqrtSteps) { return(nextX); } else { return(SqrtStep(s, nextX, ++stepCount)); } }
public Quantity Dot <T>(T other) where T : QuantityN { CheckDimensionCount(this, other); SciNumber dot = SciNumber.Zero; for (int i = 0; i < values.Count; i++) { dot += values[i] * other.values[i]; } return(new Quantity(dot, units + other.units)); }
private void Start() { slider = GetComponent <Slider>(); slider.minValue = 0; slider.maxValue = maxTimeScaleExponent; SetTimeScale(1f); slider.onValueChanged.AddListener((v) => { SetTimeScale(SciNumber.EstimateExponential(v), setSlider: false); }); }
public void SetUnitScale(SIUnitType unit, SciNumber scale) { var distanceScaleInfo = unitScales.FirstOrDefault(x => x.unit == unit); if (distanceScaleInfo != null) { distanceScaleInfo.scale = scale; } else { unitScales.Add(new UnitScale() { scale = scale, unit = unit }); } }
public void SystemFocus(GravitationalBody systemCenter, SciNumber distanceScale = null) { if (currentFocus == systemCenter) { return; } currentFocus?.SetViewLevel(ViewLevel.None); currentFocus?.OrbitedBy.ForEach(x => x.SetViewLevel(ViewLevel.None)); if (distanceScale != null) { SetUnitScale(SIUnitType.Meter, distanceScale); } systemCenter.SetViewLevel(ViewLevel.SystemCenter); systemCenter.OrbitedBy.ForEach(x => x.SetViewLevel(ViewLevel.Orbiting)); currentFocus = systemCenter; }
/// <param name="trueAnomoly">Provide a true anomoly to sample the orbit</param> public MechanicalElements ToMechanicalElements(Quantity mu, double?trueAnomoly = null) { var ta = trueAnomoly ?? this.TrueAnomoly; var rA = SemiMajorAxis / (1 + Eccentricity * Math.Cos(ta)); var perifocalR = new Quantity3(rA.TrueValue * Math.Cos(ta), rA.TrueValue * Math.Sin(ta), SciNumber.Zero, rA.units); var vP = new SciNumber(-Math.Sin(ta)); var vQ = new SciNumber(Eccentricity + Math.Cos(ta)); var perifocalV = (mu / SemiMajorAxis).Sqrt <Quantity>() * new Quantity3(vP, vQ, SciNumber.Zero); //TODO: use doubles instead var pToE = PerifocalToEquitorial(); return(new MechanicalElements() { position = perifocalR.Mul(pToE), velocity = perifocalV.Mul(pToE), }); }
//Inverse of EstimateExponential. Used for UI public static float EstimateLog(float v) { var s = new SciNumber(v); return((float)(s.exponent + ((s.mantissa - 1) / 10))); }
public Quantity4(SciNumber x, SciNumber y, SciNumber z, SciNumber w, Units units = null) : base(new List <SciNumber>() { x, y, z, w }, units) { }
public Quantity4(Quantity3 xyz, SciNumber w) : base(new List <SciNumber>() { xyz.X.TrueValue, xyz.Y.TrueValue, xyz.Z.TrueValue, w }, xyz.units) { }
public Quantity3(SciNumber x, SciNumber y, SciNumber z, Units units = null) : this(new List <SciNumber>() { x, y, z }, units) { }
public Quantity(SciNumber value, Units units = null) : base(new List <SciNumber>() { value }, units) { }