Sign in to follow this  
maxxx

how to make a circle spin ?

Recommended Posts

hi
i want to turn a circle around it's own center like a ball or car tire

so i got a 2d vector class for my object(circle) position
and i draw a circle using that


[code]Ellipse(backbufferDC,(int)objectpos.x-25 ,
(int)objectpos.y-25 ,
(int)objectpos.x+25 ,
(int)objectpos.y+25);[/code]
how can i spin my circle now ?

i've tried this :

[code]x = x*cosf(r) - y* sinf(r);
y = y*cosf(r) + x * sinf(r);[/code]

just made my circle to move around a circular path

Share this post


Link to post
Share on other sites
[quote name='maxxx' timestamp='1302986506' post='4799252']
hi
i want to turn a circle around it's own center like a ball or car tire

so i got a 2d vector class for my object(circle) position
and i draw a circle using that


[code]Ellipse(backbufferDC,(int)objectpos.x-25 ,
(int)objectpos.y-25 ,
(int)objectpos.x+25 ,
(int)objectpos.y+25);[/code]
how can i spin my circle now ?

i've tried this :

[code]x = x*cosf(r) - y* sinf(r);
y = y*cosf(r) + x * sinf(r);[/code]

just made my circle to move around a circular path
[/quote]

The function you use to draw circles can't handle rotations on its own and rotating a circle doesn't make much sense (it would look the same regardless of how its rotated).

If you tell us what API you are using we might be able to tell you how to rotate other things.

Share this post


Link to post
Share on other sites
im using win32 api
and there is going to be a line in the circle to show the rotation (i can't draw this line from the center of circle )
i know it doesn't make much sense but it's a project for school so ...

Share this post


Link to post
Share on other sites
Can you just draw the circle and then rotate one endpoint of the line? That is, one end point is the center point of the circle, the other end point is the point (circle_x, circle_y + radius), which you then rotate?

Share this post


Link to post
Share on other sites
actually our teacher said we shouldn't do that cuz that way we can spin the line instead of circle

the line should be in the random place inside of circle so we can tell whether our circle is spinning around its center or not

Share this post


Link to post
Share on other sites
It's impossible to rotate a circle - at least in computer graphics terms where a circle is defined by its center-point and a radius. I would do the following: store your circle-with-a-line-in-it as a class, give it two vectors as members, one for its center-point and one to represent its orientation. Then when you draw this construct you draw the circle (without rotation of any kind, that doesn't make sense - use the construct's center-point vector member as the origin of the circle obviously) and then you determine a line from the center of your circle out into the direction the whole thing is pointing (using the second member vector, the orientation) and just draw a segment (a part) of that line.

[img]http://i8.photobucket.com/albums/a7/dkh2/delme.png[/img]
This is what you would get, the small red line is your orientation member vector which would not be drawn, instead the small thick black segment of it is drawn.

Hope this makes sense and helps.

Share this post


Link to post
Share on other sites
[quote name='dublindan' timestamp='1303012984' post='4799365']
like i said i can't draw the line from the center point of circle
[/quote]

As many have already said, it is impossible to see the visual effect of a rotating plain uniform circle and since you cannot draw a line from center point of circle, why don't you try drawing a few lines that are perpendicular to any radial line inside the circle? That would make the rotation more obvious.

Share this post


Link to post
Share on other sites
1. Implicit form
( x - x[sub]0[/sub] )[sup]2[/sup] + ( y - y[sub]0[/sub] )[sup]2[/sup] - R[sup]2[/sup] == 0
Each pair {x,y} that fulfills the above equation is a point on the circle centered at (x[sub]0[/sub],y[sub]0[/sub]) and with radius R. AFAIK no rotation can be expressed within.

2. Parametric form
{ x = R cos( 2pi*t+p ), y = R sin( 2pi*t+p ) } w/ t in [0,1]
where a rotation in the given space can be expressed by varying the phase p.

3. Any form is given in a space, and the space can be rotated with the circle within and with respect to the reference space.

4. The (combined) visual representation of circle and line (i.e. a bitmap) can be rotated, what could be understood as a special case of 3. (kind of rotating in "pixel space").

However, as is written several times above, the visual representation will not change besides artifacts due to sampling. Demanding that the indicator line should not be rotated by itself because it would not be a proof that the circle rotates is senseless, because line and circle are 2 distinct objects anyway. That said, what sense does it make to rotate the circle in that way? Is the exercise correctly understood?

Share this post


Link to post
Share on other sites
maxxx, could you give us as much information as possible? In particular, what are you studying (you say it's a project for school. Is it high school or college? what is the subject about and what have you already seen?), and the exact the text of the assignment. with as much context information as we could need. As you have put it it doesn't seems to make much sense, so probably there's some misundestanding around there :)

[b]Edit:[/b] Hmmm, if you are using, as it seems, the Windows [url="http://msdn.microsoft.com/en-us/library/dd162510%28v=vs.85%29.aspx"]Ellipse()[/url] function, you probably should draw a circle and a line into a DC and then apply the rotation with [url="http://msdn.microsoft.com/en-us/library/dd145104%28v=vs.85%29.aspx"]SetWorldTransform[/url] function.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this