Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

264
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!