### Calculate Your Weight On Various Heavenly Bodies

by Ovid (Cardinal)
 on May 16, 2007 at 10:57 UTC ( #615742=CUFP: print w/replies, xml ) Need Help??

OK, so it's not terribly unique, but I thought it was a bit of fun. The background (and the explanation of some odd bits) is at my personal blog. I wrote this because I was curious about my weight on the new Earth which was discovered. The program takes your current weight (in any units) as an argument. Defaults to my weight :)

```#!/usr/bin/perl

use strict;
use warnings;

my \$weight = shift || 189;  # you can manually change the weight here,
+ if you prefer

# for simplicity's sake, we assume Audrey and Johnny are spherical
my @data = (

# body                mass in kg         radius in km
[ 'Mercury',          3.302 * 10**23,    2439.7    ],
[ 'Venus',            4.8685 * 10**24,   6051.9    ],
[ 'Earth',            5.9736 * 10**24,   6378.137  ],
[ 'Moon',             7.3477 * 10**22,   1748.14   ],
[ 'Mars',             6.4185 * 10**23,   3402.5    ],
[ 'Ceres',            9.46 * 10**20,     950       ],   # rough es
+timates
[ 'Jupiter',          1.8986 * 10**27,   71492     ],
[ 'Saturn',           5.6846 * 10**26,   60286     ],
[ 'Uranus',           8.6832 * 10**25,   25559     ],
[ 'Neptune',          10.243 * 10**25,   24764     ],
[ 'Pluto',            1.305 * 10**22,    1195      ],   # rough es
+timates
[ 'Eris',             1.6 * 10**22,      1200      ],   # rough es
+timates
[ 'Audrey Hepburn',   49.8951607,        0.0017018 ],
[ 'Johnny Depp',      70.3068174,        0.001778  ],
);

foreach my \$data (@data) {
my \$body = \$data->[0];
\$mass_of{\$body}   = \$data->[1];
}

\$mass_of{Hope}   = 5 * \$mass_of{Earth};

\$mass_of{'Heavy Earth'}   = 2 * \$mass_of{Earth};

\$mass_of{'Fat Earth'}   = \$mass_of{Earth};

print "If you weighed \$weight units ...\n";
foreach my \$body ( map( { \$_->[0] } @data ), 'Hope', 'Heavy Earth', 'F
+at Earth' ) {
printf "... you would weigh %.2f units on '\$body'\n" => weight_on(
+\$body);
}

sub weight_on {
my \$body = shift;
return \$weight * ( gravity(\$body) / gravity('Earth') );
}

sub gravity {
my \$body = shift;
}

sub density {
my \$body = shift;
}

Cheers,
Ovid

New address of my CGI Course.

Replies are listed 'Best First'.
Re: Calculate Your Weight On Various Heavenly Bodies
by Discipulus (Prior) on May 16, 2007 at 12:27 UTC
I really hope your default is in lbs...but
```
if (\$default->is_KG()){
require Rope;
my \$exerc = Rope->new(weight=>'+5');
\$exerc->skipping until \$default < 100;
}
kidding..

I really hope your default is in lbs

I'm a big fan of using units. There wasn't really anything (update: unit-self-aware) on CPAN at the time, so I wrote Math::Units::PhysicalValue, which would make the initial weight so much clearer.

```use Math::Units::PhysicalValue qw(PV);

my \$weight = PV "170 lb";
my \$mass   = \$weight + "0 kg";

print "My mass on earth at sea level is \$mass.\n";

-Paul

I feel obligated to point out here that your mass is not dependent on your position. :-) (Oddly enough, though, nobody seems to want to figure their weight in Newtons.)

If God had meant us to fly, he would *never* have given us the railroads.
--Michael Flanders

Yes, that default is definitely pounds, not stone, kilograms, ounces (avoirdupois or otherwise), or anything else. It's still too high of a default, though.

Cheers,
Ovid

New address of my CGI Course.

Create A New User
Node Status?
node history
Node Type: CUFP [id://615742]
Approved by marto
help
Chatterbox?
 [karlgoethebier]: He! [Eily]: Discipulus pretty much all oneliners are killing. Do you imagine how many people could be working if you asked them to do the same thing in C each time ? :P Eily is Listening to "Leave out all the rest" by Linkin Park [karlgoethebier]: that's why trade unions like C ;-)

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (10)
As of 2017-07-21 09:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
I came, I saw, I ...

Results (320 votes). Check out past polls.