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

167
Visualizações
Javascript, How do i check if two pseudo rectangles are colliding

Say I have two tables: rect1, and rect2. Each one follows the format of x,y,width,height.

For x, the bigger the number, the farther right it is. for y, the bigger the number, the farther down it is.

var rect1 = [20,40,80,60];
var rect2 = [10,30,67,10];

How would I check if these are colliding? I know it is math related, I am just having issues thinking at the moment.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It should be something along the lines of:

var rect1 = [20, 40, 80, 60];
var rect2 = [10, 30, 67, 10];
function checkCollision(rect1, rect2) {
  var x1 = rect1[0];
  var y1 = rect1[1];
  var w1 = rect1[2];
  var h1 = rect1[3];
  var x2 = rect2[0];
  var y2 = rect2[1];
  var w2 = rect2[2];
  var h2 = rect2[3];
  if (x1 < x2 + w2 && x1 + w1 > x2 && y1 < y2 + h2 && y1 + h1 > y2) {
    return true;
  } else {
    return false;
  }
}
console.log(checkCollision(rect1, rect2));

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