diff --git a/main/src/georegression/fitting/cylinder/CylinderToPointSignedDistance_F64.java b/main/src/georegression/fitting/cylinder/CylinderToPointSignedDistance_F64.java index 4e3f8330..b0b70164 100644 --- a/main/src/georegression/fitting/cylinder/CylinderToPointSignedDistance_F64.java +++ b/main/src/georegression/fitting/cylinder/CylinderToPointSignedDistance_F64.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2020, Peter Abeles. All Rights Reserved. + * Copyright (C) 2022, Peter Abeles. All Rights Reserved. * * This file is part of Geometric Regression Library (GeoRegression). * @@ -31,7 +31,7 @@ /** * Computes the signed Euclidean distance between a cylinder and a set of points, see - * {@link Distance3D_F64#distance(georegression.struct.shapes.Cylinder3D_F64, georegression.struct.point.Point3D_F64)}. + * {@link Distance3D_F64#distanceSigned(georegression.struct.shapes.Cylinder3D_F64, georegression.struct.point.Point3D_F64)}. * * See {@link CodecCylinder3D_F64} for how the model is parametrized. * diff --git a/main/src/georegression/fitting/cylinder/PointNormalDistanceFromCylinder_F64.java b/main/src/georegression/fitting/cylinder/PointNormalDistanceFromCylinder_F64.java index 9c41fa2d..3a9a007b 100644 --- a/main/src/georegression/fitting/cylinder/PointNormalDistanceFromCylinder_F64.java +++ b/main/src/georegression/fitting/cylinder/PointNormalDistanceFromCylinder_F64.java @@ -41,13 +41,13 @@ public void setModel( Cylinder3D_F64 plane ) { @Override public /**/double distance( PlaneNormal3D_F64 point ) { - return Math.abs(Distance3D_F64.distance(cylinder, point.p)); + return Math.abs(Distance3D_F64.distanceSigned(cylinder, point.p)); } @Override public void distances( List list, /**/double[] errors ) { for (int i = 0; i < list.size(); i++) { - errors[i] = Math.abs(Distance3D_F64.distance(cylinder, list.get(i).p)); + errors[i] = Math.abs(Distance3D_F64.distanceSigned(cylinder, list.get(i).p)); } } diff --git a/main/src/georegression/fitting/sphere/SphereToPointSignedDistance_F64.java b/main/src/georegression/fitting/sphere/SphereToPointSignedDistance_F64.java index f9a37e2f..c30d5ad4 100644 --- a/main/src/georegression/fitting/sphere/SphereToPointSignedDistance_F64.java +++ b/main/src/georegression/fitting/sphere/SphereToPointSignedDistance_F64.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2020, Peter Abeles. All Rights Reserved. + * Copyright (C) 2022, Peter Abeles. All Rights Reserved. * * This file is part of Geometric Regression Library (GeoRegression). * @@ -27,7 +27,7 @@ /** * Computes the signed Euclidean distance between a sphere and a set of points, see - * {@link Distance3D_F64#distance(georegression.struct.shapes.Sphere3D_F64, georegression.struct.point.Point3D_F64)}. + * {@link Distance3D_F64#distanceSigned(georegression.struct.shapes.Sphere3D_F64, georegression.struct.point.Point3D_F64)}. * * See {@link georegression.fitting.sphere.CodecSphere3D_F64} for how the model is parametrized. * For use in least-squares non-linear minimization. @@ -65,7 +65,7 @@ public void process( /**/double[] input, /**/double[] output) { codec.decode(input,sphere); for( int i = 0; i < points.size(); i++ ) { - output[i] = Distance3D_F64.distance(sphere,points.get(i)); + output[i] = Distance3D_F64.distanceSigned(sphere,points.get(i)); } } } diff --git a/main/src/georegression/metric/Distance3D_F64.java b/main/src/georegression/metric/Distance3D_F64.java index 07dcdac4..c0eecf57 100644 --- a/main/src/georegression/metric/Distance3D_F64.java +++ b/main/src/georegression/metric/Distance3D_F64.java @@ -42,8 +42,7 @@ public class Distance3D_F64 { * @param l1 Second line. Not modified. * @return Distance between the closest point on both lines. */ - public static double distance( LineParametric3D_F64 l0, - LineParametric3D_F64 l1 ) { + public static double distance( LineParametric3D_F64 l0, LineParametric3D_F64 l1 ) { double x = l0.p.x - l1.p.x; double y = l0.p.y - l1.p.y; double z = l0.p.z - l1.p.z; @@ -86,10 +85,22 @@ public static double distance( LineParametric3D_F64 l0, * @return distance. */ public static double distance( LineParametric3D_F64 l, Point3D_F64 p ) { + return distance(l, p.x, p.y, p.z); + } - double x = l.p.x - p.x; - double y = l.p.y - p.y; - double z = l.p.z - p.z; + /** + * Distance from the point to the closest point on the line. + * + * @param l Line. Not modified. + * @param px x-axis coordinate of point + * @param py y-axis coordinate of point + * @param pz z-axis coordinate of point + * @return distance. + */ + public static double distance( LineParametric3D_F64 l, double px, double py, double pz ) { + double x = l.p.x - px; + double y = l.p.y - py; + double z = l.p.z - pz; double cc = x*x + y*y + z*z; @@ -115,8 +126,7 @@ public static double distance( LineParametric3D_F64 l, Point3D_F64 p ) { * @param p Point. Not modified. * @return distance. */ - public static double distance( LineSegment3D_F64 l, - Point3D_F64 p ) { + public static double distance( LineSegment3D_F64 l, Point3D_F64 p ) { double dx = p.x - l.a.x; double dy = p.y - l.a.y; @@ -163,35 +173,40 @@ public static double distanceSigned( PlaneGeneral3D_F64 plane, Point3D_F64 point } /** + *

* Returns the signed distance a point is from the sphere's surface. If the point is outside of the sphere * it's distance will be positive. If it is inside it will be negative. - *

+ *

* distance = ||sphere.center - point|| - r * * @param sphere The sphere * @param point The point * @return Signed distance */ - public static double distance( Sphere3D_F64 sphere, Point3D_F64 point ) { + public static double distanceSigned( Sphere3D_F64 sphere, Point3D_F64 point ) { double r = point.distance(sphere.center); return r - sphere.radius; } /** - * Returns the signed distance a point is from the cylinder's surface. If the point is outside of the cylinder + * Returns the signed distance a point is from the cylinder's surface. If the point is outside the cylinder * it's distance will be positive. If it is inside it will be negative. * * @param cylinder The cylinder * @param point The point * @return Signed distance */ - public static double distance( Cylinder3D_F64 cylinder, Point3D_F64 point ) { - double r = Distance3D_F64.distance(cylinder.line, point); + public static double distanceSigned( Cylinder3D_F64 cylinder, Point3D_F64 point ) { + return distanceSigned(cylinder, point.x, point.y, point.z); + } + + public static double distanceSigned( Cylinder3D_F64 cylinder, double px, double py, double pz ) { + double r = Distance3D_F64.distance(cylinder.line, px, py, pz); return r - cylinder.radius; } /** - * Signed distance from a 3D point to 3D triangle. The sign indicates which side of the triangle the point + * Signed distance from a 3D point to 3D triangle. The sign indicates which side of the triangle the point * is on. See {@link georegression.metric.alg.DistancePointTriangle3D_F64} for the details. * * @param triangle 3D triangle @@ -199,11 +214,10 @@ public static double distance( Cylinder3D_F64 cylinder, Point3D_F64 point ) { * @return The closest point */ public static double distance( Triangle3D_F64 triangle, Point3D_F64 point ) { - - DistancePointTriangle3D_F64 alg = new DistancePointTriangle3D_F64(); + var alg = new DistancePointTriangle3D_F64(); alg.setTriangle(triangle.v0, triangle.v1, triangle.v2); - Point3D_F64 cp = new Point3D_F64(); + var cp = new Point3D_F64(); alg.closestPoint(point, cp); diff --git a/main/test/georegression/fitting/TestShapeFittingRobustOps.java b/main/test/georegression/fitting/TestShapeFittingRobustOps.java index c3219cd6..05663594 100644 --- a/main/test/georegression/fitting/TestShapeFittingRobustOps.java +++ b/main/test/georegression/fitting/TestShapeFittingRobustOps.java @@ -142,7 +142,7 @@ class TestShapeFittingRobustOps { // See if the points lie on the found plane, except for the outlier int count = 0; for (int i = 0; i < points.size(); i++) { - if (Math.abs(Distance3D_F64.distance(found, points.get(i).p)) < 1) { + if (Math.abs(Distance3D_F64.distanceSigned(found, points.get(i).p)) < 1) { count++; } } @@ -165,7 +165,7 @@ class TestShapeFittingRobustOps { // See if the points lie on the found plane, except for the outlier int count = 0; for (int i = 0; i < points.size(); i++) { - if (Math.abs(Distance3D_F64.distance(found, points.get(i).p)) < 1) { + if (Math.abs(Distance3D_F64.distanceSigned(found, points.get(i).p)) < 1) { count++; } } diff --git a/main/test/georegression/fitting/cylinder/TestCylinderToPointSignedDistance_F64.java b/main/test/georegression/fitting/cylinder/TestCylinderToPointSignedDistance_F64.java index f59b3408..2b553d64 100644 --- a/main/test/georegression/fitting/cylinder/TestCylinderToPointSignedDistance_F64.java +++ b/main/test/georegression/fitting/cylinder/TestCylinderToPointSignedDistance_F64.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2020, Peter Abeles. All Rights Reserved. + * Copyright (C) 2022, Peter Abeles. All Rights Reserved. * * This file is part of Geometric Regression Library (GeoRegression). * @@ -63,7 +63,7 @@ void compareToDistance() { alg.process(param,output); for( int i = 0; i < points.size(); i++ ) { - double expected = Distance3D_F64.distance(cylinder, points.get(i)); + double expected = Distance3D_F64.distanceSigned(cylinder, points.get(i)); assertEquals(expected,(double) output[i], GrlConstants.TEST_F64); } } diff --git a/main/test/georegression/fitting/cylinder/TestGenerateCylinderFromPointNormals_F64.java b/main/test/georegression/fitting/cylinder/TestGenerateCylinderFromPointNormals_F64.java index c203ebb3..d884d1ff 100644 --- a/main/test/georegression/fitting/cylinder/TestGenerateCylinderFromPointNormals_F64.java +++ b/main/test/georegression/fitting/cylinder/TestGenerateCylinderFromPointNormals_F64.java @@ -57,14 +57,14 @@ class TestGenerateCylinderFromPointNormals_F64 { PlaneNormal3D_F64 p1 = paramToPointOnCylinder(cylinder, rand.nextGaussian(), theta + Math.PI/2.0); // Sanity check - assertEquals(0.0, Distance3D_F64.distance(cylinder, p0.p), UtilEjml.TEST_F64); - assertEquals(0.0, Distance3D_F64.distance(cylinder, p1.p), UtilEjml.TEST_F64); + assertEquals(0.0, Distance3D_F64.distanceSigned(cylinder, p0.p), UtilEjml.TEST_F64); + assertEquals(0.0, Distance3D_F64.distanceSigned(cylinder, p1.p), UtilEjml.TEST_F64); assertTrue(alg.generate(List.of(p0, p1), found)); // Verify the found cylinder is correct by seeing if the two points lie on it - assertEquals(0.0, Distance3D_F64.distance(found, p0.p), UtilEjml.TEST_F64); - assertEquals(0.0, Distance3D_F64.distance(found, p1.p), UtilEjml.TEST_F64); + assertEquals(0.0, Distance3D_F64.distanceSigned(found, p0.p), UtilEjml.TEST_F64); + assertEquals(0.0, Distance3D_F64.distanceSigned(found, p1.p), UtilEjml.TEST_F64); } } diff --git a/main/test/georegression/fitting/sphere/TestSphereToPointSignedDistance_F64.java b/main/test/georegression/fitting/sphere/TestSphereToPointSignedDistance_F64.java index b577a9b6..e4a45aad 100644 --- a/main/test/georegression/fitting/sphere/TestSphereToPointSignedDistance_F64.java +++ b/main/test/georegression/fitting/sphere/TestSphereToPointSignedDistance_F64.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2020, Peter Abeles. All Rights Reserved. + * Copyright (C) 2022, Peter Abeles. All Rights Reserved. * * This file is part of Geometric Regression Library (GeoRegression). * @@ -60,7 +60,7 @@ void compareToDistance() { alg.process(param,output); for( int i = 0; i < points.size(); i++ ) { - double expected = Distance3D_F64.distance(sphere,points.get(i)); + double expected = Distance3D_F64.distanceSigned(sphere,points.get(i)); assertEquals(expected,(double) output[i], GrlConstants.TEST_F64); } } diff --git a/main/test/georegression/metric/TestDistance3D_F64.java b/main/test/georegression/metric/TestDistance3D_F64.java index 7d81ab7e..f6d2fa23 100644 --- a/main/test/georegression/metric/TestDistance3D_F64.java +++ b/main/test/georegression/metric/TestDistance3D_F64.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020, Peter Abeles. All Rights Reserved. + * Copyright (C) 2022, Peter Abeles. All Rights Reserved. * * This file is part of Geometric Regression Library (GeoRegression). * @@ -159,8 +159,8 @@ void distance_sphere_point() { assertTrue(ro>4.5); assertTrue(ri<4.5); - assertEquals(ro-4.5,Distance3D_F64.distance(sphere,outside), GrlConstants.TEST_F64); - assertEquals(ri-4.5,Distance3D_F64.distance(sphere,inside), GrlConstants.TEST_F64); + assertEquals(ro-4.5,Distance3D_F64.distanceSigned(sphere,outside), GrlConstants.TEST_F64); + assertEquals(ri-4.5,Distance3D_F64.distanceSigned(sphere,inside), GrlConstants.TEST_F64); } @Test @@ -176,8 +176,8 @@ void distance_cylinder_point() { assertTrue(ro>3.5); assertTrue(ri<3.5); - assertEquals(ro-3.5,Distance3D_F64.distance(cylinder,outside), GrlConstants.TEST_F64); - assertEquals(ri-3.5,Distance3D_F64.distance(cylinder,inside), GrlConstants.TEST_F64); + assertEquals(ro-3.5,Distance3D_F64.distanceSigned(cylinder,outside), GrlConstants.TEST_F64); + assertEquals(ri-3.5,Distance3D_F64.distanceSigned(cylinder,inside), GrlConstants.TEST_F64); } @Test