I'm developing an app to check if a draw is symmetric or not. All the users line are stored into an ArrayList composed by a list of points, structured as well:
private ArrayList<ArrayList<Pair<Float,Float>>> segments = new ArrayList<>();
This is how I build the drawing area:
The black shape is part of the background and I don't need to consider it when I have to check the symmetry. I only need its center (which I store as a single coordinate) since I need to consider checking the symmetry by it. Since the draws are made by children, I also need to consider a bit of flexibility since the lines will never be exactly symmetric. I implemented a method which divides each segments in 10 parts and then check if the coordinates of each part have a similare increase/decrease:
private boolean checkShape (int z, ArrayList<Pair<Float,Float>> points) {
ArrayList<Pair<Float,Float>> copia = segments.get(z);
int nGroupsFirstShape = (segments.get(z).size()*10)/100;
int nValuesFirstShape[] = new int[10];
for (int j=0, j2=0; j<10; j++, j2+=nGroupsFirstShape) {
int sumValues=0;
sumValues+=copia.get(j2).first-copia.get(j2+nGroupsFirstShape-1).first;
sumValues+=copia.get(j2).second-copia.get(j2+nGroupsFirstShape-1).second;
nValuesFirstShape[j] = sumValues;
}
ArrayList<Pair<Float,Float>> copia2 = points;
int nGroupSecondShape = (copia2.size()*10)/100;
int nValuesSecondShape[] = new int[10];
for (int j=0, j2=0; j<10; j++, j2+=nGroupSecondShape) {
int sumValues=0;
sumValues+=copia2.get(j2).first-copia2.get(j2+nGroupSecondShape-1).first;
sumValues+=copia2.get(j2).second-copia2.get(j2+nGroupSecondShape-1).second;
nValuesSecondShape[j] = sumValues;
}
int differences[] = new int[10];
int numberOf = 0;
for (int index=0; index<10; index++) {
differences[index] = nValuesFirstShape[index] - nValuesSecondShape[index];
if (differences[index]<0) differences[index] = -differences[index];
if (differences[index]<nGroupsFirstShape*2.5) numberOf++;
}
if (numberOf>=6) return true; else return false;
}
If this is verified for at least 6 parts, then I can considerer the segments symmetric. The huge problem of this method is that the lines can have different sizes. Do you know any methods to calculate the symmetry of a drawing area? Since I save the image as a bitmap, I also tried to find a method to calculate it directly on the image file, but I didn't find anything