Physics in java

i dont understand how you are supposed to implement physics into a java program. for instance, i want to simulate someone jumping in a program and can come up with a quadratic equation based on time, but then I realized i dont know how to use time in a java program. so i decided to use a for loop that has a Thread.sleep() call at the end (not sure if this is a reasonable method) but now have a problem because most of the path includes fractional x/y coordinates and the image goes blank as i assume it doesnt know how to deal with fractional coordinates. How do I get by this?

[587 byte] By [JimStonea] at [2007-10-2 21:42:24]
# 1

> i dont understand how you are supposed to implement

> physics into a java program. for instance, i want to

> simulate someone jumping in a program and can come up

> with a quadratic equation based on time

One equation? Last time I looked, you needed one equation for each space component. So there are two for 2D space and three for 3D space. You have three components of an acceleration vector, which you integrate in time to get velocity, which you integrate in time to get position.

It's more complex than your "quadratic equation in time".

> but then I realized i dont know how to use time in a java program.

Wouldn't time just be another variable name? There's CPU clock time and the time in your solution - two very different things.

> so i decided to use a for loop that has a

> Thread.sleep() call at the end (not sure if this is a

> reasonable method)

I don't believe it is.

> but now have a problem because

> most of the path includes fractional x/y coordinates

> and the image goes blank as i assume it doesnt know

> how to deal with fractional coordinates. How do I get

> by this?

You learn some more about physics and numerical methods for starters. You also need to learn something about computer graphics, because you also need to learn how to transform coordinates in solution space to those in screen space. It's far more complex than you're making it out to be.

%

duffymoa at 2007-7-14 0:57:40 > top of Java-index,Java Essentials,Java Programming...
# 2
you can use Date, Calendar instead of Time
angeles1016a at 2007-7-14 0:57:40 > top of Java-index,Java Essentials,Java Programming...
# 3
To fix the decimal coordinates, do something like this:double x = 3.66;double y = 4.78;g.fillRect((int)x, (int)y, 50, 50);
CaptainMorgan08a at 2007-7-14 0:57:40 > top of Java-index,Java Essentials,Java Programming...
# 4
ok, well I see I have a lot to learn.. can anyone recommend any good websites/books on the subject?
JimStonea at 2007-7-14 0:57:40 > top of Java-index,Java Essentials,Java Programming...
# 5

> > i dont understand how you are supposed to

> implement

> > physics into a java program. for instance, i want

> to

> > simulate someone jumping in a program and can come

> up

> > with a quadratic equation based on time

>

> One equation? Last time I looked, you needed one

> equation for each space component. So there are two

> for 2D space and three for 3D space. You have three

> components of an acceleration vector, which you

> integrate in time to get velocity, which you

> integrate in time to get position.

>

That's still one equation, albeit an equation in multiple dimensions using vector math.

> > so i decided to use a for loop that has a

> > Thread.sleep() call at the end (not sure if this is

> a

> > reasonable method)

>

> I don't believe it is.

>

It isn't. Thread.sleep() isn't going to give you any degree of precision (and that's just one of the drawbacks).

jwentinga at 2007-7-14 0:57:40 > top of Java-index,Java Essentials,Java Programming...
# 6
> ok, well I see I have a lot to learn.. can anyone> recommend any good websites/books on the subject?Physics for Game Developers, published by O'Reilly, is a good resource.Code is in C++ but can be ported to Java if you know both languages a bit.
jwentinga at 2007-7-14 0:57:40 > top of Java-index,Java Essentials,Java Programming...