Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Tex-Twil

macrumors 68030
Original poster
May 28, 2008
2,501
15
Berlin
Hi,
I have a UIImageView representing the level of the "artificial horizon" in a plane. Blue is the sky, brown is the ground. This image is actually clipped by its super view which creates the square.

Screen%20Shot%202011-07-27%20at%207.29.38%20PM.png


When I I move the nose of the plane up, I move the image down:

Screen%20Shot%202011-07-27%20at%207.31.39%20PM.png


When I move the nose of the plane down, I move the picture up :

Screen%20Shot%202011-07-27%20at%207.33.36%20PM.png


This is called the "pitch"

So far I've been modifying only the x axis of the image:

Code:
imageHorizon.center = CGPointMake(imageHorizon.center.x, imageHorizon.center.y + valueToMove);

When I "roll" the plane I rotate the picture either to the left or right:

Screen%20Shot%202011-07-27%20at%207.36.15%20PM.png

Code:
imageHorizon.transform = CGAffineTransformRotate(imageHorizon.transform, angleToRotate*(CGFloat)(M_PI/180));


Now, the problem is that once I rotated the picture and want to modify the "pitch", I dont know which formula to use to find the correct x,y to move the picture towards the sky or ground direction:

Screen%20Shot%202011-07-27%20at%207.42.17%20PM%20copy.png


In other words, when I rotate the picture with an angle β, what are the x, y value to add to the center of the image to move it on the red line ?

thanks for your help,
Tex
 
Last edited:

Tex-Twil

macrumors 68030
Original poster
May 28, 2008
2,501
15
Berlin
Maybe this will help : http://forum.onlineconversion.com/showthread.php?t=5408

I KNOW I have seen a much better tutorial on this, but I can't find it anymore, sorry.
ok I will have a look but it seems quite complex. I thought that using simple trigonometry should work:

Screen%20Shot%202011-07-27%20at%207.42.17%20PM%20copy.png


cos(α) = x /h
sin(α) = y / h


so
x = h * cos(α)
y = h * sin(α)

but anyway in my code it's not working :( The image is not moving to the right direction:

Code:
// derive from beta and convert to radians
CGFloat alpha = (90 - beta)  * (CGFloat) (M_PI/ 180);
CGFloat moveX = distanceToMove * cos(alpha);
CGFloat moveY = distanceToMove * sin(alpha);
imageHorizon.center = CGPointMake(imageHorizon.center.x + moveX, imageHorizon.center.y + moveY);
 
Last edited:

Sykte

macrumors regular
Aug 26, 2010
223
0
If I'm not mistaken you want to keep it in degrees and not radians. Then + or - your current location.
 
Last edited:

Tex-Twil

macrumors 68030
Original poster
May 28, 2008
2,501
15
Berlin
I got it working with a much easier solution. I put the image in a UIView. I apply the rotation to this view. Then I apply the pitch to the image (which is subview of the "roll" view. Since it is a subview, the coordinates are relative to the superview meaning that I have to simply add or subtract a value the Y coordinate ;)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.