Question Need some help with trigonometry

ALX

Well-known member
Joined
Nov 16, 2005
Messages
253
Location
Columbia, SC
Programming Experience
10+
I apologize for not paying better attention in trig class back in the 60's. Yes, I am that old ! I need help determining how to adjust the X and Y coordinates of an image that has been rotated to move the image to the Left, Right, Up or Down. The image is in a Picture Box and may have been rotated by the user to align a scanned image to a reference grid. The user also needs to be able to move the image left, right, up or down with the arrow keys to help center the image. My problem is: if the image has been rotated, the transform is based on the image's original disposition. If the user presses the Left arrow key and the image has been rotated 90 degrees, subtracting 1 from the image's X coordinate moves the image up instead of left. I could copy the bitmap as it stands in it's rotated position and set the angle back to 0, but each time that is done there is a degradation of the image quality. I know I need to adjust both the X and Y coordinates using sines and / or cosines, but I just can't recollect how to do it. I know there's a kind math genius out there that can help...
Many Thanks !!!
 
I don't know how you do things, but for example with graphics transformations you could perhaps change the order to avoid the trigonometry, first move in 2D space then rotate?
 
I think I'll end up doing that. I've considered having a button to "Set" the rotation after which the only allowed adjustments would be horizontal or vertical. You always have good input, John. Thanks for the great help you have given me over the years. You have the patience of a saint !!!
 
One other attempt I made at this was to copy the bitmap to a Picture Box that is larger than the Panel that contains it. That would force the panel to display scroll bars. Then as the user pressed the Left, Right, Up, Down keys to fine tune the horizontal & vertical positions, I would use code similar to...
VB.NET:
"If Panel1.HorizontalScroll.Value > Panel1.HorizontalScroll.Minimum Then
    Panel1.HorizontalScroll.Value -= 1
End If"
to shift the image within the visible portion of the Picture Box. That works except that it only registers every other keystroke. I see the scroll bars move slightly with every keystroke, but the image only moves every other keystroke... WTF ???
 
I played a little with the Graphics transformations and attach the project here, basically it contains five slightly different versions of the same code to rotate (NumericUpDown box) and move an image (with arrow keys). Maybe you find it useful?
 

Attachments

  • TransformSample.zip
    56.7 KB · Views: 53
I'm glad you found it useful. I actually needed a tangent calculation in 2005, but have otherwise managed to avoid that. The graphics libraries we use is probably full of it.
 

Latest posts

Back
Top