Sign in to follow this  

A simple Circle Question

This topic is 2831 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've got another simple question that has to do with circles (the last question I had was answered quickly and in a way I could understand it, I was quiet impressed). After doing some research I found out how to find points on a circle if I know the center and the Radius, using x = r * cos( theta ) + j y = r * sin( theta ) + k with j,k being the center. I've also found out how to find a point in a circle that is closest to another given point. But what I can't find is how to tell what theta a point of a circle is on. Let me explain what I need to do. I have a ship that needs to move a given distance from its enemy (to keep out of weapon range), the circle represents all points on that given distance. Using the formula I can find the closest point (call it point A), 99% of the time that is all I'll need. But if that points fall outside the boundary of my map (x,y < 0 or x,y >= count(map)) I need to find the closest point from point A that is on my map. To do this I want to find the theta of point A, and iterate left and right from that point until I find the first point that is on the map and move the ship there. To make it clear I've never taken trig., I will someday, so if its a simple answer I don't know it, if its impossible to find them I am sorry for asking, but I can't find anything on Google, though I could be using the wrong phrase. Thanks for any future answers.

Share this post


Link to post
Share on other sites
if i do understand you right this is what i am getting: you have a ship at t0 position is valid. And you have the same ship at t1 at an invalid position. lets asume the map is a quad (or the bounds of the monitor) cast a ray from position0 to position1 and test the intersection with the appropriate intersection test.

Share this post


Link to post
Share on other sites
atan2(y, x) will give you the angle (in radians) from the +X axis of the point (x, y)

atan2 is the arc-tangent function that takes y and x as separate parameters, instead in a ratio like normal atan. This is useful because it will return the proper angle even in quadrant III, where both x and y are negative, whereas doing atan(y/x) will return the quadrant I angle since the ratio will be positive.

This works because tan() gives you slope of the line at a certain angle from the X axis. Therefore, if we have the slope, we simply use atan() (the inverse, arc tan) to find the angle.

Share this post


Link to post
Share on other sites

This topic is 2831 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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