Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

231
Views
Given circle that is centered on bottom-left corner of a rect, calculate width of circle's bounding rect so its radius touches the top-right corner

Given a circle that is centered on the bottom-left corner of any rectangle (square, horizontal, vertical), calculate the width of the circle's bounding rectangle so its radius touches the top-right corner of the sizing rectangle in JavaScript.

Considering the image below, I am looking for 1 JS function that can handle all 3 scenarios, given the known width and height of the rectangle.

function getCircleWidth(width: number, height: number): number {
    // return width of circle's bounding rectangle
}

UPDATE:

See the accepted answer below for the bullet proof logic for this problem, Ended up with the following with help from here https://www.omnicalculator.com/math/diagonal-of-rectangle:

function getCircleWidth(width: number, height: number): number {
    return (Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2)) * 2);
}

Requirements

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The width of a circle's bounding rectangle, is the circle's diameter (and that bounding rectangle is a square).

A circle's diameter is the double of its radius.

The diagonal of the given rectangle has a length that is equal to that radius.

The length of the diagonal can be derived from the right triangle it forms with the sides of that rectangle, using the Pythagorean theorem

So:

function getCircleWidth(width: number, height: number): number {
    return (width**2 + height**2)**0.5 * 2;
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!