We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › How to write an array contains another array
Page Index Toggle Pages: 1
How to write an array contains another array? (Read 940 times)
How to write an array contains another array?
Sep 18th, 2009, 5:26am
 
Hi~
I want to judge whether a pattern which comprising 4 points is symmetrical.
What I think is translate 4 points as below:
 //(x, y)  -> (y, -x) 90 degrees
 //(x, y) -> (-x, -y) 180 degrees
 //(x, y) -> (-y, x) 270 degrees
 //(x, y) -> (x, -y) x axis
 //(x, y) -> (-x, y) y axis
 //(x, y) -> (-y, -x) diagonal\
 //(x, y) -> (-y, x) diagonal/
then, I get a new set of points:
{(x1,y1),(x2,y2),(x3,y3),(x4,y4)} -> {(x1',y1'),(x2',y2'),(x3',y3'),(x4',y4')}
After that I can compare this 2 sets of points, to see whether they coincide.

But I don't know how the syntax could be. Is it possible to write an array with 4 elements that contains another array with 2 elements?
Or is there a better way to figure out whether the pattern is symmetrical?
Re: How to write an array contains another array?
Reply #1 - Sep 18th, 2009, 5:48am
 
Not quite sure what you mean by "symmetrical" points. Could you give at least one example of a symmetrical set of points and also at least one example of a set of points that is not symmetrical?
Re: How to write an array contains another array?
Reply #2 - Sep 18th, 2009, 6:09am
 
For the first question at least, the answer is simple:
Code:
int[][] points = { { 1, 2}, {3, 4}, {5, 6}, {7, 8} }; 

Re: How to write an array contains another array?
Reply #3 - Sep 18th, 2009, 6:18am
 
Sorry to forget mentioning that all the points is in a coordinate system with boundary.
Suppose there're 4 points{ (-2,2) (2,2) (-2,-2) (2,-2)}, which composed a square that is symmetrical.
but if the 4 points are {(-2,1) (1,1) ((2,-1) (1,-2)}, then it's not symmetrical.
Re: How to write an array contains another array?
Reply #4 - Sep 18th, 2009, 6:23am
 
PhiLho  wrote on Sep 18th, 2009, 6:09am:
For the first question at least, the answer is simple:
Code:
int[][] points = { { 1, 2}, {3, 4}, {5, 6}, {7, 8} }; 



I want to write something like this:

int [] apoint = new int[2]
int [] [] points= new int [4] [ apoint[] ]

I know it's probably not correct, but I hope it make what I want clearer.
Re: How to write an array contains another array?
Reply #5 - Sep 18th, 2009, 7:19am
 
Code:
int[][] points = new int[4][2]; 

Page Index Toggle Pages: 1