/SolarSystem/SolarSystemBodyFactory.cs
C# | 46 lines | 40 code | 6 blank | 0 comment | 0 complexity | f168fe4096fa316e66d33e6824bb5ad9 MD5 | raw file
Possible License(s): BSD-3-Clause
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using MathNet.Numerics.LinearAlgebra.Double;
-
- namespace SolarSystem
- {
- public class SolarSystemBodyFactory
- {
- private static readonly Double MassOfSun = 1.9891 * Math.Pow(10, 30);
-
- public static Body CreateSun()
- {
- return new Body()
- {
- Name = "Sun",
- Radius = 6.96342 * Math.Pow(10, 5),
- Mass = 1.9891 * Math.Pow(10, 30),
- Position = new DenseVector(new[] { 0d, 0d }),
- Velocity = new DenseVector(new[] { 0d, 0d }),
- Rotation = 0,
- RotationVelocity = 0
- };
- }
-
- public static Body CreateBody(String name, Double radius, Double mass, Double semiMajorAxis, Double eccentricity, Double rotationVelocity)
- {
- var position = new DenseVector(new[] { GetDistanceAtAphelion(semiMajorAxis, eccentricity), 0 });
- var velocity = new DenseVector(new[] { 0, GetVelocityAtAphelion(semiMajorAxis, eccentricity) });
-
- return new Body() { Name = name, Radius = radius, Position = position, Velocity = velocity, Rotation = 0, RotationVelocity = rotationVelocity };
- }
-
- private static Double GetDistanceAtAphelion(Double semiMajorAxis, Double eccentricity)
- {
- return (1 + eccentricity) * semiMajorAxis;
- }
-
- private static Double GetVelocityAtAphelion(Double semiMajorAxis, Double eccentricity)
- {
- var distance = GetDistanceAtAphelion(semiMajorAxis, eccentricity);
- return Math.Sqrt(Constants.GravitationalConstant * MassOfSun * (2 / distance - 1 / semiMajorAxis));
- }
- }
- }