# Help rotating pitch refence plane

I've developed a code snip that's a kind-of compass bearing/pitch targeting guide. Requires phone to be pointing North (or South) and have a pitch of zero. When these parameters are met, the crosshair display "tightens up" and give a degree of guidance on how close the phone is to the above target. See attached *.aia.

I think it's working quite well. However, I now want to start integrating a change that allows the pitch target to be something other than zero. Essentially the same display, but say, the phone pointing North/South with the required pitch will see the display cross-hairs "tighten up".

I got my head around using the sin() and cos() of the heading value to adjust the line thickness and to use the sin() of the azimuth and pitch to help adjust the bullseye size, but I can't get my head around how I might rotate my pitch reference plane from zero to an arbitrary value.

Any guidance here would be great.

Thank you.
Gymbal_Compass_checkpoint1.aia (26.6 KB)

Sensors and the
OrientationChanged(azimuth,pitch,roll) Block (The OrientationChanged event handler is run when the orientation has changed.) might helpful and knowing that

Pitch : 0 degree when the device is level, increasing to 90 degrees as the device is tilted so its top is pointing down, then decreasing to 0 degree as it gets turned over. Similarly, as the device is tilted so its bottom points down, pitch decreases to −90 degrees, then increases to 0 degree as it gets turned all the way over.

An image of what you are attempting to achieve showing how your idea would work certainly would be helpful to anyone attempting to provide specific advice

You can find matrix multiplication formulas for rotation at

For three dimensional rotation, read further down in that article.

Do you need a matrix multiplication package in blocks?

I probably have one lying around.
matrix.aia (11.4 KB)

2 Likes

Thanks @SteveJG

I thought I understood most of that. My OP included the complete aia so anyone could view the code and run the app.

Should I also include the snips of the code and screenshots here too? I'm sorry if my call out dor help wasn't done in the right way.

Thanks @ABG

I think there is something in this for me. From reading and trying to understand this, I've already realised there was a much better way for me to determine my oval dimension using trigonometry (out of the 12th century) rather than linear equations. I previously had:

But now have:

Both achieved similar outcomes, but calculating the oval size using trigonometry was the right way to do it.

I know the answer to my main question here lies in trigonometry, but i'll need to keep reading and try to understand it better before coming to the answer.

Yes, so we can fully understand your question, in this case an image of your screen would help. Loading an aia is not as useful as the op posting his/her relevant Blocks. Thanks.

Thanks @ABG

Your suggested reading on the rotation works. While the Wiki page examples were for 2 dimensions, and I was only really working in one dimension for this function, the code is easily adapted by ignoring the axis you're not interested in.

My revised blocks:

I use a dummy variable instead of taking latitude from the location sensor:

and then perform:

This will require a degree of development to ensure the calculation is relevant for all angles of pitch, but it's got the right starting point.

Sorry, I've had to un-solve this for now. I realise my blocks were close, but not returning correct values. I'll work on it some more and get back to you.

I think one of my problems is the way pitch angles are returned as 0 90 0 or 0 -90 0, depending on phone orientation. I might need a way to convert these to 0 - 360 degrees if I'm to use trigonometric calculations.

Okay, so baby steps here, and documenting the journey in case anyone would like to provide some guidance along the way.

I'm now using the AccelerometerSensor ZAccel in combination with the OrientationSensor Pitch to translate the standard pitch output of 0 90 0 or 0 -90 0 to a full one-dimensional polar system of 0-360 degrees.

Blocks for trial purposes, which are working:

The output may be a little glitchy when the device is standing upright at the interfaces of G on the Z-Axis reading the accelerometer, but I'll deal with that when I translate this concept to actual graphical movement.

Tomorrow, I hope to make more sense of the Transformation Matrix calculations that @ABG provided above.

Rather than trying to use pitch values directly, I resolved the issue by simply using a combination of the pitch sensor values and the ZAccel values to have the phone's pitch angle shown as a one-dimensional polar system of 0-360 degrees.

Doing this allows the use of trigonometric sine values that can calculated directly for the full rotation circle whilst simply adding and subtracting the relevant latitude angles.

In simple terms, the blocks for this to draw the arc are simply:

Where True_Pitch is calculated as:

This conversion essentially does this:

The Latitude_Test is taken directly from the Location sensor.

However, I'm doing more than just drawing an oval, I'm also colouring it and changing its line thickness, so I also do a whole bunch of other tests to provide the right display.

I hope this helps anyone who might be interested in doing something similar. I'd also be interested if anyone else has other good ideas about this.

Attached is my incomplete, but working AIA also for reference. Incomplete, because I need to revisit the bullseye procedure, but hopefully you'll understand what's going on.

Gymbal_Compass_v2.aia (32.3 KB)

Interesting.

Can you use a polar plot of az/el in your app? Consider

Polar Plot (Polar Graph) It was used by me to plot the positions of satellites in the overhead sky. You may be able to adapt it to your telescope app.

There is another part of my larger app that interfaces with a gps module via an esp32, but I'm only really interested in the number of satellites providing lock.

This code here is more for the compass/pre-alignment part of the app.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.