How to animate a Rectangle on a Path2D in a Graphics2D context

I just started learning the basics of the Graphics2D class. For now, I can draw different objects and implement them ActionListenerto actually move them to the screen onKeyPress. So far so good, although I was thinking about making something more complicated. I want to pass the path to my object and animate it only along this particular path.

Something like that, I will draw a line in the sky, and the plane should adhere to this drawn line and keep it alone on this particular line. Is it now possible?

I don’t need any code, but a few different methods or ideas will allow me to start working on this. Visualize my idea as shown below.

Starting point:

enter image description here

End point:

enter image description here

, , ( ) ( )

, java, Path2D GeneralPath. - , .

+5
4

!

. , .:)

. , api , , :

y = f (x ) 

:

0 , 1 . (t) (, 0.001 ).

, :

x = xstart + (xend-xstart) * t
y = ystart + (yend-ystart) * t

t , , . , - , , (t ^ 2 t)...

,  Stephane

+2

-, a b. .

-, . , , .

.

+1

, 2D- . , , Java Java 2D Sprites Java 3D OpenSource Java 3D.org. , , 2D 3D.

+1

- LANSim. "". , .

+1
source

All Articles