views:

119

answers:

4

Hi all,

I am using a 3rd-party "rotator" object, which is providing a smooth, random rotation along the surface of a sphere. The rotator is used to control a camera (see rotator.h/c in source code for xscreensaver).

The output of the rotator is latitude and longitude. What I want is for the camera to stay above the "equator" - thus limited to a hemisphere.

I'd rather not modify the rotator itself. So I could take the latitude output and use the absolute value of it. However, smooth rotator movement across the equator would not produce smooth camera motion: it would bounce.

I suppose I could scale output latitude from the rotator from its current range to my target range: e.g. f(lat) = (lat+1)/2 would map the (0, 1) range to (0.5, 1). I.e. map the whole "globe" to the northern hemisphere. The movement would still be smooth. But what would be intended as the "south pole" by the rotator would become the "equator" for my camera. Wouldn't that result in strange motion? Maybe discontinuities? I'm not sure.

Is there another way to map a sphere (latitude and longitude) to a hemisphere, smoothly?

Update:

Thanks for your attention and responses. A couple of people have asked for clarification on "smooth". I mean not jerky: a small change in velocity of the rotator should be mapped to a small change in velocity of the camera. If I just took the absolute value of the latitude, a zero change in velocity of the rotator as it crossed the equator would translate to an abrupt sign-flip of the velocity of the camera (a.k.a. a bounce).

IIRC this is equivalent to requiring that the first derivative of the velocity be continuous. Continuous second derivative might be nice but I don't think it's essential.

+1  A: 

A sphere and a hemisphere are topologically different, therefore there is no way to smoothly map between the two in a manner that would satisfy your criteria.

Ignacio Vazquez-Abrams
Nooooo! (-1) - A sphere and a hemisphere are topologically equivalent.
Kragen
Ugg, my bad - they aren't topologically equivalent, (sorry)
Kragen
@Ignacio - sorry, but have to disagree with you. To my understanding, the OP's criteria does not require a 1:1 mapping of the latitude derivative, so a smooth mapping does exist, as suggested by tom10 and myself.
ysap
@ysap, @Ignacio: correct, a 1:1 mapping of the derivative is not required, justa smooth mapping.
LarsH
+1  A: 

Instead of the absolute value of the latitude you could do something smooth, like (latitiude)2.

tom10
Good suggestion... why didn't I think of something that simple. :-)
LarsH
A: 

I'm not entirely certain I understand your question, so I'll re-state it just in case:

You want to be able to convert any point (given by latitude and longitude) and convert that to a point on a hemisphere so that "movement is smooth" (i.e. a small movement on the sphere translates to a small movement on the hemisphere)

In this case I believe that you can simply "fold the sphere in back on itself" (e.g. take the Modulo of the latitude about the equator).

Kragen
But this is exactly what the OP is trying to avoid. Imagine crossing the equator at a constant speed from the north side to the south side. In the "mirrored" transform, you will have an sudden change of the velocity from negative to positive, maintaining the speed size. This will cause the "bouncing" effect the OP mentiones.
ysap
@Kragen, sorry, I thought "movement is smooth" was clear but I'll edit my question to clarify. It is not just that a small movement translates to a small movement, but that a small dv (change in velocity) translates to a small dv.
LarsH
+3  A: 

The velocity is the derivative of the position. By just "mirroring" the lat value, you create a "corner" in the position function when hitting the equator. So, in order to get a smooth transition, you need to map the linear position (i.e, the latitude as a function of the time) to a function that changes slowly near the equator, and where the 1st derivative is 0 at the equator.

tom10's suggestion for mapping lat'(lat) = (lat)^2 is a good example of such a function. However, you need to normalize the result so you get lat'(90deg) = 90deg. So, the correct mapping should be:

lat'(lat) = 90*(lat/90)^2

An alternative to a parabole is a sin() function, with the appropriate shifting and normalizing. Depending on how much you want the velocity to be close to the original velocity when "away" from the equator, you can have higher or lower order exponent values, like:

lat'(lat) = 90*( |lat| / 90)^K

ysap
Thanks! I will try both n^2 and sin suggestions.
LarsH