Determining Orbit Location

Cd577ee1cb56aa2ad5645b7daa0a2830
0
eddie 101 Dec 17, 2009 at 19:31

Hello!

A bit of a math question here, hopefully someone finds this interesting, or better yet, a possible solution. :)

I’ve drawn this up on a diagram, but I’ll explain it here for further illustration.

I’ve got a camera that orbits around a point. It has a set radius away from it’s orbit point, and an object it ‘looks at’.

Here’s where things start to get interesting. The object it’s looking at can have a target, somewhere else in the world. I’d like to constrain the camera to orbit such that it keeps a set number of degrees between the target and the object it’s looking at.

Is there any mathematical way of getting the precise location(s) of the new camera resting point? Ideally one that isn’t too computationally expensive, and ideally one I can understand? :)

Here’s a diagram where I’ve tried to illustrate the issues, as well as the knowns and unknowns.

targetproblem.jpg

After doing some research, I’m thinking I can solve this using a combination of cosine law and tan law, substituting when necessary, but I’m not entirely confident and it’ll take a while to build the equations and plug it in. In the meantime, I’d love to have other people’s opinions or ideas.

Cheers,

-e-

8 Replies

Please log in or register to post a reply.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Dec 17, 2009 at 22:48

An intriguing if rather bizarre problem. :wacko: So, to rephrase, you have a predetermined orbit center (C) and radius (cd) and you want to find the possible camera location(s) such that the line segment AB subtends a predetermined angle from the camera’s point of view?

Assuming I’ve correctly understood your problem, I don’t have a full solution, but here’s another way of looking at it. You have two constraints (camera’s radius from C and the angle between A and :). You can thus think of the point you want to find as the intersection of two curves. One curve would be a circle around C of radius cd, i.e. all the points that satisfy the radius constraint. The second curve would be all the points that satisfy the angle constraint. The shape of this second curve isn’t obvious; a quick sketch suggests it’s kind of like a cardioid, but with two cusps, one each at A and B. But perhaps with a bit of work you can find the equation of this curve, and then algebraically intersect it with the circle.

EDIT: One way to construct the latter curve might be as follows: imagine two lines, one through A and one through B; the absolute angles of the two lines differ by the desired AB angle. Their intersection point is thus one point on the curve we wish to find. As you rotate the two lines around their respective points, in lockstep so that their relative angle remains constant, their intersection point should sweep out that double-cardioid curve.

Cd577ee1cb56aa2ad5645b7daa0a2830
0
eddie 101 Dec 17, 2009 at 22:53

I seem to always concoct bizarre problems. :)

Reebeta, you always amaze me with what you know.

Now, I have to admit that math isn’t my strongest suit. Can you offer me some pointers in how I go about discovering the equation of the curve? Tutorials, web links, anything would be appreciated.

-e-

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Dec 17, 2009 at 22:58

I edited my post after you replied and added an idea about how to construct the curve. You might try constructing equations for the two lines and algebraically intersecting them to get to the curve. If I have a chance later maybe I’ll poke at it some more. It would be nice to get down to a closed form solution. :wacko:

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Dec 18, 2009 at 06:49

Well, the curve turned out to be really simple! After doing a page of algebra, I rediscovered the inscribed angle law. :wacko: Basically, you can think of AB as a chord of two circles (one on each side of the line); then the external parts of the circles are the desired curve along which the angle between A and B is a constant. These circles have a radius of 0.5 * (distance ab) / sin(angle AB) and are located above and below the midpoint of AB at a distance of 0.5 * (distance ab) / tan(angle AB). I’ll try to post a diagram in a bit to be clearer about what I’m talking about, but pretty much finding the camera position comes down to finding intersection points of a couple circles, which is a relatively easy geometry problem. :)

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Dec 18, 2009 at 07:26

Here’s a diagram of what I mean:

devmasterproblem.th.png

The left side shows the construction of the two circles based on A and B, and the desired angle theta_AB. The right shows intersecting that with the camera circle around C to get the two possible solution points. Depending on the relative size and position of the camera circle it’s possible to have as many as four solution points.

Fd80f81596aa1cf809ceb1c2077e190b
0
rouncer 103 Dec 18, 2009 at 07:41

its good your thinking about adding a decent camera to your game, which isnt necessarily always implemented.
Itll definitely add play value.

Cd577ee1cb56aa2ad5645b7daa0a2830
0
eddie 101 Dec 18, 2009 at 17:00

Reedbeta:

Awesome, thanks so much for putting that talented cranium to work for me.

That’s fascinating - I didn’t know of the inscribed angle law. That totally was the keystone for this problem.

In the interests of me not having to ask the same questions at a later date, would you mind if I paraphrase my understanding of this, and hopefully if you could correct me where my assertions are incorrect? It would help me solidify this in my head.

As I understand it, you’re building a circle that inscribes an angle of theta_AB and reaches out to two points that are |AB| apart.

You can then find the ‘height’ from the mid point of the |AB| chord to the inner point of the circle using simple tan = opposite/adjacent, solving for the ‘adjacent’, and the radius using a similar sin = opposite/hypotenuse, solving for hypotenuse.

Man, writing that down even makes me think of it clearer. I hope I’m not wrong in my paraphrasing, as that sounds more and more correct.

After that, you’re right - treating the original orbit as simply a circle that intersects with this larger circle should make solving this solution much simpler. Off the top of my head I don’t remember calculating circle intersections, but I remember doing it in junior high, so I can’t imagine it’ll be too hard to scrape the rust off the noggin.

Thanks again Reed! Please let me know if I’ve thought of any of this incorrectly.

Cheers!

-e-

P.S. If you don’t mind, how did you end up drawing such good math diagrams? Mine was just a botched MS Paint job, yours looks much better. :)

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Dec 18, 2009 at 17:34

Sounds like you’ve got it. :yes: I actually used MS Word to make the math diagrams and took a screen shot, LOL. It has a pretty decent vector art system built in - not as powerful as Adobe Illustrator or what-have-you, but also much easier to use. I also used the MS Equation Editor for the equations.