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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:51:27+00:00 2026-05-29T05:51:27+00:00

First, see: https://math.stackexchange.com/questions/105180/positioning-a-widget-involving-intersection-of-line-and-a-circle I have an algorithm that solves for the height of an

  • 0

First, see:

https://math.stackexchange.com/questions/105180/positioning-a-widget-involving-intersection-of-line-and-a-circle

I have an algorithm that solves for the height of an object given a circle and an offset.

It sort of works but the height is always off:
Here is the formula:
enter image description here

and here is a sketch of what it is supposed to do:
enter image description here

And here is sample output from the application:
enter image description here

In the formula, offset = 10 and widthRatio is 3. This is why it is (1 / 10) because (3 * 3) + 1 = 10.

The problem, as you can see is the height of the blue rectangle is not correct. I set the bottom left offsets to be the desired offset (in this case 10) so you can see the bottom left corner is correct. The top right corner is wrong because from the top right corner, I should only have to go 10 pixels until I touch the circle.

The code I use to set the size and location is:

void DataWidgetsHandler::resize( int w, int h )
    {
        int tabSz = getProportions()->getTableSize() * getProportions()->getScale();
        int r = tabSz / 2;
        agui::Point tabCenter = agui::Point(
            w * getProportions()->getTableOffset().getX(),
            h * getProportions()->getTableOffset().getY()); 

        float widthRatio = 3.0f;
        int offset = 10;
        int height = solveHeight(offset,widthRatio,tabCenter.getX(),tabCenter.getY(),r);
        int width = height * widthRatio;

        int borderMargin = height;

        m_frame->setLocation(offset,
            h - height - offset);

        m_frame->setSize(width,height);

        m_borderLayout->setBorderMargins(0,0,borderMargin,borderMargin);


    }

I can assert that the table radius and table center location are correct.

This is my implementation of the formula:

int DataWidgetsHandler::solveHeight( int offset, float widthRatio, float h, float k, float r ) const
{

    float denom = (widthRatio * widthRatio) + 1.0f;

    float rSq = denom * r * r;

    float eq = widthRatio * offset - offset - offset + h - (widthRatio * k);
    eq *= eq;
    return  (1.0f / denom) *
        ((widthRatio * h) + k - offset - (widthRatio * (offset + offset)) - sqrt(rSq - eq) );


}

It uses the quadratic formula to find what the height should be so that the distance between the top right of the rectangle, bottom left, amd top left are = offset.

Is there something wrong with the formula or implementation? The problem is the height is never long enough.

Thanks

  • 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-29T05:51:29+00:00Added an answer on May 29, 2026 at 5:51 am

    Well, here’s my solution, which looks to resemble your solveHeight function. There might be some arithmetic errors in the below, but the method is sound.

    You can think in terms of matching the coordinates at the point of the circle across
    from the rectangle (P).

    Let o_x,o_y be the lower left corner offset distances, w and h be the
    height of the rectangle, w_r be the width ratio, dx be the desired
    distance between the top right hand corner of the rectangle and the
    circle (moving horizontally), c_x and c_y the coordinates of the
    circle’s centre, theta the angle, and r the circle radius.

    Labelling it is half the work! Simply write down the coordinates of the point P:

    P_x = o_x + w + dx = c_x + r cos(theta)
    P_y = o_y + h = c_y + r sin(theta)
    

    and we know w = w_r * h.

    To simplify the arithmetic, let’s collect some of the constant terms, and let X = o_x + dx - c_x and Y = o_y - c_y. Then we have

    X + w_r * h = r cos(theta)
    Y + h = r sin(theta)
    

    Squaring and summing gives a quadratic in h:

    (w_r^2 + 1) * h^2 + 2 (X*w_r + Y) h + (X^2+Y^2-r^2) == 0
    

    If you compare this with your effective quadratic, then as long as we made different mistakes :-), you might be able to figure out what’s going on.

    To be explicit: we can solve this using the quadratic formula, setting

    a = (w_r^2 + 1) 
    b = 2 (X*w_r + Y)
    c = (X^2+Y^2-r^2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

See the pictures: https://i.stack.imgur.com/CqOJU.jpg On the first picture in the library, on the left,
I wanna check sharepoint title first and see if the lib doesn't have that
I have a .txt file with content(see first image) I need the content in
first, please see the blog as the link showed below: http://blogs.nitobi.com/joe/2008/10/17/phonegap-now-for-android/comment-page-1/#comment-12918 the author made
I have this code: $url=https://graph.facebook.com/me/friends?access_token=.$access_token.&fields=id,first_name,last_name&limit=10; $content=file_get_contents($url); Whenever I use this on a non authenticated
I'm writing a JSON library for C (see https://github.com/DanielWaterworth/Butterfly ). I can serialize every
First see my Source Code: WebClient client = new WebClient(); String url = http://localhost;
It is not the first time i see it Ive seen in Facebook source
I'm just taking my first steps with Azure and the first thing I see
I'm familiarizing myself with Ruby and it's the first time I see synonyms for

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.