Algorithm Help

This is a discussion on Algorithm Help within the C++ Programming forums, part of the General Programming Boards category; Problem: I have coordinates of of two side of the rectangles- Suppose I have coordinates of 5000 boxes. Like this- ...

  1. #1
    Registered User
    Join Date
    Jul 2013
    Posts
    3

    Question Algorithm Help

    Problem: I have coordinates of of two side of the rectangles-

    Name:  PCHBP.jpg
Views: 157
Size:  5.3 KB

    Suppose I have coordinates of 5000 boxes. Like this-
    Code:
             (    x1,    y1)    (    x2,    y2)     
             (0.0000,0.0000)    (0.3412,0.4175)     
             (0.7445,0.0000)    (1.0000,0.6553)     
             (0.7445,0.6553)    (1.0000,1.0000)     
             (0.0000,0.6553)    (0.7445,1.0000)     
             (0.3412,0.0000)    (0.7445,0.4175)     
             (0.3412,0.4175)    (0.7445,0.6553)     
             (0.0000,0.4175)    (0.3412,0.6553) ...etc
    These coordinates subdivide an unit squre like this -

    Name:  unit4.jpg
Views: 155
Size:  5.6 KB

    I want to calculate the number of nearest rectangles for each of the boxes using c++.

    Example

    For rectangle# 7 the nearest boxes are- 4,1,6 and 2
    (If they share only corner they are not consider as nearest boxes, So rectangle 5 & 3 are not nearest of rectangle 7)

    Can anyone help me how can I write the algorithm for this problem?
    Attached Images Attached Images  

  2. #2
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    If two boxes are touching, they must be along the same vertical or horizontal line:
    Code:
    .        |-----
             |     |
             |  C  |
             |     |
         ----|-----
        | A  |
        |    |
         ----|
             |
             |----
             |    |
       ------| D  |
      |      |    |
      |   B  |    |
      |      |----
      |      |
       ------|
             |
    A and D do not touch at all. A and C only touch at the corners. B and D touch at more than just corners. The kinds of comparisons you'd make to separate the cases are obvious.
    Last edited by oogabooga; 07-07-2013 at 05:44 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. -->. algorithm .<--
    By broken_heart in forum C Programming
    Replies: 5
    Last Post: 09-26-2009, 09:42 AM
  2. I need an algorithm.... please help
    By darcome in forum C Programming
    Replies: 5
    Last Post: 03-16-2003, 01:24 PM
  3. A better algorithm
    By spoon_ in forum C Programming
    Replies: 3
    Last Post: 03-02-2003, 12:37 PM
  4. algorithm help
    By the Wookie in forum C++ Programming
    Replies: 5
    Last Post: 02-19-2003, 07:12 PM
  5. my grandfather's chess algorithm can beat your grandfather's chess algorithm...
    By doubleanti in forum A Brief History of Cprogramming.com
    Replies: 22
    Last Post: 08-17-2001, 07:52 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21