aspose file tools*
The moose likes Meaningless Drivel and the fly likes Math help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Other » Meaningless Drivel
Bookmark "Math help" Watch "Math help" New topic
Author

Math help

Rick Beaver
Ranch Hand

Joined: Dec 14, 2004
Posts: 464
Hi all

I am writing a simple boat simulation and I am stuck on one part of calculating a boats speed / position. Please can someone help me with an equation?

Given a fixed speed (lets call it S - in metres per second) and a given bearing ( call it B - 0-359) - can anyone please tell me what calculation will tell me how many metres North (+ve or -ve) and how many metres East (+ve or -ve) the boat moves per second

I am sure there is rinky dink fangled equation for this - but I didn't do well in Math

Thanks guys


ph34r my 133t j4v4 h4><0r1ng sk177z
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20695
    ∞

I've done something like this: given a polygon defined with a series of lat/long points, determine the square kilometers.

The trick is that as you get further from the equator, the distance between 0 degrees and 1 degree east gets smaller.

So the answer I'm giving you is that this is not a quick, simple thing.


permaculture Wood Burning Stoves 2.0 - 4-DVD set
Rick Beaver
Ranch Hand

Joined: Dec 14, 2004
Posts: 464
Hi Paul

Thanks for responding - I am modelling this on a theoretically flat planet so I am not taking into account any real-world variations etc. I am assuming a steady course at a constant speed for a fixed period of time. The stuff you mentioned is way over my head I just wanted to make a little boat gif move about on a JPanel

I think what I am looking for is something like "The square on the hypotenuse is equal to the sum of the squares of the other two sides" but based on only knowing the angle of the triangle and the length of the hypotenuse - yeah, I know, I should have listened in class
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11480
    
  16

it's been a while, but you want the sine and the cosine of the angle. asuming 0 is due north, and you go around clockwise, the sine(angle) * speed will give you the horizontal speed, and the cosine(angle) * speed will give you the vertical.

i think...

[edit] using your notation:

HorizontalSpeed = sine(b) * S

VerticalSpeed = cosine(b) * S
[ December 22, 2005: Message edited by: fred rosenberger ]

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
If you're working on a flat plain (not the real earth) you might need to convert to polar coordinates to move and then back to cartesian. The math is over my head (music major) but I managed to use the constructs my dad gave me (math prof) to do some neat 3D motion stuff in Pascal in a former life.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Rick Beaver
Ranch Hand

Joined: Dec 14, 2004
Posts: 464
I think that was it Fred - thanks.

If my boat is on a bearing of 30 degrees and travels 10 metres per second

(sine 30) * 10 = 5 metres East
(cosine 30) * 10 = 8.66 metres North

That seems just about perfect to me.

Follow on question - why does 30 sin on a calculator give me 0.5 (correct) but Math.sin(30) gives me -0.9880316240928618 (wrong)

I appreciate all the help Thanks again
Sachin Satija
Greenhorn

Joined: Aug 24, 2005
Posts: 28
Originally posted by Rick Beaver:
I think that was it Fred - thanks.
Follow on question - why does 30 sin on a calculator give me 0.5 (correct) but Math.sin(30) gives me -0.9880316240928618 (wrong)

I appreciate all the help Thanks again


Beacuse the sine function in math class takes radians as parameters. But you can use Math.sin(Math.toRadians(30)) to achieve the same.

Sachin


SCJP1.4--91%<br />IBM 399
Rick Beaver
Ranch Hand

Joined: Dec 14, 2004
Posts: 464
You lot are brilliant - thanks.

This has to be one of the smartest communities on the net. I feel my inferiority complex kicking in
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11480
    
  16

glad i could help.
 
wood burning stoves
 
subject: Math help