Do the math?

I have 4 coodinates (x,y) that mark the 4 corners of a rectangle (not necessarly a square). If I click a point need the “lines” the intersect those points, I need to know which of the coordinate pairs the click was closest to. Did I click nearest the TOP edge? LEFT, BOTTOM or RIGHT … or was I outside of a predetermined tolerance?

The idea is to select an edge, without have to hit the “line” exactly… just gotta be reasonable close

Assuming the box edges are vertical/horizontal, You can use abs to help you here.

if abs(top-y) < tolerance then // clicked top edge End if

actually headed that direction… In reality it is more than a “square” it is actually a “grid”
so I am going to take my click Point § and find the Horizontal line and vertical line the is closest (abs(delta)
once I have those two line… the sign of each delta will tell me what side of the line the point is on

just need to decide what do to if the distance from top and left are equal… :slight_smile:

Calculate the distance using the good old Pythagorean formula a^2 + b^2 = c^2.
c is the distance.
a is abs(x1 - x2), b is abs(y1 - y2).

[quote=416475:@Tim Hare]Calculate the distance using the good old Pythagorean formula a^2 + b^2 = c^2.
c is the distance.
a is abs(x1 - x2), b is abs(y1 - y2).[/quote]
No need to be that expensive. What Greg mentioned (with some expansion) works just fine… Since the lines are horizontal and vertical, and I’m not looking for the distance to a specific point

Cool. Your mention of a grid made me think of “closest point on the grid”. As in snap to grid.

Nah… when the user clicks on the grid… In needed to know which horizontal or vertical line (and what square) was clicked…
so for example … Cell(5,3) Top Side

Wouldn’t it be faster using matrices?

not sure how you figure how Matrix Math is easier or faster than a simple comparison of DeltaX and DeltaY

but thanks… I have it all worked out… its fast, its accurate and does exactly what needs to be done.

Gregs origninal statement pointed me in the direction that I couldn’t put my finger on originally