Results 1 to 6 of 6

Thread: [RESOLVED] calculating vertices of a square

  1. #1

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,414

    Resolved [RESOLVED] calculating vertices of a square

    assuming i have a square:

    Name:  square.png
Views: 2837
Size:  2.2 KB

    + i know the coordinates of point A + point C, or the coordinates of point B + point D...

    how can i find the coordinates of the other 2 points?

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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 don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * 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??? *

  3. #3

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,414

    Re: calculating vertices of a square

    i forgot to mention, the square will be rotated

  4. #4
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,335

    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 2002
    Posts
    2,431

    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

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,414

    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
  •  



Click Here to Expand Forum to Full Width