private void curveArrayValues(Adaptor3d_Curve curve, int size, double u[]) { for (int i = 0; i < size; i++) { gp_Pnt gp = curve.Value(u[3 * i]); u[3 * i] = gp.X(); u[3 * i + 1] = gp.Y(); u[3 * i + 2] = gp.Z(); } }
public boolean move(int i, double[] xyz) { boolean ret = false; double l1 = Math.sqrt( (xyz[3 * i] - xyz[3 * i - 3]) * (xyz[3 * i] - xyz[3 * i - 3]) + (xyz[3 * i + 1] - xyz[3 * i - 2]) * (xyz[3 * i + 1] - xyz[3 * i - 2]) + (xyz[3 * i + 2] - xyz[3 * i - 1]) * (xyz[3 * i + 2] - xyz[3 * i - 1])); double l2 = Math.sqrt( (xyz[3 * i] - xyz[3 * i + 3]) * (xyz[3 * i] - xyz[3 * i + 3]) + (xyz[3 * i + 1] - xyz[3 * i + 4]) * (xyz[3 * i + 1] - xyz[3 * i + 4]) + (xyz[3 * i + 2] - xyz[3 * i + 5]) * (xyz[3 * i + 2] - xyz[3 * i + 5])); double a1 = length(a[i - 1], a[i], 20); double a2 = length(a[i], a[i + 1], 20); double d1 = (a1 - l1) / a1; double d2 = (a2 - l2) / a2; double d3 = (a1 + a2 - l1 - l2) / (a1 + a2); double delta = Math.abs(d2 - d1); if (delta > 0.05 * d3) { double newA = a[i] + 0.8 * (a[i + 1] - a[i - 1]) * (l2 - l1) / (l1 + l2); // double [] newXYZ = curve.Value(newA); gp_Pnt pt = curve.Value(newA); double[] newXYZ = new double[] {pt.X(), pt.Y(), pt.Z()}; l1 = Math.sqrt( (newXYZ[0] - xyz[3 * i - 3]) * (newXYZ[0] - xyz[3 * i - 3]) + (newXYZ[1] - xyz[3 * i - 2]) * (newXYZ[1] - xyz[3 * i - 2]) + (newXYZ[2] - xyz[3 * i - 1]) * (newXYZ[2] - xyz[3 * i - 1])); l2 = Math.sqrt( (newXYZ[0] - xyz[3 * i + 3]) * (newXYZ[0] - xyz[3 * i + 3]) + (newXYZ[1] - xyz[3 * i + 4]) * (newXYZ[1] - xyz[3 * i + 4]) + (newXYZ[2] - xyz[3 * i + 5]) * (newXYZ[2] - xyz[3 * i + 5])); a1 = length(a[i - 1], newA, 20); a2 = length(newA, a[i + 1], 20); d1 = (a1 - l1) / a1; d2 = (a2 - l2) / a2; if (Math.abs(d2 - d1) < delta) { ret = true; a[i] = newA; xyz[3 * i] = newXYZ[0]; xyz[3 * i + 1] = newXYZ[1]; xyz[3 * i + 2] = newXYZ[2]; } } return ret; }
public boolean move(int i, double[] xyz) { boolean ret = false; double l1 = Math.sqrt( (xyz[3 * i] - xyz[3 * i - 3]) * (xyz[3 * i] - xyz[3 * i - 3]) + (xyz[3 * i + 1] - xyz[3 * i - 2]) * (xyz[3 * i + 1] - xyz[3 * i - 2]) + (xyz[3 * i + 2] - xyz[3 * i - 1]) * (xyz[3 * i + 2] - xyz[3 * i - 1])); double l2 = Math.sqrt( (xyz[3 * i] - xyz[3 * i + 3]) * (xyz[3 * i] - xyz[3 * i + 3]) + (xyz[3 * i + 1] - xyz[3 * i + 4]) * (xyz[3 * i + 1] - xyz[3 * i + 4]) + (xyz[3 * i + 2] - xyz[3 * i + 5]) * (xyz[3 * i + 2] - xyz[3 * i + 5])); double delta = Math.abs(l2 - l1); if (delta > 0.05 * (l1 + l2)) { double newA = a[i] + 0.8 * (a[i + 1] - a[i - 1]) * (l2 - l1) / (l1 + l2); // double [] newXYZ = curve.Value(newA); gp_Pnt pt = curve.Value(newA); double[] newXYZ = new double[] {pt.X(), pt.Y(), pt.Z()}; double newl1 = Math.sqrt( (newXYZ[0] - xyz[3 * i - 3]) * (newXYZ[0] - xyz[3 * i - 3]) + (newXYZ[1] - xyz[3 * i - 2]) * (newXYZ[1] - xyz[3 * i - 2]) + (newXYZ[2] - xyz[3 * i - 1]) * (newXYZ[2] - xyz[3 * i - 1])); double newl2 = Math.sqrt( (newXYZ[0] - xyz[3 * i + 3]) * (newXYZ[0] - xyz[3 * i + 3]) + (newXYZ[1] - xyz[3 * i + 4]) * (newXYZ[1] - xyz[3 * i + 4]) + (newXYZ[2] - xyz[3 * i + 5]) * (newXYZ[2] - xyz[3 * i + 5])); if (Math.abs(newl2 - newl1) < delta) { ret = true; a[i] = newA; xyz[3 * i] = newXYZ[0]; xyz[3 * i + 1] = newXYZ[1]; xyz[3 * i + 2] = newXYZ[2]; } } return ret; }