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

  • Home
  • SEARCH
  • 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 6658761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:57:04+00:00 2026-05-26T01:57:04+00:00

I am refactoring a graphic program that shows a drawing. The program uses its

  • 0

I am refactoring a graphic program that shows a drawing. The program uses its own transformation and the code is quite complicated. I’d like to refact the code with a transformation matrix instead.

The window and view coordinates are X to the right and Y to downwards.

The drawing in window uses the top left point as base point (0,0). The view is a screen rectangle area with base point (0,0) at the top left point too.

The view area can by any rectangle on the screen. It shows the drawing inside 80%x80% area leaving some margins around.

The drawing has a size of width x height. The program should show the drawing with the same scale ratio at both directions. The center of the drawing is mapping to the center of the view area. the drawing can be rotated in any angle between 0 ~ 360 degrees.

What is the general transformation matrix for this, given the following data:

  1. width and height of the drawing
  2. Rotation angle
  3. width and height of the view area
  4. Margins around the drawings
  • 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-26T01:57:05+00:00Added an answer on May 26, 2026 at 1:57 am

    First you need the width/height of the box containing the rotated image

    x0 = image_width/2 * cos(angle) + image_height/2 * sin(angle)
    x1 = image_width/2 * cos(angle) - image_height/2 * sin(angle)
    y0 = image_width/2 * sin(angle) + image_height/2 * cos(angle)
    y1 = image_width/2 * sin(angle) - image_height/2 * cos(angle)
    rotated_width = max(abs(x0), abs(x1)) * 2
    rotated_height = max(abs(y0), abs(y1)) * 2
    

    then you need to compute which of the two dimensions will be the scaling constraint

    sf = min((view_width - 2*border) / rotated_width,
             (view_height - 2*border) / rotated_height)
    

    then you can compute the 3×2 transformation matrix

    m11 = sf*cos(angle)
    m12 = sf*sin(angle)
    m21 = -sf*sin(angle)
    m22 = sf*cos(angle)
    m31 = view_width/2 - image_width/2 * m11 - image_height/2 * m21
    m32 = view_height/2 - image_width/2 * m12 - image_height/2 * m22
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Whilst refactoring some old code I realised that a particular header file was full
While refactoring code and ridding myself of all those #defines that we're now taught
Whilst refactoring some legacy C++ code I found that I could potentially remove some
Whilst refactoring some code I came across some getter methods that returns a std::string.
I'm refactoring a program that has a lot of nested calls such as ServiceManagement.getGlobalizationService()
I am refactoring a class so that the code is testable (using NUnit and
I am refactoring a C# library that uses a Dictionary<int, SomeInterface> all over the
I'm refactoring some code. Right now there are quite a few places with functions
I am refactoring some code that I did not write, and I found a
While refactoring some old code I have stripped out a number of public methods

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.