Point on the line closest to x, y

Possible duplicate:
How do I know if a point is near a certain line?

//Returns the point on the line traced from start to end which
//comes nearest to 500,000, 500,000. The points are scaled between
//1,000,000 and 0 from their original fp types.
Point closestToCentre(Point start, Point end);

Does anyone know faster than a single step through pixels?

Can any more anxiety than me demonstrate my mathematical skills and geometry?

_______ ___________ EDIT

Thanks to Chris, it baffled me:

[x; -a / bx-c / b] = [0; -c / b] -1 / b [-b; a] x.

Now I see that this is simply splitting the (mostly y-component) vector into two that combine to give the same result. Got an old partial fraction of brain cells excited within a minute :)

_______ _________ EDIT

Jason Moore, thanks for the inspiration, this is what I do, graphically,

64x64 square with 2 sample lines each passing edge to edge and missing the center by some distance

Hope this is clearer.

____ EDIT ________

, , ​​ , , ?

enter image description here

, - . , . , .

____ _________ EDIT

, , stackoverflow . : .

, matti ( ):

http://www.topcoder.com/tc?d1=tutorials&d2=geometry1&module=Static

, !

http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html

+5
3

, , MathWorld.

, , - x, y . , , x, y.

: (2) , y = mx + c, , .

+7

, - :

  • , (500 000, 500 000).
  • , , .

Kris 1, , , 2, , .

1 = (x1, y1) 2 = (x2, y2). , ,

y = (y2 - y1)/(x2 - x1) * (x - x1) + y1

perp. (5e5, 5e5)

y = (x1 - x2)/(y1 - y2) * (x - 5e5) + 5e5

(x, y) (x, y) ( ). , mathworld. , , , , , , mathworld , .

+1

See my answer to this stack overflow question . This question is more complex than yours, so you should be able to use the first couple of steps in your answer to get what you need.

0
source

All Articles