wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Circular motion....... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Circular motion......." Watch "Circular motion......." New topic
Author

Circular motion.......

sachin upatil
Greenhorn

Joined: May 17, 2010
Posts: 29
HI,

i want to animate a circle in circular motion. circle will rotate in circular motion at fixed point.

How should i do this?
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

http://download.oracle.com/docs/cd/E17409_01/javase/tutorial/2d/index.html
http://download.oracle.com/docs/cd/E17409_01/javase/tutorial/uiswing/painting/index.html

And if that doesn't help, go through http://catb.org/~esr/faqs/smart-questions.html


luck, db
There are no new questions, but there may be new answers.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> i want to...

so, what can't you do?
Petar Thomas
Ranch Hand

Joined: Oct 11, 2009
Posts: 234
How fast?

You need mathemathics, trigonometry, geometry...
sachin upatil
Greenhorn

Joined: May 17, 2010
Posts: 29
Now i able to rotate a line(radius) within circle using sin and cos formula.
But unable to rotate a circle in circular motion.
what should i try for this circular motion?
Petar Thomas
Ranch Hand

Joined: Oct 11, 2009
Posts: 234
I don't really have enough knowledge for this now... but,
I will, then, today, learn 2d,
and You can post Your code, if You can...

Then, maybe someone will help You,
or I will jump in.(probably)
sachin upatil
Greenhorn

Joined: May 17, 2010
Posts: 29
Here is my code. Fa and Fb is rotating inside circle.

Now i want to rotate circle in circular motion at fixed point.
How i will get this?
Give direction.


Petar Thomas
Ranch Hand

Joined: Oct 11, 2009
Posts: 234
MMM... I can't work with Applet, I don't know nothing about it. And, I need a bit time to turn it to JFrame, and something useful to me, becaouse I never used 2d before and paint(), but...

but...

(I may be wrong , becouse I didn't test anything ..)

but,

circleR = new Ellipse2D.Float(400, 100, 200, 200);

You see, this here... there are parameters that never change... 400,100,200,200...

while here:

int X = (int)(500 + (100) * java.lang.Math.cos(-degrees));
int Y = (int)(200 + (100) * java.lang.Math.sin(-degrees));

int X1 = (int)(500 + (100) * java.lang.Math.cos(degrees));
int Y1 = (int)(200 + (100) * java.lang.Math.sin(degrees));

You see, parameter depends on the 'degrees'.

'degrees' changes.... and from the 'degrees' the x,y and x1,y1 are calculated

(Which is radius here, what is this...) Anyway, I don't understand this at first look. Why is one 500 and one 200 , and what is 100? I'm totally blind. Ahhaaa... this is offset, 500 and 200, and 100 is a radius...

How this works?

angle is turned into degrees... (aha, this is Thread, hm.. )

and repaint calls paint...


So 500,200 is the center, 100 is the radius..

Do You want two circles?


Try like this:



This should work, maybe.....

Did You wrote this program alone or did You copied it? Do You understand how it works? I didn't tested anything. Maybe it even doesn't work. But do You understand how angle is changeing, and how degree is calculated from angle every time repaint() is called?
sachin upatil
Greenhorn

Joined: May 17, 2010
Posts: 29
petar,

Yes, i write this program. Fa and Fb are lines which are moving in clockwise and anticlockwise direction.
(500,200) is starting point for line which is fixed and center point for circle.

Because of angle each time we are getting value of (X,Y),(X1,Y1). And Fa and Fb line is rotating.

Now i want to rotate same circle in circular motion.
Petar Thomas
Ranch Hand

Joined: Oct 11, 2009
Posts: 234
Ahhhaaaaaa... now I understand.... Ockay, I think I kinow how... I just go to drink water, think, and then I'll write a reply... It's easy.. I'll be back in few minutes..
Petar Thomas
Ranch Hand

Joined: Oct 11, 2009
Posts: 234
So...

The center of that circle is (500,200).... That is a center of the rotation.... And now, the center should rotate.......

If the center should rotate, then there should be another center

..one more center... for this center to rotate around... ( ?? : ) )


..and... it should be calculated as well, like this lines, actuallz, exactelly on the same way...

...but ... the angle of the whole rotation doesnt have to be the same angle of the line rotation...

I don't know if You agree or disagree...

ockay... lets say there is two angles.... 'angle' for lines, and ... 'angleR' for rotation..






...and...



... and...



I suppose now it works.....

mmm..

500,200 are now the center of the rotation... and 100 is the radius.. on which travels the center of line rotation...

That is visible in this part...



(maybe 500,200, and 100 should be in some variables)

and this XR,YR is now used in other formula in place where there used to be a static center of rotation 500,200



..now the center of the rotation is not static any more... the center is rotating....XR,YR is rotating around 500,200 at radius 100...


Here... I hope it helped... : )
I hope it works...




Petar Thomas
Ranch Hand

Joined: Oct 11, 2009
Posts: 234
No! It doesn't....

This part I did wrong:



Here, it is needed XR,YR as the begining of the line ..now...



Now it works, probably..
Petar Thomas
Ranch Hand

Joined: Oct 11, 2009
Posts: 234
sachin upatil
Greenhorn

Joined: May 17, 2010
Posts: 29
Petar,

I want circular motion like thiswebpage
Petar Thomas
Ranch Hand

Joined: Oct 11, 2009
Posts: 234
Beauty is in the eye of the beholder.

Please, explain better.



(Do You want #exactely# as like it is on the picture on that web page?)





Is this maybe what You want? Is it working?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
probably 90+% of the code required you downloaded in your JDK

go to your progamFiles (or wherever your JDK lives):

progamFiles/java/jdk/demo/applets/clock

double-click the html file and you have an analog clock
just change the timer from 1000 (1 sec) to about 250 (experiment),
and you should get the same perpetual motion effect
sachin upatil
Greenhorn

Joined: May 17, 2010
Posts: 29
Petar,

Thank you.

But i am trying to rotate circumference of circle. It's like a fixed wheel at center which is rotating.

-sachin
Petar Thomas
Ranch Hand

Joined: Oct 11, 2009
Posts: 234
Sachin,

But rotating a circumference of a circle is to me personaly a strange idea... If in the imagination the circumference is an endlessly thin line, in which there are endless count of dots, I don't know how to make that - it rotates... But maybe someone who studied mathemathics on the university knows if that its possible.

In practice, there would be two versions of it, as I think now:
One version is just a circle on the screen that doesn't move at all... with an explanation that "it is rotating so we don't see it"... becaouse as circle rotates, but it is on the same place... the dots on the screen are always the same....

The second version ... is the visual effect... that looks like a rotating circle...

Maybe I'm wrong somehow.

I'm sorry that I could'n help You, I tried...

Bye,

Petar

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38075
    
  22
The bit about "rotating" is loose terminology. It means to have a point which rotates, following a circle.
Petar Thomas
Ranch Hand

Joined: Oct 11, 2009
Posts: 234
Hi,

To me, next thing is obviouse: If I have one dot rotating 10 degrees per step, I would do it so to calculate in advance those 36 locations of each 10 degree step, and those locations doesn't change, so, if I would have a dot rotating in 1 degree step, 360 steps, then I would have precalculated 360 locations, for one dot, but, also, if I would have 360 dots, that would use those 360 precalculated positions, then, when one dot moves, the other steps in, on the same position... and so, 360 dots, move to the the next position, which is in the same time the previous position of the next dot that moved as well... Or in another words, if in the circumference of the circle, with all dots rotating, one dot also rotating is in one moment at 45 degrees, and that same dot will be in the other moment at 120 degrees, as the whole circle rotated for 75 degrees, so that dot will be on the same place of the dot which was at 120 degrees when this dot was at 45, and this is with all the dots as well. Every dot travels the same path like any other dot, when one dot moves away, another slips in, on the same place, and that's how for all the dots in the circle. Let's say like this, every frame of an animation would look the same like a previous frame or any other frame. The only way to do it, by my opinion is to make a visual effect. For example, I am not enough experienced, but if Java 2d uses antialiasing, then it is possible that "one dot", created by drawLine(x, y, 1, 1) or drawRect(x, y, 1, 1) or fillRect(x, y, 1, 1) , maybe it is possible that one dot would "cover" more pixels in different colors, and even on this way it would still be a nice static circle... Maybe it is possible to draw a "two positions" of a wheel rotating, where every even positon looks the same, and every odd position looks the same, and maybe even it makes a kind of a moving effect, but maybe it would look only like click-clack left-right.. Maybe then it would be better to have more than two positions which are repeated. But then, actually, I think, there should be left empty space for dots to travel, so that wheel would look like zebra maybe. Maybe then, those empty dots in between should be in lighter color, to fill the emptines till the full line. Other way would be to create a "bump" on a circumference of a circle, a dirt, like on a tire of a car.. you know how tire of a car looks to an eye, there are variouse visual illusions there... At the end, if you have a perfect circle perfectly rotating, or dots rotating, rotation is invisible.

For example, look at this smiley:


There is no problem in rotating one dot, or ten dots, but when there is enough dots to form unbreaked line of a circumference of a circle, then ... it's a circle. And, mathematically, all the dot's on the screen have to be calculated, as those dots belong to the circle, dots them selfs, their positions, are not moving any more... The circumference is not moving. So, if you have a full unbreaked line of circumference of the circle, made out od dots, those dots are also, always the same dots...

Like, for example, "theatre of the shadows", when one shadow is moved, and other moved exactely on the same place, that's how it can be created an illusion that nothing has moved at all.

sachin upatil
Greenhorn

Joined: May 17, 2010
Posts: 29
HI Petar,

Thank you.

i did it.

in java we have Graphics2d.ROTATE method.

Using this method we can rotate a circle.

-sachin
Petar Thomas
Ranch Hand

Joined: Oct 11, 2009
Posts: 234
Sachin,

I am very glad.
Thank You to You too, I was learning like this also.

Petar
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38075
    
  22
Beware of the rotate method; it uses an affine transform which requires a lot of floating-point arithmetic, and causes imprecision in location of the Graphics object. It is better if you use the method which copies a Graphics object (I think it is called Graphics#create()) and apply all the Affine Transforms to the copy.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Circular motion.......
 
Similar Threads
Security Forum?
WA #1.....word association
big book o science
image transperancy
Got 18 seconds?