Jump to content

Game Calculator


superlou

Recommended Posts

I've seen a few posts that go pretty deep into some excellent math. I was wondering if anybody would have a use for a tool to experiment with writing gameplay optimizations? I've duct-taped a demo here that is a paper-thin (and ugly, don't forget ugly) wrapper over the Sage mathematics platform. Sage is pretty awesome and covers CAS and matrix operations using a python-like syntax.

Anyway, if there's some interest, I'll try to keep developing and make it more of a useable tool rather than a tech demo. Open to any comments and suggestions. It currently doesn't have basic nicities like version control or permissions, so you might want to play nice with each other's tools. It's also on a dirt cheap VPS so I apologize if it's not the fastest site out there.

Thanks,

Louis

Link to comment
Share on other sites

I've developed a code piece that does the above in C, for eccentric orbits (e up to 1, not more), for Kerbin only at the moment (can do it for other KSP bodies, may add an option for custom bodies too).


#include <math.h>
#include <stdio.h>

int main(void)

{

float apoapsis;
float periapsis;
float radius[17] = {1,1,1,1,600000,1,1,1,1,1,1,1,1,1,1,1,1};
float mu[17] = {1,1,1,1,3.5316e12,1,1,1,1,1,1,1,1,1,1,1,1};
int planet;
float soi[17] = {1,1,1,1,84159286,1,1,1,1,1,1,1,1,1,1,1,1};
float eccentricity;
float vp;
float va;
int i;
float vp2;
float va2;
float guess = 1000;
int repeat;

repeat = 1;

while (repeat != 0)
{
planet = 17;


printf("Velocity Calculator\n");
printf("Pick a body - \n");
printf("Sun - 0\n");
printf("Moho - 1\n");
printf("Eve - 2\n");
printf("Gilly - 3\n");
printf("Kerbin - 4\n");
printf("Mun - 5\n");
printf("Minmus - 6\n");
printf("Duna - 7\n");
printf("Ike - 8\n");
printf("Dres - 9\n");
printf("Jool - 10\n");
printf("Laythe - 11\n");
printf("Vall - 12\n");
printf("Tylo - 13\n");
printf("Bop - 14\n");
printf("Pol - 15\n");
printf("Eeloo - 16\n");
while (planet > 16 || planet < 0)
{
printf("Pick your body:");
scanf("%d", &planet);

}



printf("Input Periapsis altitude (m):");
scanf("%f", &periapsis);
printf("Input Apoapsis altitude (m):");
scanf("%f", &apoapsis);
eccentricity = (apoapsis - periapsis)/(apoapsis + periapsis + 2*radius[planet]);
printf("%f\n %f\n", eccentricity, mu[planet]);
vp2 = (1+eccentricity)*mu[planet]/(periapsis + radius[planet]);
va2 = (1-eccentricity)*mu[planet]/(apoapsis + radius[planet]);


va = sqrt(va2);
vp = sqrt(vp2);
printf("Periapsis velocity is: %f\n", vp);
printf("Apoapsis velocity is: %f\n", va);

if (apoapsis > soi[planet])
{
printf ("Warning, you will escape into the parent SOI!\n");
}

printf("Repeat? Enter zero for no, any other integer for yes\n");
scanf("%d", &repeat);

}

return 0;

}


Link to comment
Share on other sites

Hi SunJumper. I converted the C code to Sage: http://gath.louissimons.com/tools/3

I need to figure out how to have my preprocessor identify strings properly. Currently, when you enter the body name, you need to wrap it in quotes. So, if I enter 'kerbin', 70000, and 73000, I get:

Eccentricity: 0.00297619047619048

Periapsis velocity: 2285.64390920694

Apoapsis velocity: 2299.28954448579

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...