Jump to content

Help: TWR formula in Visual basic?


Brainlord Mesomorph

Recommended Posts

I hate to show my ignorance esp. in things a lot of other people understand.

As a veteran VB coder I can grok some very heavy math as long as its typed in text. But when it comes to something as simple as this:

eb56e634c4b30235deeaf0a0708fbfcf.png

not so much.

I've got thrust in kilo-newtons (right?) KSP gives me mass in decimal tons (?) and g I assume is Kerbin (Earth) gravity (in m/s squared?) -- THAT's where physics always came apart for me. I get the concepts, but the unit-conversion in the math just drives me batty!

I'm trying to write a function to calc the TWR of an entire ship, Anyone want to show me what that should look like in VB?

Many TIA

Bra

Edited by Brainlord Mesomorph
Link to comment
Share on other sites

A Newton is a kg m/s2,hence how you get a ratio as the bottom of the equation is kg * m/s2 

So if:

  • Fr = thrust in kN
  • m = mass in tonnes

then

TWR = (1000*Fr) /(1000*m *9.81) 

The 1000's are obviously the conversions from kg to tonnes, and N to kN, and they cancel out so your original equation works fine

TWR = Fr/(m*9.81)

Link to comment
Share on other sites

That would be a good source of confusion :D  KSP works in metric tonnes not imperial tons, so yes, a tonne is a megagram.  But to really confuse things the SI unit for mass is the kg not the g.

You're in good company though, NASA's Mars climate orbiter crashed because one bit of software was doing calculations in imperial, and another was acting on the data assuming it was in metric.

As a Brit we get used to working with both systems, I buy fuel in litres and beer in pints.  I weight myself if stone but my flight luggage in kg, and market traders now get fined if they sell in pounds.  Road signs are in miles and I calculate fuel economy in miles per gallon (a gallon being 1.2 US gallons).  I'm a farmers son and crop yields are in tonnes per acre, although most people from non farming backgrounds work in square meters and wouldn't know how long a chain is even if they play cricket (a wicket is 1 chain long).  Horse racing is in Miles and Furlongs, but running races tends to be 5km, 10km, 13 miles and 26 miles.

We're a strange country :D

 

 

 

Link to comment
Share on other sites

WAIT: doesn't that mean the  ">1" part doesn't  belong there?

A ratio equals a fraction. that makes sense.  And your TWR must be greater than 1 *if* your going to move (off the ground in gravity G). But it isn't always true.  (some things don't move off the pad, but fly in space)

Why is that ">1" there?

Edited by Brainlord Mesomorph
Link to comment
Share on other sites

44 minutes ago, Brainlord Mesomorph said:

Why is that ">1" there?

It's there in order to tell you "When making the calculation, you must arrive at a number greater than 1, or else you will not go to space today."

(i.e. you pretty much had it pegged)

Or, to express it in code (C# rather than VB here, but you get the idea):

public static readonly double kerbinGravity = 9.81 // m/s2

public static double CalculateTWR(double thrustKilonewtons, massTonnes)
{
    return thrustKilonewtons / (massTonnes * kerbinGravity);
}

public static bool CanIGoToSpaceToday(double thrustKilonewtons, massTonnes)
{
    return CalculateTWR(thrustKilonewtons, massTonnes) > 1.0;
}

A suggestion:  If you're dabbling in coding and you're in any way involved with KSP, it's worth learning C# rather than VB.  Not only is it a cooler language ;) ... it's also what pretty much all KSP mods are written in, you'll find a lot more people in the KSP community who are willing & able to give advice in it.

(Since it's .NET, it's binary-compatible with VB.  For example, I believe it would be possible to write a KSP mod in VB.  But I've never come across anyone who actually does; they all use C#.)

Edited by Snark
Link to comment
Share on other sites

39 minutes ago, Brainlord Mesomorph said:

Why is that ">1" there?

To let you know that if your (vertically launched) rocket's TWR isn't over 1, you won't be going to space today.

Edit: I wish the forum would let us know before posting when someone has already answered a question. Mutter.

Edited by swjr-swis
Link to comment
Share on other sites

32 minutes ago, swjr-swis said:

To let you know that if your (vertically launched) rocket's TWR isn't over 1, you won't be going to space today.

Edit: I wish the forum would let us know before posting when someone has already answered a question. Mutter.

I got that part. I'm saying its not part of the definition (or calculation of) TWR and it was confusing to me (and might be to others)

TWR will *not* always be >1

but it always will be = Fr/(m*9.81)

Edited by Brainlord Mesomorph
Link to comment
Share on other sites

21 minutes ago, Brainlord Mesomorph said:

I got that part. I'm saying its not part of the definition (or calculation of) TWR and it was confusing to me (and might be to others)

TWR will *not* always be >1

but it always will be = Fr/(m*9.81)

Well, yeah.  So all one can say is either,

  • "whoever gave you that formula was a lying sack of <something unpleasant>", or
  • "whoever gave you that formula assumed you'd understand from context what the >1 meant", or
  • "maybe it was clearer in the original context, but you presented the formula here without any reference to where you got it from, and therefore it's not really possible for anyone to comment on"

;)

Joking aside, though... agreed that it can be confusing!

Link to comment
Share on other sites

1 hour ago, Snark said:

If you're dabbling in coding and you're in any way involved with KSP, it's worth learning C# rather than VB.  Not only is it a cooler language ;)

9 lines to do what VB can do in 1?  :D

 

real_programmers.png

 

 

I'm an engineer/analyst not a programmer, I just hack stuff around in VBA instead since nobody lets me use Fortran any more.

Edited by RizzoTheRat
Link to comment
Share on other sites

12 minutes ago, RizzoTheRat said:

9 lines to do what VB can do in 1?

Oh, hush.  You can code that in one line in C#, too.  :P

Not gonna get into a this-language-is-better-than-that-language debate here, just offering some friendly practical advice.

Link to comment
Share on other sites

15 hours ago, RizzoTheRat said:

As a Brit we get used to working with both systems, I buy fuel in litres and beer in pints.  I weight myself if stone but my flight luggage in kg, and market traders now get fined if they sell in pounds.  Road signs are in miles and I calculate fuel economy in miles per gallon (a gallon being 1.2 US gallons).  I'm a farmers son and crop yields are in tonnes per acre, although most people from non farming backgrounds work in square meters and wouldn't know how long a chain is even if they play cricket (a wicket is 1 chain long).  Horse racing is in Miles and Furlongs, but running races tends to be 5km, 10km, 13 miles and 26 miles.

We're a strange country :D

Ye gods that's a messed up arrangement.. at least in Australia, when we went metric, we just went all in.. no more imperial units in use at all. Now, there are several generations that only think in metric. Being 55, I lived through the switch, and can use either system comfortably.. anyone younger, not so much.

Edited by JAFO
Link to comment
Share on other sites

14 hours ago, RizzoTheRat said:

I just hack stuff around in VBA instead since nobody lets me use Fortran any more.

Hey.. even Ars Technica was forced to admit that Fortran still kicks butt.. :):cool:

 

http://arstechnica.com/science/2014/05/scientific-computings-future-can-any-coding-language-top-a-1950s-behemoth/

Edited by JAFO
Link to comment
Share on other sites

31 minutes ago, JAFO said:

Ye gods that's a messed up arrangement

Just Another F***ing Observer?

I worked for Rolls Royce some years ago. Due to high tolerances on components, international customers, and some parts commonality between engines, they had some drawings where a single component might have one bit measured in metric and other bits in imperial :D And don't get me started on BTU/kg...

 

Sorry, wandering way off topic.

 

OP - Makes sure you use the sea level thrust not the vacuum one, I've had rockets sat on the launch pad at full thrust going nowhere because of that one :D.  Anyone know how the thrust changes with altitude?

Edited by RizzoTheRat
Link to comment
Share on other sites

21 hours ago, RizzoTheRat said:

OP - Makes sure you use the sea level thrust not the vacuum one, I've had rockets sat on the launch pad at full thrust going nowhere because of that one :D.  Anyone know how the thrust changes with altitude?

atmospheric pressure slows the exhaust velocity, effectively lowering the output thrust and isp, a simple case of needing to move the air out of the way

Link to comment
Share on other sites

19 minutes ago, kurja said:

Why US gallons instead of UK/imperial gallons?

Imperial, but pointing out to any that don't realise that a real gallon is 1.2 Us gallons

 

2 hours ago, jhousen said:

atmospheric pressure slows the exhaust velocity, effectively lowering the output thrust and isp, a simple case of needing to move the air out of the way

Sorry I meant what's the curve like.  Presumably pressure drops off as a function of altitude squared, but the thrust is related to the pressure differential, so if the exhaust pressure is significantly higher than atmospheric is it going to change more slowly?

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...