Sign in to follow this  
Leo28C

Geometry and circles...

Recommended Posts

Hello everyone! Look at this pic: http://img215.imageshack.us/img215/3904/circleec0.jpg Given the position of the black dot, how can I get the position of the red dot (of course the red dot has to move around the circle)? Sorry, I didn't pay attention in geometry class... [headshake] Thanks!

Share this post


Link to post
Share on other sites
Position of the red dot should be:

Red x-pos = Black x-pos + circleradius * cos(angle)
Red y-pos = Black y-pos + circleradius * sin(angle)

Edit: If you want to draw a cicle, not just one dot, you're probably better off using the circle-equation: y = sqrt(r*r - x*x) and then use those values for the other quadrants too.

Share this post


Link to post
Share on other sites
Just for the sake of everyone that reads your post, here's the image inline:



This is going to be tough to explain if you don't have a strong geometry background, so I'll try to cover the main points and hide a few details. A circle has the following equation: (x - u)2 + (y - v)2 = r2. (u,v) is the center of the circle, r is the radius, and (x,y) is any point that satisfies the above equation (basically it's representative of all the points on the circle). If the origin is (0,0), you get the simplified x2 + y2 = r2. There exist two trigonometric functions, sine and cosine, which operate on angles. It just so happens that sin(t)2 + cos(t)2 = 1, where t is the angle. Multiply through by r2, and we get (r*sin(t))2 + (r*cos(t))2 = r2. This is the same formula as a circle, with x = r*cos(t) and y = r*sin(t). So to get the point on a circle, you pick an angle t and plug it into those two simple equations. If the center of the circle isn't (0,0), then just add the center to the result you get for x and y, i.e. (x,y) + (u,v). To get the point to appear as though it's rotating, just increment t over time. Keep in mind that t is in something known as radians, which is basically a way to describe how "far" you are along the circumference of the circle as a multiple of the radius. So t takes on real values that are usually very small (not the typical 0°-360° that you might have seen before). The point wraps around the circle when t is a multiple of 2*PI (so 0 to 2*PI is one rotation).

I'm sure other posters can fill in any details they think I left out. I know I do a lot of handwaving but that should get you off to a start at least.

Share this post


Link to post
Share on other sites
Oh, so that's what sin and cos are for. I've been asking myself that question since I first read that C++ tutorial about math.h, say, 2004? 2005?

Guess I'll take trigonometry class whenever I go to college and pay attention.

Anyway, yes, thanks you both! [grin]

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