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

184
Visualizações
Determine if two non-rectangles overlap in JS

I have two html elements (in my case they are SVG path elements). Each of these has a different stroke width. Is there any way to determine if two of these paths overlap? I have tried using the npm path intersection library, but it doesn't allow me to specify a width. Also, the results are approximate, but I need more exact data.

I don't need to calculate the actual intersection area, or coordinates. I just need to know if an intersection occurs between these two paths with definite widths. Is there a solution?

edit: here is an example to demonstrate something i want

<svg xmls="http://www.w3.org/2000/svg">
  <path id="p1" d="M10,10 C20,30, 50,70, 100,100" stroke-width="3" stroke='black'></path>
  <path id="p2" d="M20,0 Q200,30,0,100" stroke-width="5" stroke="red"></path>
</svg>
path {
  fill: none;
}
svg {
  position: absolute;
  top: 100px;
  left: 100px;
}

in javascript, i have something like this:

let p1 = document.getElementById("p1"), p2 = document.getElementById("p2");

if (p1 intersects/overlaps with p2) {
  //run some code
}

example 1

it produces the above, which i classify as an intersection, as the paths themselves overlap

example 2 here, i produced the same lines, but one is shifted. I do not classify this as an overlap

about 4 years ago · Juan Pablo Isaza
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