Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: Calculating a point around a circle  (Read 1120 times)

0 Members and 1 Guest are viewing this topic.
Calculating a point around a circle
« on: March 16, 2007, 07:29:05 pm »
  • [sic]
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 2334
If I have the bottom half of a semicircle, and know the x value of a point, how would I calculate the y value so that the point rests directly on the edge of the circle?
« Last Edit: March 16, 2007, 07:51:58 pm by Kame »
Logged
Re: Calculating a point around a circle
« Reply #1 on: March 16, 2007, 07:45:23 pm »
  • Fear my Blades
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 562
Basic functions for calculating points around a circle based on angle.  (r = radius of circle)
x=r*cos(a)
y=r*sin(a)


So first well take the function for finding x, based on angle, and invert it to find the angle based on x.
x=r*cos(a)

x/r=cos(a)

arccos(x/r)=a

Now stick that into the function for finding y as the value for angle.

y=r*sin(arccos(x/r))


The x, and y values you use should assume that the center of the circle is at 0, 0.  If not subtract the centers x from your x value before calculating, and add the centers y to the result.  You'll probably also have to make the result negative first.  It's been a while since I've actually used these calculations, so I apologize in advance if I got something wrong.
Logged

I've done it (sorta)!  Bloom Lighting in GameMaker, and 3D mode too!  Check out the awesome Screen Saver.
  • Kousou Games
Re: Calculating a point around a circle
« Reply #2 on: April 12, 2007, 10:40:07 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 53
It's much simpler than Atrius suggested (although it is a perfectly correct method)

The general equation of a circle on the origin(0,0) is
x^2 + y^2 = r^2 (Pythagorean Theorem)
Where r is the radius of the circle.

If you know x and r, you can find y by rearranging:

y = sqrt(r^2 - x^2)

Simple. Oh, but since the value for y comes out positive from this formula, you need to make it negative in order to be in the bottom semicircle. This should be easy in whatever programming language you are using.

e.g.

 y = sqrt(r^2 - x^2)
 y = -y


Oh, and if you need the appropriate equations for a circle that is not centered on the origin, it's

(x - a)^2 + (y - b)^2 = r^2  As Atrius said.

Therefore y = sqrt( r^2 - (x - a)^2 ) + b

I hope that helps.
« Last Edit: April 12, 2007, 10:45:32 pm by JamesRobinson59281 »
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.014 seconds with 40 queries.