PDA

View Full Version : Find a cartesian line from distance of 4 points

__bob__
03-10-2016, 01:57 AM
Hi all!

I have square of size 2*hl with a center in (0,0).

A--------B
| |
| O |
| |
D--------C

And i have the minimal signed distance between A B C D and line. Can i find the cartesian représentation of this line only from these distances?

GClements
03-10-2016, 03:06 AM
If the line is defined by the implicit equation a*x+b*y=c (i.e. a*x+b*y-c=0) and the the normal vector (a,b) is normalised (i.e. a2+b2=1) then the signed distance of a point x,y from the line is just d=a*x+b*y-c.

If the distances from A,B,C,D are dA,dB,dC,dD, then you have

-a*hl + b*hl - c = dA (1)
a*hl + b*hl - c = dB (2)
a*hl - b*hl - c = dC (3)
-a*hl - b*hl - c = dD (4)

Subtracting 1 from 2

2*a*hl = dB - dA
=> a = (dB - dA) / (2*hl)

Subtracting 3 from 2

2*b*hl = dB - dC
=> b = (dB - dC) / (2*hl)

-2*c = dA + dC
=> c = -(dA + dC) / 2

Alternatively, adding 2 and 4 gives the same result:

-2*c = dD + dB
=> c = -(dB + dC) / 2

I.e. one of the distances is redundant; the mean of the distances for opposite corners must be equal (and is equal to the distance of the line from the origin).

Note that if a2+b2 isn't equal to 1, you still have the correct equation for the line; it just means that your signed "distances" include a scale factor.