Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

229
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda