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 8895657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:50:22+00:00 2026-06-14T23:50:22+00:00

How can I find the scale ratio a rotated Rect element in order fit

  • 0

How can I find the scale ratio a rotated Rect element in order fit it in a bounding rectangle (unrotated) of a specific size?

Basically, I want the opposite of getBoundingClientRect, setBoundingClientRect.

  • 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-06-14T23:50:24+00:00Added an answer on June 14, 2026 at 11:50 pm

    First you need to get the transform applied to the element, with <svg>.getTransformToElement, together with the result of rect.getBBox() you can calculate the actual size. Width this you can calculate the scale factor to the desired size and add it to the transform of the rect. With this I mean that you should multiply actual transform matrix with a new scale-matrix.

    BUT: This is a description for a case where you are interested in the AABB, means axis aligned bounding box, what the result of getBoundingClientRect delivers, for the real, rotated bounding box, so the rectangle itself in this case, you need to calculate (and apply) the scale factor from the width and/or height.

    Good luck…

    EDIT::

    function getSVGPoint( x, y, matrix ){
        var p = this._dom.createSVGPoint();
        p.x = x;
        p.y = y; 
        if( matrix ){
            p = p.matrixTransform( matrix );
        }
        return p;
    }
    
    function getGlobalBBox( el ){
        var mtr = el.getTransformToElement( this._dom );
        var bbox = el.getBBox();
        var points = [
            getSVGPoint.call( this, bbox.x + bbox.width, bbox.y, mtr ),
            getSVGPoint.call( this, bbox.x, bbox.y, mtr ),
            getSVGPoint.call( this, bbox.x, bbox.y + bbox.height, mtr ),
            getSVGPoint.call( this, bbox.x + bbox.width, bbox.y + bbox.height, mtr ) ];
    
        return points;
    
    };
    

    with this code i one time did a similar trick… this._dom refers to a <svg> and el to an element. The second function returns an array of points, beginning at the top-right edge, going on counter clockwise arround the bbox.

    EDIT:

    the result of <element>.getBBox() does not include the transform that is applied to the element and I guess that the new desired size is in absolute coordinates. So the first thing you need to is to make the »BBox« global.

    Than you can calculate the scaling factor for sx and sy by:

    var sx = desiredWidth / globalBBoxWidth;
    var sy = desiredHeight / globalBBoxHeight;
    
    var mtrx = <svg>.createSVGMatrix();
    mtrx.a = sx;
    mtrx.d = sy;
    

    Than you have to append this matrix to the transform list of your element, or concatenate it with the actual and replace it, that depends on you implementation. The most confusion part of this trick is to make sure that you calculate the scaling factors with coordinates in the same transformation (where absolute ones are convenient). After this you apply the scaling to the transform of the <element>, do not replace the whole matrix, concatenate it with the actually applied one, or append it to the transform list as new item, but make sure that you do not insert it before existing item. In case of matrix concatenation make sure to preserve the order of multiplication.

    The last steps depend on your Implementation, how you handle the transforms, if you do not know which possibilities you have, take a look here and take special care for the DOMInterfaces you need to implement this.

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

Sidebar

Related Questions

I can't seem to find documentation regarding the ability to scale axes in a
I can find ample evidence that MongoDBs are always kept in the order given
Ok, so I realize I can find the scale value from a layer's CATransform3D
I'm learning Scala and there is a thing that I can't find out about
I can find the JS and HTML code in response by alert() . But
I can find the tool command in my filesystem under: /Applications/Xcode.app/Contents/Developer/usr/bin/otool If I specify
Where can find resources about best practices for SharePoint programming? I am talking about
I can find no non-deprecated way of hiding an item in a menu bar
I can find the definition files at http://www.php.net/~helly/php/ext/spl/... but I want to extend DirectoryIterator
I can find out the error in my apps. When am trying to execute

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.