Results 1 to 7 of 7

Thread: Need some help with trigonometry

  1. #1
    .NET Framework
    .NET 4.0
    Join Date
    Nov 2005
    Location
    Columbia, SC
    Posts
    193
    Reputation
    163

    Need some help with trigonometry

    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 !!!

  2. #2
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    15,214
    Reputation
    2860
    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?
    [xcode=vb] code here [/xcode] - see bbcode list or use formatting buttons in posting editor.

    Visual Studio Community 2017

  3. #3
    .NET Framework
    .NET 4.0
    Join Date
    Nov 2005
    Location
    Columbia, SC
    Posts
    193
    Reputation
    163
    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 !!!

  4. #4
    .NET Framework
    .NET 4.0
    Join Date
    Nov 2005
    Location
    Columbia, SC
    Posts
    193
    Reputation
    163
    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...
    Code:
     
    "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 ???

  5. #5
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    15,214
    Reputation
    2860
    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?
    Attached Files Attached Files
    [xcode=vb] code here [/xcode] - see bbcode list or use formatting buttons in posting editor.

    Visual Studio Community 2017

  6. #6
    .NET Framework
    .NET 4.0
    Join Date
    Nov 2005
    Location
    Columbia, SC
    Posts
    193
    Reputation
    163

    Smile

    This is it !!! Thank You John ! Who needs sines and cosines ?
    '... Never cease to amaze me !!!
    Last edited by ALX; 10-12-2018 at 9:10 PM.

  7. #7
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    15,214
    Reputation
    2860
    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.
    [xcode=vb] code here [/xcode] - see bbcode list or use formatting buttons in posting editor.

    Visual Studio Community 2017

Similar Threads

  1. Trigonometry help
    By RonMex in forum VB.NET General Discussion
    Replies: 5
    Last Post: 04-15-2011, 1:37 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •