Image rotation depending on azimuth

Majkl

Member
Joined
Dec 8, 2023
Messages
5
Location
Czech Republic
Programming Experience
3-5
Hi,
I get the current azimuth value from the GPS and I would like the image embedded in GmapControl to rotate depending on the azimuth, which I did, but I would like the current image to remain from the value from 180 to 360, but as it will be from 0 to 180 so that the image is rotated so that it is not upside down.
It will probably require two images, but I'm not sure how to do it; I haven't been able to solve it yet. Does anyone have experience with this?
I use the nuGet elements of Gmap.NET.Core and Gmap.WinForms
I am attaching the project here - My files - UploadNow.io

I apologize for my English.
 
What's wrong with just using the modulus operator to always compute the rotation angle? Eg. Rotation = azimuth % 180?
 
What's wrong with just using the modulus operator to always compute the rotation angle? Eg. Rotation = azimuth % 180?

Thank you for the response, I asked the question of turning the azimuth incorrectly and it is solved. I missed certain connections. :)
For the interestingness of the solution here:
C#:
if (pictureBox3.InvokeRequired)
{

    pictureBox3.BeginInvoke(new Action(() => pictureBox3.Image = pictureBox4.Image));
    pictureBox3.BeginInvoke(new Action(() => pictureBox3.Image = RotateImage(pictureBox3.Image, (float)g_AzimuthInspvaa - 90)));
    //this.Invoke(pictureBox3.Image = RotateImage(pictureBox3.Image, (float)g_AzimuthInspvaa - 90);)
}
else
{
    pictureBox3.Image = pictureBox4.Image;
    pictureBox3.Image = RotateImage(pictureBox3.Image, (float)g_AzimuthInspvaa - 90);
}
 
Why copy the image from one picture box into another picture box, then the take that image, rotate it, and then put it back into the picture box?

Unless your RotateImage() methor is destructive, just have a reference to the image itself as a class variable (almost like your global variable for azimuth), pass that into the rotate image method, and then assign to your picture box. Something like:
C#:
void SetRotatedImage()
{
    pictureBox3.Image = RotateImage(_subjectImage, g_azimuthAngle - 90);
}

And the reason why the above is in it's own method is to apply the DRY principle (Don't Repeat Yourself) so that your refresh code can the simply be:
C#:
if (InvokeRequired)
    Invoke(SetRotatedImage)
else
    SetRotatedImage();

If your RotateImage() mathod is destructive, you should change the signature so that it doesn't return an image, because that would follow the principle least surprise that was one of the guiding principles of C# API design back in the early days. Of course if it destructive, then I doubt that copying from one picture box to another would have protected the image in the original picture box, because the copying was only by reference, not by value.
 

Latest posts

Back
Top Bottom