### Thread: x , y coordinates

Page 1 of 2 12 Last
1. No Profile Picture
Junior Member
Devshed Newbie (0 - 499 posts)

Join Date
Jun 2002
Posts
9
Rep Power
0

#### x , y coordinates

hi !
i need a little help

i have points all over the screen on x y coordinates
like this

. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .

and so on all over the screen the x y coornites are known in advance
now wat i am trying to do is when ever a saqure is formed between four points user must get a message that a saqure is formed and when all the saqures are formed the loop must exit
i am unbale to do this
if some body can help i will be grate full
thanks
suhail
2. Where X1 and Y1 are starting points,
and X2 and Y2 are ending points...

If

(X1 - X2) = (Y1 - Y2)

Then

"You have a square"
3. Please do not post the same thing in multiple forums, this is considered double posting.
4. Originally posted by Waltjp
Where X1 and Y1 are starting points,
and X2 and Y2 are ending points...

If

(X1 - X2) = (Y1 - Y2)

Then

"You have a square"
To follow up on my previous post...

You should compare the absolute value of (X1 - X2) = absolute value of (Y1 - Y2)

If true, you have a square.
5. No Profile Picture
Junior Member
Devshed Newbie (0 - 499 posts)

Join Date
Jun 2002
Posts
9
Rep Power
0
hi !

it did't help !

u say
X1-X2 =Y1-Y2
i have a saqure but no i only have twolines like this
look

i have a starting point
x1,y1 = 10,10
and ending point
x2,y2 = 15,15

now
x1-x2 =y1-y2
10-15 = 10-15
5=5

i have two lines not four i will get ths shape not a saqure ?
|
|
|______

ok thsi si wat my prog do

i have point all over the screen on x y coordinated the distace between one x,y point is 5 coloums x,y

. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .

now the user can move throgh these point with the help of cursor keys up ,down,right and left,

now if the user wants to selctt any point , user just press enter now that x,y point is selected lets say 10,10
now from ths point forward user can only move one point to right ,lleft ,up and down and select any of thses four points
now the user agin press the enter key and slects the up point at location x,y = 10,5

now a line is drawn from point 10,10 to 10,5 as soon as the line is drawn loops start again user can move throgh any point he wants and select the first point again at any x,y coornites and as soon as he selects that point he can move the courser to only one point ,up,down,right and left and as soon he select any point from these four points the line is dranm between thses points and so on it continues

now wat i wnat was how will i know if a saqure is formed anywhere between four points ??????

suhail
6. No Profile Picture
Junior Member
Devshed Newbie (0 - 499 posts)

Join Date
Jun 2002
Posts
9
Rep Power
0
????????
no help ?
7. No Profile Picture
Junior Member
Devshed Newbie (0 - 499 posts)

Join Date
Apr 2002
Location
Detroit, MI
Posts
14
Rep Power
0
You need to check your entire board for squares. I'm sure you have the board represented as a two-dimensional array. Here's some psudo-code for what I would do. Hope I am understanding you correctly.

1. You need to scan (using a loop) your board from upper left (point 1,1) to lower right (lets say 20,20). Locate a point on the board (POINT 1).

2. When you find POINT 1, check the entire row that POINT 1 is in for OTHER points. Also check the entire column that POINT 1 is in for OTHER points. I'd use an algorithm that loops through each point in the row, and whenever it finds a point in that same ROW, it checks to see if there is a point in the same COLUMN the same distance away (from POINT 1).

3. If you do the above and encounter a place where there is a POINT 1 with POINTS 2 and 3 that are the same distances away, (X2 - X1 = Y3 - Y1 & obviously Y1 = Y2 and X1 = X3), then check for a correct POINT 4 to make a square, at Y4 = Y3, X4 = X2.

Make sure you repeat step 2 for every matching row/column pair.
Make sure you repeat step 1 using every point as a starting point, or "POINT 1".

For reference I used the following:

A * * * * B
* * * * * *
* * * * * *
* * * * * *
* * * * * *
C * * * * D

with
A = X1, Y1
B = X2, Y2
C = X3, Y3
D = X4, Y4

Hope that helps get you started at least! If not, ask questions!
Last edited by Nichademus; June 12th, 2002 at 12:12 PM.
8. No Profile Picture
Junior Member
Devshed Newbie (0 - 499 posts)

Join Date
Jun 2002
Posts
9
Rep Power
0
hi !
can u please explain point 2

2. When you find POINT 1, check the entire row that POINT 1 is in for OTHER points. Also check the entire column that POINT 1 is in for OTHER points. I'd use an algorithm that loops through each point in the row, and whenever it finds a point in that same ROW, it checks to see if there is a point in the same COLUMN the same distance away (from POINT 1).

wat do u mean by POINT 1 is in for OTHER points.????

suhailkaleem
9. No Profile Picture
Junior Member
Devshed Newbie (0 - 499 posts)

Join Date
Apr 2002
Location
Detroit, MI
Posts
14
Rep Power
0
What I meant in point 2 was...

Say you have a point at X,Y-coordinate 4,5. Think about the array as in rows and columns for a second.

Point 4,5 is in row 4 and column 5. Check Row 4 for other points.
Also check column 5 for other points.

Say you are using a 20 by 20 array.

For X goes from 1 to 20
{ Y = 5
look for point other than this point (being 4)
If found then
{
Measure distance from 4
Check for a third point, equidistant from 4,5 in column 4.
}
}

So for example, say you have a point 4,5 and a point at 10,5.

The above algorithm would go from 1 to 20.
At 10 it would find a point.
10 - 4 would equal 6.
It would look for a point at 4,11.
If found then you look for the 4th point of the square.

Hope that helps. Feel free to ask again if I didn't make sense.
10. No Profile Picture
Junior Member
Devshed Newbie (0 - 499 posts)

Join Date
Jun 2002
Posts
9
Rep Power
0
hi !
the user can only select one point ahead from the current seletc point
lets say user selects point 20,20

now after selcting 20 ,20 user is restricted to select only these points

20,25 ( down cursor key )
20,15 ( up cursor key )
15,20 ( left cursor key )
25.20 ( rigt cursor key )

where 5 is the distance between every row and coloum

now lets say user selects a point 20,25 ( down cursor key )
now a line is drawn from 20,20 to 20,25 ,

now user can agin slect any point after selcting any point the user is agian restrced to select any four points (up ,down,right and left )
and again a ine is drwan between the first point selected and the second point slect and so on the user can draw lines all over the screen

now let say user select point 20,20
now there are four possiblities for making a saqure a saqure can be made to left ,right , up , and down right ?
so how will i know where did the user made the saqure and also if the saqure already made the saqure and user trys to make a another saqure over the current how will i stop the user ?

suhailkaleem
11. No Profile Picture
Junior Member
Devshed Newbie (0 - 499 posts)

Join Date
Apr 2002
Location
Detroit, MI
Posts
14
Rep Power
0
Originally posted by suhailkaleem
now let say user select point 20,20
now there are four possiblities for making a saqure a saqure can be made to left ,right , up , and down right ?
so how will i know where did the user made the saqure and also if the saqure already made the saqure and user trys to make a another saqure over the current how will i stop the user ?

suhailkaleem
After the user inserts any point, you run a function which checks the entire board for squares.

So even if you start at 20,20... and you don't know which way they are going to make the square, it won't matter. Just write a function which checks the entire board for squares.

As for what if the user tries to make another square over the currect one... well I believe the algorithm I provided will find all the squares possible, even ones that begin at the same point.

What code do you have thus far that works and I don't quite follow you when you say if you start at 20,20 the user can only put more points at 20,25 or 20,15 or 15,20... can't the user place points anywhere on the board?
12. No Profile Picture
Junior Member
Devshed Newbie (0 - 499 posts)

Join Date
Jun 2002
Posts
9
Rep Power
0
mail sent to you with code
let me know if there is some problem

suhailkaleem
13. Why don't you just ask someone to write the code for you? Seems that's what you're looking for anyway.

For any 4 points selected

A = X1, Y1
B = X2, Y2
C = X3, Y3
D = X4, Y4

Compare the X value of point A to the other 3 points.

There should be only 1 other point with the same X value. If this is not true you do not have a square, stop here.

If it is true compare the Y value of point A to the other 3 points. Again, this should be true in only 1 case and should not be the point containing the same X value as found above.

This is what is known at this time.

A = X1, Y1
B = X1, ?
C = ?, Y1
D = ?, ?

Check the X value of C and D. If they are the same proceed.

Check the Y value of B and D. If they are the same proceed.

From what I've read I think that will suffice for your needs. If it's possible for the user to pick non-consecutive points you'll have to check the length of the sides and possibly the slope.

It would also be helpful if you shared your code here for everyone to take a look at.
14. No Profile Picture
Junior Member
Devshed Newbie (0 - 499 posts)

Join Date
Apr 2002
Location
Detroit, MI
Posts
14
Rep Power
0
Wow, I didn't even think of squares that were made on diagonals... that definitely complicates the problem.

I wish I could help further, but alas, I don't have a C compiler and I'm quite busy starting a new job...

If this is for a class (which I figure it is), it might be best to find a friend and work in groups. Thats what basically got me through my upper level comp sci classes.

Good luck!
15. In the final months of my schooling I spent so much time at my friends house that his wife offered to make up a bed for me.
Page 1 of 2 12 Last