Thread: is this formula correct ?

1. is this formula correct ?

Hi,
I'm a develepper and I need help with basic trigonometry.

In my application I have a image representing the level of the "artificial horizon" in a plane. Blue is the sky, brown is the ground.

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

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

This is called the "pitch"

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

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

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:

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 ?

I thought that using simple trigonometry should work:

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

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

then simply add the x and y to the current coordinates of the image. The resulting behaviour in my application is not correct though

Is this a correct formula to use ?

thanks,
Tex

2. Re: is this formula correct ?

Originally Posted by TexTwil
Hi,
I'm a develepper and I need help with basic trigonometry.

In my application I have a image representing the level of the "artificial horizon" in a plane. Blue is the sky, brown is the ground.

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

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

This is called the "pitch"

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

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

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:

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 ?

I thought that using simple trigonometry should work:

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

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

then simply add the x and y to the current coordinates of the image. The resulting behaviour in my application is not correct though

Is this a correct formula to use ?

thanks,
Tex
simply adding them with the current coordinates won't work. you have to make sure that u have added them with correct sign. for example the x=h*cos(a) would be added with a negative sign while the y=h*sin(a) would be added with a positive sign.

3. Re: is this formula correct ?

Originally Posted by abhishekkgp
simply adding them with the current coordinates won't work. you have to make sure that u have added them with correct sign. for example the x=h*cos(a) would be added with a negative sign while the y=h*sin(a) would be added with a positive sign.
you mean :

if I'm in 0, $\pi$/2
imageX = imageX + h * cos(α)
imageY = imageY + h * sin(α)

if I'm in $\pi$/2, $\pi$
imageX = imageX - h * cos(α)
imageY = imageY + h * sin(α)

if I'm in $\pi$, 3 $\pi$/2
imageX = imageX - h * cos(α)
imageY = imageY - h * sin(α)

if I'm in 3 $\pi$/2, 0
imageX = imageX + h * cos(α)
imageY = imageY - h * sin(α)

?

4. Re: is this formula correct ?

It's "almost" working but there is still something wrong as you can see on the following video: in the beginning it behaves correctly but the image does not ends up on the same position where it started

I wonder if I shall rotate the image all the time around the center of the screen instead of rotating it around its center (which moves when I apply the pitch)