Matthew F. answered 04/06/19
Professional Software/ Web Developer Specializing in Java
I would recommend GeoRegression, seems to be what you're looking for.
Geometric Regression Library (GeoRegression) is an open source Java geometry library for scientific computing with a focus on 2D/3D space. GeoRegression provides the ability to estimate the closest point/distance between geometric primitives, best-fit shapes, and best fit geometric transform between sets of objects
Examples of shapes that can be defined, both 2D and 3D.
http://georegression.org/javadoc/
3D might be possible through some abstract means with this library, so I'd look into it, but it would be oblique as all get out.