Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

267
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda