【发布时间】:2020-02-14 12:46:32
【问题描述】:
我正在开发一个应用程序来检查绘制是否对称。所有用户行都存储在一个由点列表组成的 ArrayList 中,也是结构化的:
private ArrayList<ArrayList<Pair<Float,Float>>> segments = new ArrayList<>();
黑色形状是背景的一部分,当我必须检查对称性时,我不需要考虑它。我只需要它的中心(我将其存储为单个坐标),因为我需要考虑通过它检查对称性。由于绘画是由儿童绘制的,因此我还需要考虑一些灵活性,因为线条永远不会完全对称。我实现了一个方法,将每个部分分成 10 个部分,然后检查每个部分的坐标是否有相似的增加/减少:
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;
}
如果至少对 6 个部分进行了验证,那么我可以认为这些段是对称的。这种方法的巨大问题是线条可以有不同的大小。你知道计算绘图区域对称性的任何方法吗?由于我将图片保存为位图,所以我也尝试了直接在图片文件上计算的方法,但是没有找到
【问题讨论】:
-
您在寻找什么样的对称性?你提到了一个中心。那么它是关于已知中心的点反射吗?
-
您的示例有几条曲线,但您的数据结构仅存储两个点,这意味着您只有直线。
-
@NicoSchertler 是的,我正在寻找关于黑色形状中心的点反射
-
@Code-Apprentice 将曲线逐点存储到ArrayList中
-
@Babbara 所以ArrayList基本上代表了很多小线段来组成曲线?
标签: java android math geometry symmetric