I have written some java code for the calculation of some various acceleration and etc. type data. I am now trying to graph that data so I can pull specific data over a time line. The values I have received via my math program are purely accurate with several different means of error checking. I do not need assistance for the java programming. What I need is a accurate graphing techniques so I can get the appropriate data.


acceleration formula

The x axis in that is the time variable. The y axis should be distance, but I'm getting totally bogus numbers. I know I may be off on my understanding of how it would graph.

    double D = Double.parseDouble(txtDistance.getText());
    double T = Double.parseDouble(txtTime.getText());
    double IV = Double.parseDouble(txtIVelocity.getText());
    double M = Double.parseDouble(txtMass.getText());

    double hd = Distance(D);
    double ht = Time(T);

    //double A = (2 * (hd - ht * IV)) / (ht * ht);
    double A = 2 * (hd/ht - IV)/ht;     
    double PG = (A / 9.8) * 100;

    //IV + A * ht
    //double V = hd / ht;
    double V = IV + A * ht;
    double PL = (V / 299792458) * 100;
    double MPH = V * 2.236936;

    double F = M * A;
    double LBT = F * 0.224809;

    DecimalFormat df = new DecimalFormat("####0.0000");




As you can see by that, I am inputting distance, time, initial velocity, and mass. And in return, it calculates and displays final velocity, percent light speed, miles per hour, acceleration, percent G-force, trust in newton's, and lbs of thrust.

Sample data:

Distance: 160934400 Km (just over an AU) Time: 40 hrs Initial velocity: 3070 m/s (geosynchronous earth orbit) Mass: 54431 Kg

The craft starts in earth orbit and accelerates for 50% of the distance and decelerates for 50% of the distance. This is figured with 72000 seconds, and 80467200000 meters.

Sample response:

Final velocity: 1117600.0000 m/s Percent light: 0.3728 % Miles per hour: 2499999.6736 mph (for human understanding of speed for reader) Acceleration: 30.9592 m/s^2 Percent G-force: 315.9099 % Thrust: 315.9099 N Lbs Thrust: 378834.2788 Lbs (again for human understanding)

I know these numbers are as accurate as they can be utilizing the constant acceleration equations posted above. I know these numbers are extreme, but it is a science fiction novel.

The purpose of all this is I am writing a science fiction novel and I have a story line and a time line. I am needing various speeds, based on time and acceleration, etc. I have an additional program that will take this data and graph it so I can click on points to get the appropriate data I need at the given time in the story.

What is the appropriate means of graphing that so I can get accurate numbers that will make sense for my story when you, potential reader read the book?

As an aside for even more accurate numbers, I need to know how to modify my equations to account for gravitational interference in acceleration, etc.

I have spent the last week, upwards to 80 hours working on this so my book can be as accurate as it can be. With that being said, it would be near impossible for me to include all my work on this subject. Any assistance you are willing to offer so I can move forward with this novel would be extremely appreciated.

  • $\begingroup$ Define bogus numbers. $\endgroup$
    – Kyle Kanos
    Jun 12 '15 at 16:33
  • 3
    $\begingroup$ You seem to want to produce a graph as a necessary step for producing "accurate" values of velocity from time and accelleration. The graph seems superfluous and harmful to your aim - wouldn't it be simpler, quicker and more accurate to simply calculate the result using a calculator (or a three-cell spreadsheet)? $\endgroup$ Jun 12 '15 at 16:37
  • $\begingroup$ Potentially, you are correct, and would be a good thing to produce, and a bit of assistance in doing so would be greatly appreciated. I was preferring a graph for the visualization aspect of it, which could potentially be included in the book in some meaningful manner. For now a spreadsheet would get me going, but I would still like to have the graph and the knowledge by which it was created. $\endgroup$ Jun 12 '15 at 16:48
  • $\begingroup$ (.5 * 30.9592\right) x^2 + 3070x + 0 ........ When I graph that, I get a parabola that totally doesn't make any sense to the data I have. $\endgroup$ Jun 12 '15 at 16:52
  • $\begingroup$ (.5 30.9592) x^2 + 3070x + 0 ..... edit $\endgroup$ Jun 12 '15 at 16:58

I am more familiar with graphing in Python than in the language you are using. The following snippet of code produces the graph you are asking for:

import numpy as np
import matplotlib.pyplot as plt

# sci fi velocity graph
D = 160934400000     # m
v_i = 3070           # m/s
total_time = 40*3600 # seconds: 40 hours

# to cover half the distance in half the time, we solve
# x(t) = x(0) + v_0*t + 0.5*a*t*t
# x(0) = 0
# x(t) = D/2
# t = total_time / 2 = th
th = total_time / 2
a = 2.0*(xt/th-v_i)/th

print 'acceleration needed is %.2f m/s^2'%a
# this prints out 30.96 m/s^2 - encouraging

# calculate position during acceleration phase - every second:
tm = 20*3600 # time at mid point
for t in range(0,tm+1):
    x.append(v_i*t + 0.5 * a * t * t)

xm = x[-1] # position at mid point

for t in range(tm+1, 2*tm):
    x.append((v_i + tm*a)*(t-tm) - 0.5 * a * (t - tm) * (t - tm) + xm)

time = np.arange(0,2*tm)/3600.0

plt.plot(time, np.array(x)/1000)
plt.xlabel('time (hr)')
plt.ylabel('position (km)')

v_t = np.diff(x)
plt.xlabel('position (km)')
plt.ylabel('velocity (km/s)')

plt.plot(time[:-1], v_t/1000)
plt.xlabel('time (hr)')
plt.ylabel('velocity (km/s)')

This produces the following graph:

enter image description here

You can also plot velocity as a function of time:

enter image description here

Or as a function of position:

enter image description here

  • $\begingroup$ Comment in the programming: Numpy is a bit more expressive on the array math than you use. While I'm sure (hoping) that it was for clarity's sake, just thought I should point it out. $\endgroup$
    – Kyle Kanos
    Jun 12 '15 at 19:05
  • $\begingroup$ @KyleKanos Yes - I decided not to go all Python in this as it would likely confuse my audience. Actually I originally had tighter code with more lines of explanation, then decided to go more basic. Like this it is easier to follow / translate? $\endgroup$
    – Floris
    Jun 12 '15 at 19:17
  • $\begingroup$ i must say that actually comes out to the 1.6E11 meters is it supposed to, but i made a booboo in the explanation. that is included in your graph. it should accelerate to half point and decelerate to end point. from 0 to 40 it should appear to be more of a bell curve. $\endgroup$ Jun 12 '15 at 20:10
  • $\begingroup$ I am plotting the position, not the velocity, along the Y axis. The slope of this curve is the velocity - you see it accelerating for the first half and decelerating for the second half. If you want, you can plot velocity (which would be a triangle if plotted against time) or even velocity as a function of position (rather than time). I added those graphs. Did I understand you correctly? $\endgroup$
    – Floris
    Jun 12 '15 at 20:38
  • 1
    $\begingroup$ Mass is not an issue as the ship uses an experimental magnetic propulsion. The mass will not change. The sun is a rather large fuel tank. :) Thank you very much for your help. $\endgroup$ Jun 13 '15 at 1:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.