Skip to main content
GameDev.net gamedev.net
🔒 Locked

A simple Circle Question

Started by Charles Leverett Mar 14, 2010 at 2:30 PM 1 replies 850+ views
Original Post
Charles Leverett
Charles Leverett
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.
flery
flery
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.
nullsquared
nullsquared
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.