Results 1 to 6 of 6

Thread: [RESOLVED] calculating vertices of a square

  1. #1

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 02
    Posts
    21,653

    Re: calculating vertices of a square

    IF
    A = X1, Y1
    C = X2, Y2
    THEN
    B = X2, Y1
    D = X1, Y2

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.-I also subscribe to all threads I participate, so there's no need to pm when there's an update.*
    *Proof positive that searching the forums does work: View Thread *
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *
    * Use Offensive Programming, not Defensive Programming. * On Error Resume Next is error ignoring, not error handling(tm).
    "There is a major problem with your code, and VB wants to tell you what it is.. but you have decided to put your fingers in your ears and shout 'I'm not listening!'" - si_the_geek on using OERN

  3. #3

  4. #4
    Hyperactive Member
    Join Date
    Jul 11
    Location
    UK
    Posts
    436

    Re: calculating vertices of a square

    Given A and C (as PointF) then
    Code:
    Dim B, D As New PointF
    
    B.X = ((C.X + A.X) + (A.Y - C.Y)) / 2
    B.Y = ((A.Y + C.Y) + (C.X - A.X)) / 2
    D.X = ((C.X + A.X) - (A.Y - C.Y)) / 2
    D.Y = ((A.Y + C.Y) - (C.X - A.X)) / 2
    I hope.... I did it "by eye". Let me know.

  5. #5
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 02
    Posts
    2,301

    Re: calculating vertices of a square

    Given A and C, the center of the square is M = (A+C)/2. Suppose P is a vector perpendicular to the vector from A to C of the same length. Then B is M + P/2 and D is M - P/2. In 2D, it happens that given a vector (x, y), the vector (-y, x) is perpendicular to (x, y). Since the vector from A to C is C-A = (C.x - A.x, C.y - A.y), P is just (A.y - C.y, C.x - A.x). In all...

    B.x = (A.x + C.x)/2 + (A.y - C.y)/2
    B.y = (A.y + C.y)/2 + (C.x - A.x)/2
    D.x = (A.x + C.x)/2 - (A.y - C.y)/2
    D.y = (A.y + C.y)/2 - (C.x - A.x)/2

    These formulas agree with Inferrd's, so they should be what you were after.
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  6. #6
    vb Coda .paul.'s Avatar
    Join Date
    May 07
    Location
    Chelmsford UK
    Posts
    16,470

    Re: calculating vertices of a square

    Quote Originally Posted by Inferrd View Post
    Given A and C (as PointF) then
    Code:
    Dim B, D As New PointF
    
    B.X = ((C.X + A.X) + (A.Y - C.Y)) / 2
    B.Y = ((A.Y + C.Y) + (C.X - A.X)) / 2
    D.X = ((C.X + A.X) - (A.Y - C.Y)) / 2
    D.Y = ((A.Y + C.Y) - (C.X - A.X)) / 2
    I hope.... I did it "by eye". Let me know.
    Quote Originally Posted by jemidiah View Post
    Given A and C, the center of the square is M = (A+C)/2. Suppose P is a vector perpendicular to the vector from A to C of the same length. Then B is M + P/2 and D is M - P/2. In 2D, it happens that given a vector (x, y), the vector (-y, x) is perpendicular to (x, y). Since the vector from A to C is C-A = (C.x - A.x, C.y - A.y), P is just (A.y - C.y, C.x - A.x). In all...

    B.x = (A.x + C.x)/2 + (A.y - C.y)/2
    B.y = (A.y + C.y)/2 + (C.x - A.x)/2
    D.x = (A.x + C.x)/2 - (A.y - C.y)/2
    D.y = (A.y + C.y)/2 - (C.x - A.x)/2

    These formulas agree with Inferrd's, so they should be what you were after.
    thanks for the help. the formulas proved to be the simplest solution...

Posting Permissions

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