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

269
Visualizações
How do I move a point's y coordinate to intersect with a line?

enter image description here

I have point c, which represents the center of a circle. After I drag the circle, I want its y coordinate hmm to snap to a line that's drawn between point a and b. How do I solve for hmm?

So far I've been able to find the midway y value between points a and b. However, it's not taking into account point c's x value.:

const snapYToLine = (aY, bY) => {
  const yDist = bY - aY;
  return aY + (yDist * 0.5);
}

const a = { x: 10, y: 10 };
const b = { x: 50, y: 30 };
const c = { x: 20, y: 0 }; // not doing anything with this yet...

const hmm = snapYToLine(a.y, b.y); // will need to include c.x here...
console.log(hmm);
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

X coordinate of C depends on where you drag it, but Y coordinate should be so point stays on line between A and B?

The equation of line between 2 points (A and B): (x - Xa) / (Xa - Xb) = (y - Ya) / (Ya - Yb).

So hmm = (x - Xa) * (Ya - Yb) / (Xa - Xb) + Ya.

Because it's equation of line you can drag point C over A/B X coordinates and still find corresponsive Y value.

Hope I've understood your question right.

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