Results 1 to 4 of 4

Thread: Rectangle's coordinates

Threaded View

  1. #4
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141
    This is what I came up with real quick. See if it gives you some ideas.
    VB Code:
    1. '   Define Corners 1, 2, 3, and 4
    2. '   Find the lengths of
    3. '       Side 1_2
    4. '       Side 2_3
    5. '       Side 3_4
    6. '       Side 4_1
    7. '       Diagonal 1_3
    8. '       Diagonal 2_4
    9. '
    10. '   1-----------2
    11. '   |           |
    12. '   |           |
    13. '   |           |
    14. '   4-----------3
    15. '
    16. '   If Side 1_2 = Side 3_4 and Side 4_1 = Side 2_3 Then
    17. '       Either Square, parallagram or Rectangle
    18. '   If Diagonal 1_3 = Diagonal 2_4 Then Rectangle or Square
    19. '       Else parallagram
    20. Option Explicit
    21.  
    22. Private Type Corners
    23.     X As Integer
    24.     Y As Integer
    25. End Type
    26.  
    27. Dim Corner(1 To 4) As Corners
    28. Dim Side(1 To 4) As Single
    29. Dim Diagonal(1) As Single
    30.  
    31. Private Sub Form_Load()
    32.  
    33.     Me.AutoRedraw = True
    34.     Me.Show
    35.    
    36. '   Define the corners of the rectangle
    37.     Corner(1).X = 400
    38.     Corner(1).Y = 400
    39.    
    40.     Corner(2).X = 2400
    41.     Corner(2).Y = 200
    42.    
    43.     Corner(3).X = 2500
    44.     Corner(3).Y = 1200
    45.    
    46.     Corner(4).X = 500
    47.     Corner(4).Y = 1400
    48.    
    49. '   Draw the rectangle
    50.     Me.Line (Corner(1).X, Corner(1).Y)-(Corner(2).X, Corner(2).Y)
    51.     Me.Line -(Corner(3).X, Corner(3).Y)
    52.     Me.Line -(Corner(4).X, Corner(4).Y)
    53.     Me.Line -(Corner(1).X, Corner(1).Y)
    54.    
    55. '   Get the length of each side
    56.     Side(1) = GetLength(Corner(1), Corner(2)) ' Side 1_2
    57.     Side(2) = GetLength(Corner(3), Corner(4)) ' Side 3_4
    58.     Side(3) = GetLength(Corner(2), Corner(3)) ' Side 2_3
    59.     Side(4) = GetLength(Corner(4), Corner(1)) ' Side 4_1
    60.    
    61. '   Get Diagonal Lengths
    62.     Diagonal(0) = GetLength(Corner(1), Corner(3))
    63.     Diagonal(1) = GetLength(Corner(2), Corner(4))
    64.    
    65. End Sub
    66.  
    67. Private Function GetLength(FirstCorner As Corners, SecondCorner As Corners) As Single
    68. Dim A As Long
    69. Dim B As Long
    70. Dim C As Long
    71.  
    72.  
    73.     A = Abs(FirstCorner.X - SecondCorner.X)
    74.     B = Abs(FirstCorner.Y - SecondCorner.Y)
    75.    
    76.     C = A ^ 2 + B ^ 2
    77.    
    78.     GetLength = Sqr(C)
    79.    
    80. End Function
    Last edited by MarkT; May 27th, 2003 at 04:03 PM.

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