using System;
using System.Collections.ObjectModel;
using System.IO;
using System.Windows.Forms;

namespace Moon_Jumper
{
public partial class Form4 : Form
{
public Form4()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{

double MassMoon = 0;
long RayonMoon = 0;
double GParam = 0.0;

if (comboBox1.SelectedItem.ToString() == "Moon")
{
MassMoon = 7.342E22; // kg 6.417E2)
RayonMoon = 1736000; // meters 3396000
GParam = 4.9E12;
}
else if (comboBox1.SelectedItem.ToString() == "Earth")
{
MassMoon = 5.97237E24; // kg 6.417E2)
RayonMoon = 6356000; // meters 3396000
GParam = 3.986E14;
}
else if (comboBox1.SelectedItem.ToString() == "Mars")
{
MassMoon = 6.4171E23; // kg 6.417E2)
RayonMoon = 3396200; // meters 3396000
GParam = 4.283E13;
}

double CableDensity = double.Parse(textBox1.Text);
double CableHeight = double.Parse(textBox2.Text);

double Divider = double.Parse(textBox3.Text);
long CableDivider = long.Parse(textBox4.Text);

Collection < Collection < Collection < bool > > > Moon = Create_Sphere(RayonMoon, (long)(Divider));

double MoonDensity = MassMoon / (4 / 3.0 * Math.PI * Math.Pow(RayonMoon, 3));
double MoonPartMass = MoonDensity * Math.Pow(2 * RayonMoon / Divider, 3);
double CablePartMass = CableDensity * CableHeight / CableDivider;

double G = 6.6740831E-11;

double TotalForce = 0.0;
double TotalCentripede = 0.0;

for (long i = 1; i < CableHeight; i = i + (long)(Math.Ceiling(CableHeight / CableDivider)))
{
for (int k = 1; k < = Divider; k++)
{
for (int l = 1; l < = Divider; l++)
{
for (int m = 1; m < = Divider; m++)
{
if (Moon[k][l][m] == true /*k == 50 && l == 50 && m == 50*/)
{
double step = 2 * RayonMoon / Divider;
double b = i + step * m;
double a = Math.Sqrt(Math.Pow((RayonMoon - l * step), 2) + Math.Pow((RayonMoon - k * step), 2));
double tmp = (MoonPartMass * CablePartMass * G / (a * a + b * b)) * Math.Cos(Math.Atan(a / b));
TotalForce += tmp;
}
}
}
}
TotalCentripede += CablePartMass * Math.Pow(Math.Sqrt(GParam / (RayonMoon + CableHeight)) / (RayonMoon + CableHeight) * (RayonMoon + i), 2) / (RayonMoon + i);
}

MessageBox.Show(TotalForce.ToString() + " :: " + (TotalCentripede).ToString() + " :: " + (TotalForce - TotalCentripede).ToString());
}

private Collection < Collection < Collection < bool > > > Create_Sphere(double rayon, long parts)
{
Collection < Collection < Collection < bool > > > sphere = new Collection < Collection < Collection < bool > > >();

double step = 2.0 * rayon / parts;

for (long i = 0; i < = parts; i++)
{
Collection < Collection < bool > > tmp2 = new Collection < Collection < bool > > ();
for (long j = 0; j < = parts; j++)
{
Collection < bool > tmp = new Collection < bool >();
for (long k = 0; k < = parts; k++)
{
bool test = false;

double distance = Math.Sqrt(Math.Pow(rayon - i * step, 2) + Math.Pow(rayon - j * step, 2) + Math.Pow(rayon - k * step, 2));

if (distance < = rayon) test = true;

tmp.Add(test);
}
tmp2.Add(tmp);
}
sphere.Add(tmp2);
}

return sphere;
}
}
}