Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 520693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:10:19+00:00 2026-05-13T08:10:19+00:00

I am writing a drawing program, Whyteboard — http://code.google.com/p/whyteboard/ I have implemented image rotating

  • 0

I am writing a drawing program, Whyteboard — http://code.google.com/p/whyteboard/

I have implemented image rotating functionality, except that its behaviour is a little odd. I can’t figure out the proper logic to make rotating the image in relation to the mouse position

My code is something similar to this:

(these are called from a mouse event handler)

def resize(self, x, y, direction=None):
    """Rotate the image"""
    self.angle += 1
    if self.angle > 360:
        self.angle = 0
    self.rotate()


def rotate(self, angle=None):
    """Rotate the image (in radians), turn it back into a bitmap"""
    rad = (2 * math.pi * self.angle) / 360
    if angle:
        rad = (2 * math.pi * angle) / 360
    img = self.img.Rotate(rad, (0, 0))

So, basically the angle to rotate the image keeps getting increased when the user moves the mouse. However, this sometimes means you have to “circle” the mouse many times to rotate an image 90 degrees, let alone 360.

But, I need it similar to other programs – how the image is rotated in relation to your mouse’s position to the image.

This is the bit I’m having trouble with. I’ve left the question language-independent, although using Python and wxPython it could be applicable to any language

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T08:10:19+00:00Added an answer on May 13, 2026 at 8:10 am

    I’m assuming resize() is called for every mouse movement update. Your problem seems to be the self.angle += 1, which makes you update your angle by 1 degree on each mouse event.

    A solution to your problem would be: pick the point on the image where the rotation will be centered (on this case, it’s your (0,0) point on self.img.Rotate(), but usually it is the center of the image). The rotation angle should be the angle formed by the line that goes from this point to the mouse cursor minus the angle formed by the line that goes from this point to the mouse position when the user clicked.

    To calculate the angle between two points, use math.atan2(y2-y1, x2-x1) which will give you the angle in radians. (you may have to change the order of the subtractions depending on your mouse position axis).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 283k
  • Answers 283k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I like to let properties handle this for me. If… May 13, 2026 at 4:16 pm
  • Editorial Team
    Editorial Team added an answer I would say none of those two solutions change anything… May 13, 2026 at 4:16 pm
  • Editorial Team
    Editorial Team added an answer Try to find the following line in your php.ini: display_errors… May 13, 2026 at 4:16 pm

Related Questions

I am just starting out with QT. I have read through some tutorials, and
I am writing a program that will draw a solid along the curve of
Not sure exactly what I need to do to make this work, so my
I'm writing a C++ program that has a large number of classes. In my
I am trying to write a fragment program that will take a texture and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.