__bob__

03-10-2016, 02: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, 04: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)

Adding 1 and 3

-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.

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.