Determining the Size of a Rectangle based on Co-ordinates in Java -


i've been struggling problem awhile , i'm looking assistance.

  1. information know/am given:

    • a series of co-ordinates similar following
      • x=5, y=5
      • x=5, y=6
      • x=9, y=10
      • x=1, y=1
      • x=2, y=1
      • x=1, y=2
      • x=2, y=2
    • every point in list part of rectangle, @ least 1x1
    • these lists int[]s, x-coords in 1 array, , y-coords in another
    • the array co-ordinates matched (e.g. xcoords[5] makes ordered pair ycoords[5])
    • the size of arrays not consistent (it might 50 x-coords , 50 y-coords)
    • the co-ordinates can negative
  2. what need find

    • the number of rectangles in list (e.g. example 3)
    • the size of each rectangle (e.g. example r1=2x1, r2=1x1, r3=2x2)
    • the format of results don't matter

example:

public class rectangle_test {      public static void main(string[] args) {         int[] xcoords = {5,5,9,1,2,1,2};         int[] ycoords = {5,6,10,1,1,2,2};      }  } 

i have idea of how approach problem...

  1. get first element of each array , assign variable

int initialx = xcoords[0]; int initialy = ycoords[0]; 2. loop through arrays, , compare initial values each value in array, , reset if both different

if(initialx != xcoords[currentindex] && initialy != ycoords[currentindex] && xcoords[currentindex] != xcoords[currentindex+1] && ycoords[currentindex] != ycoords[currentindex+1]){     initialx = xcoords[currentindex];     initialy = ycoords[currentindex];     numrects++; } 
  1. however, can't figure out how determine rectangle size code above...


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -