use of imagingbook.pub.geometry.basic.Pnt2d in project imagingbook-common by imagingbook.
the class ParametricLine method main.
// --------------------------
public static void main(String[] args) {
Pnt2d p1 = Pnt2d.from(1, 2);
Pnt2d p2 = Pnt2d.from(4, 3);
AlgebraicLine al1 = AlgebraicLine.from(p1, p2);
System.out.println("al1 = " + al1);
ParametricLine pl = ParametricLine.from(al1);
System.out.println("pl = " + pl);
AlgebraicLine al2 = AlgebraicLine.from(pl);
System.out.println("al2 = " + al2);
System.out.println("al1 = al2 ? " + al1.equals(al2));
}
use of imagingbook.pub.geometry.basic.Pnt2d in project imagingbook-common by imagingbook.
the class ProcrustesFit method makeDataMatrix.
private RealMatrix makeDataMatrix(Pnt2d[] points, double[] meanX) {
RealMatrix M = MatrixUtils.createRealMatrix(2, points.length);
RealVector mean = MatrixUtils.createRealVector(meanX);
int i = 0;
for (Pnt2d p : points) {
RealVector cv = p.toRealVector();
// RealVector cv = MatrixUtils.createRealVector(p.toDoubleArray());
if (meanX != null) {
cv = cv.subtract(mean);
}
M.setColumnVector(i, cv);
i++;
}
return M;
}
use of imagingbook.pub.geometry.basic.Pnt2d in project imagingbook-common by imagingbook.
the class ProcrustesFit method getMeanVec.
private double[] getMeanVec(Pnt2d[] points) {
double sumX = 0;
double sumY = 0;
for (Pnt2d p : points) {
sumX = sumX + p.getX();
sumY = sumY + p.getY();
}
return new double[] { sumX / points.length, sumY / points.length };
}
use of imagingbook.pub.geometry.basic.Pnt2d in project imagingbook-common by imagingbook.
the class ProjectiveMapping2D method main.
// -----------------------------------------------------------------
/**
* For testing only.
* @param args ignored
*/
public static void main(String[] args) {
PrintPrecision.set(6);
// book example:
Pnt2d[] P = { PntDouble.from(2, 5), PntDouble.from(4, 6), PntDouble.from(7, 9), PntDouble.from(5, 9), // 5 points, overdetermined!
PntDouble.from(5.2, 9.1) };
Pnt2d[] Q = { PntDouble.from(4, 3), PntDouble.from(5, 2), PntDouble.from(9, 3), PntDouble.from(7, 5), // 5 points, overdetermined!
PntDouble.from(7, 4.9) };
ProjectiveMapping2D pm = ProjectiveMapping2D.fromPoints(P, Q);
System.out.println("\nprojective mapping = \n" + pm.toString());
for (int i = 0; i < P.length; i++) {
Pnt2d Bi = pm.applyTo(P[i]);
System.out.println(P[i].toString() + " -> " + Bi.toString());
}
System.out.println("pm is of class " + pm.getClass().getName());
ProjectiveMapping2D pmi = pm.getInverse();
pmi = pmi.normalize();
System.out.println("\ninverse projective mapping (normalized) = \n" + pmi.toString());
for (int i = 0; i < Q.length; i++) {
Pnt2d Ai = pmi.applyTo(Q[i]);
System.out.println(Q[i].toString() + " -> " + Ai.toString());
}
ProjectiveMapping2D testId = pm.concat(pmi);
System.out.println("\ntest: should be a scaled identity matrix: = \n" + testId.toString());
}
use of imagingbook.pub.geometry.basic.Pnt2d in project imagingbook-common by imagingbook.
the class LinearFit2D method calculateError.
public default double calculateError(Pnt2d[] P, Pnt2d[] Q, RealMatrix A) {
final int m = Math.min(P.length, Q.length);
LinearMapping2D map = new LinearMapping2D(A.getData());
double errSum = 0;
for (int i = 0; i < m; i++) {
Pnt2d p = P[i];
Pnt2d q = Q[i];
Pnt2d pp = map.applyTo(p);
double e = q.distance(pp);
errSum = errSum + e * e;
}
return Math.sqrt(errSum);
}
Aggregations