Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Find a cartesian line from distance of 4 points

  1. #1
    Intern Contributor
    Join Date
    Mar 2014
    Posts
    59

    Find a cartesian line from distance of 4 points

    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?
    Last edited by __bob__; 03-10-2016 at 03:39 AM.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,529
    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
    Code :
    -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
    Code :
    2*a*hl = dB - dA 
    => a = (dB - dA) / (2*hl)
    Subtracting 3 from 2
    Code :
    2*b*hl = dB - dC
    => b = (dB - dC) / (2*hl)
    Adding 1 and 3
    Code :
    -2*c = dA + dC
    => c = -(dA + dC) / 2
    Alternatively, adding 2 and 4 gives the same result:
    Code :
    -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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •