ini.trakem2.utils

## Class M

• ```public final class M
extends Object```
TrakEM2's mathematician.
• ### Constructor Summary

Constructors
Constructor and Description
`M()`
• ### Method Summary

All Methods
Modifier and Type Method and Description
`static void` ```appendShortest(float f, float precision, StringBuilder sb)```
Appends to @param sb the shortest possible String representation of a float number, according to the desired decimal @param precision.
`static void` ```apply(CoordinateTransform ict, Area roi, Area a)```
Apply in place the @param ict to the Area @param a, but only for the part that intersects the roi.
`static void` ```apply(CoordinateTransform ict, double[][] p, int i, double[] fp)```
Reuses the @param fp to apply in place.
`static void` ```apply(VectorDataTransform vdt, Area a)```
`static void` ```apply(VectorDataTransform vdt, Area a, boolean remove_outside)```
Parts of @param a not intersected by any of @param vdt rois will be left untouched if @param remove_outside is false.
`static Area` `areaInInts(Area area)`
Converts all points in @param area to ints by casting.
`static Area` `areaInIntsByRounding(Area area)`
Converts all points in @param area to ints by rounding.
`static VectorString2D` ```asVectorString2D(Polygon pol, double z)```
`static float[]` ```computeSegmentsIntersection(float ax0, float ay0, float ax1, float ay1, float bx0, float by0, float bx1, float by1)```
`static void` ```convolveGaussianSigma1(float[] in, float[] out, CircularSequence seq)```
`static Shape` ```createArrowhead(double x1, double y1, double x2, double y2)```
Create an arrowhead at the end of the line segment defined by x1,y1 and x2,y2.
`static Shape` ```createArrowhead(double x1, double y1, double x2, double y2, double magnification)```
`static List<Point3f>` ```createIcosahedron(int subdivisions, float radius)```
Returns a "3D Viewer"-ready list mesh, centered at 0,0,0 and with radius as the radius of the enclosing sphere.
`static ij.process.FloatPolygon` ```createInterpolatedPolygon(ij.process.FloatPolygon p, double interval, boolean isLine)```
Copied from ImageJ's ij.gui.PolygonRoi.getInterpolatedPolygon, by Wayne Rasband and collaborators.
`static double` ```distance(double x1, double y1, double x2, double y2)```
`static double` ```distance(double x1, double y1, double z1, double x2, double y2, double z2)```
`static double` ```distance(Tuple3d t1, Tuple3d t2)```
`static double` ```distancePointToLine(double px, double py, double lx1, double ly1, double lx2, double ly2)```
For a point px,py return its distance to a line defined by points lx1,ly1 and lx2,ly2.
`static double` ```distancePointToLine(double px, double py, double pz, double lx1, double ly1, double lz1, double lx2, double ly2, double lz2)```
In 3D
`static double` ```distancePointToSegment(double px, double py, double lx1, double ly1, double lx2, double ly2)```
For a point px,py return its distance to a line SEGMENT defined by points lx1,ly1 and lx2,ly2.
`static double` ```distancePointToSegment(double px, double py, double pz, double lx1, double ly1, double lz1, double lx2, double ly2, double lz2)```
`static double` ```distancePointToSegment(Vector3d p, Vector3d v1, Vector3d v2)```
Minimum distance between point v0 and a line segment defined by points v1 and v2.
`static double` ```distancePointToSegmentSq(double px, double py, double pz, double lx1, double ly1, double lz1, double lx2, double ly2, double lz2)```
`static double` ```distancePointToSegmentSq(Vector3d p, Vector3d v1, Vector3d v2)```
`static double` ```distanceSq(double x1, double y1, double z1, double x2, double y2, double z2)```
`static double` ```distanceSq(Tuple3d t1, Tuple3d t2)```
`static boolean` ```equals(double a, double b)```
`static Polygon` ```findPath(Area area, int x, int y)```
Detect if a point is not in the area, but lays inside one of its path, which is returned as a Polygon.
`static double` ```getAngle(double x, double y)```
Returns the angle in radians of the given polar coordinates, correcting the Math.atan2 output.
`static Area` `getArea(Roi roi)`
`static Area` `getArea(ShapeRoi sroi)`
`static Collection<Polygon>` `getPolygons(Area area)`
`static Collection<Polygon>` `getPolygonsByRounding(Area area)`
`static boolean` ```intersects(Area a1, Area a2)```
Test whether the areas intersect each other.
`static Point2D.Double` ```inverseTransform(AffineTransform affine, double x, double y)```
`static boolean` `isAreaROI(Roi roi)`
Returns true if the roi is of closed shape type like an OvalRoi, ShapeRoi, a Roi rectangle, etc.
`static boolean` `isEmpty(Area area)`
`static double` ```lateralAreaOfTruncatedCone(double r1, double r2, double height)```
`static double` ```measureArea(Area area, Loader loader)```
Returns the approximated area of the given Area object; Loader can be null; if not, it's used to secure memory space.
`static double` ```measureArea(Point3f p1, Point3f p2, Point3f p3)```
Compute the area of the triangle defined by 3 points in 3D space, returning half of the length of the vector resulting from the cross product of vectors p1p2 and p1p3.
`static void` ```quicksort(float[] data, Object[] sortAlso)```
`static void` ```quicksort(float[] data, Object[] sortAlso, int left, int right)```
Adapted from Stephan Preibisch's mpi.fruitfly.math.General homonimous method.
`static String` ```shortest(float f, float precision)```
Returns the shortest possible String representation of a float number, according to the desired decimal @param precision.
`static Area[]` ```splitArea(Area a, PolygonRoi proi, Rectangle world)```
Returns an array of two Area objects, or of 1 if the @param proi doesn't intersect @param a.
`static double` ```totalAreaOfTruncatedCone(double r1, double r2, double height)```
The lateral area plus the two circles.
`static Point2D.Double` ```transform(AffineTransform affine, double x, double y)```
`static Area` ```transform(CoordinateTransform ict, Area a)```
Return a new Area resulting from applying @param ict to @param a; assumes areas consists of paths with moveTo, lineTo and close operations.
`static double` ```volumeOfTruncatedCone(double r1, double r2, double height)```
`static CoordinateTransform` ```wrap(AffineTransform to_world, CoordinateTransform ict, AffineTransform to_local)```
The @param ict is expected to transform the data as if this data was expressed in world coordinates, so this method returns a transformation list that prepends the transform from local to world, then the @param ict, then from world to local.
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Constructor Detail

• #### M

`public M()`
• ### Method Detail

• #### distancePointToSegment

```public static final double distancePointToSegment(double px,
double py,
double pz,
double lx1,
double ly1,
double lz1,
double lx2,
double ly2,
double lz2)```
• #### distancePointToSegmentSq

```public static final double distancePointToSegmentSq(double px,
double py,
double pz,
double lx1,
double ly1,
double lz1,
double lx2,
double ly2,
double lz2)```
• #### distancePointToSegment

```public static final double distancePointToSegment(Vector3d p,
Vector3d v1,
Vector3d v2)```
Minimum distance between point v0 and a line segment defined by points v1 and v2.
• #### distancePointToSegmentSq

```public static final double distancePointToSegmentSq(Vector3d p,
Vector3d v1,
Vector3d v2)```
• #### distance

```public static final double distance(Tuple3d t1,
Tuple3d t2)```
• #### distanceSq

```public static final double distanceSq(Tuple3d t1,
Tuple3d t2)```
• #### distance

```public static final double distance(double x1,
double y1,
double z1,
double x2,
double y2,
double z2)```
• #### distance

```public static final double distance(double x1,
double y1,
double x2,
double y2)```
• #### distanceSq

```public static final double distanceSq(double x1,
double y1,
double z1,
double x2,
double y2,
double z2)```
• #### distancePointToLine

```public static double distancePointToLine(double px,
double py,
double pz,
double lx1,
double ly1,
double lz1,
double lx2,
double ly2,
double lz2)```
In 3D
• #### distancePointToLine

```public static double distancePointToLine(double px,
double py,
double lx1,
double ly1,
double lx2,
double ly2)```
For a point px,py return its distance to a line defined by points lx1,ly1 and lx2,ly2. Formula as in http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html at 2008-11-11 20:19 Zurich time.
• #### distancePointToSegment

```public static double distancePointToSegment(double px,
double py,
double lx1,
double ly1,
double lx2,
double ly2)```
For a point px,py return its distance to a line SEGMENT defined by points lx1,ly1 and lx2,ly2.
• #### equals

```public static final boolean equals(double a,
double b)```
• #### transform

```public static final Point2D.Double transform(AffineTransform affine,
double x,
double y)```
• #### inverseTransform

```public static final Point2D.Double inverseTransform(AffineTransform affine,
double x,
double y)```
• #### getAngle

```public static final double getAngle(double x,
double y)```
Returns the angle in radians of the given polar coordinates, correcting the Math.atan2 output. Adjusting so that 0 is 3 o'clock, PI+PI/2 is 12 o'clock, PI is 9 o'clock, and PI/2 is 6 o'clock (why atan2 doesn't output angles this way? I remember I had the same problem for Pipe.java in the A_3D_editing plugin)
• #### isEmpty

`public static final boolean isEmpty(Area area)`
• #### intersects

```public static final boolean intersects(Area a1,
Area a2)```
Test whether the areas intersect each other.
• #### getArea

`public static final Area getArea(Roi roi)`
• #### getArea

`public static final Area getArea(ShapeRoi sroi)`
• #### measureArea

```public static final double measureArea(Area area,
Returns the approximated area of the given Area object; Loader can be null; if not, it's used to secure memory space.
• #### measureArea

```public static final double measureArea(Point3f p1,
Point3f p2,
Point3f p3)```
Compute the area of the triangle defined by 3 points in 3D space, returning half of the length of the vector resulting from the cross product of vectors p1p2 and p1p3.
• #### isAreaROI

`public static final boolean isAreaROI(Roi roi)`
Returns true if the roi is of closed shape type like an OvalRoi, ShapeRoi, a Roi rectangle, etc.
• #### getPolygons

`public static final Collection<Polygon> getPolygons(Area area)`
• #### getPolygonsByRounding

`public static final Collection<Polygon> getPolygonsByRounding(Area area)`
• #### transform

```public static final Area transform(CoordinateTransform ict,
Area a)```
Return a new Area resulting from applying @param ict to @param a; assumes areas consists of paths with moveTo, lineTo and close operations.
• #### apply

```public static final void apply(CoordinateTransform ict,
Area roi,
Area a)```
Apply in place the @param ict to the Area @param a, but only for the part that intersects the roi.
• #### apply

```public static final void apply(VectorDataTransform vdt,
Area a)```
• #### apply

```public static final void apply(VectorDataTransform vdt,
Area a,
boolean remove_outside)```
Parts of @param a not intersected by any of @param vdt rois will be left untouched if @param remove_outside is false.
• #### findPath

```public static final Polygon findPath(Area area,
int x,
int y)```
Detect if a point is not in the area, but lays inside one of its path, which is returned as a Polygon. Otherwise returns null. The given x,y must be already in the Area's coordinate system.
• #### areaInInts

`public static final Area areaInInts(Area area)`
Converts all points in @param area to ints by casting.
• #### areaInIntsByRounding

`public static final Area areaInIntsByRounding(Area area)`
Converts all points in @param area to ints by rounding.
• #### quicksort

```public static void quicksort(float[] data,
Object[] sortAlso)
throws IllegalArgumentException```
Throws:
`IllegalArgumentException`
• #### quicksort

```public static void quicksort(float[] data,
Object[] sortAlso,
int left,
int right)```
Adapted from Stephan Preibisch's mpi.fruitfly.math.General homonimous method.

```public static final Shape createArrowhead(double x1,
double y1,
double x2,
double y2)```
Create an arrowhead at the end of the line segment defined by x1,y1 and x2,y2.

```public static final Shape createArrowhead(double x1,
double y1,
double x2,
double y2,
double magnification)```
• #### createIcosahedron

```public static final List<Point3f> createIcosahedron(int subdivisions,
Returns a "3D Viewer"-ready list mesh, centered at 0,0,0 and with radius as the radius of the enclosing sphere.
• #### apply

```public static final void apply(CoordinateTransform ict,
double[][] p,
int i,
double[] fp)```
Reuses the @param fp to apply in place.
• #### wrap

```public static final CoordinateTransform wrap(AffineTransform to_world,
CoordinateTransform ict,
AffineTransform to_local)
throws Exception```
The @param ict is expected to transform the data as if this data was expressed in world coordinates, so this method returns a transformation list that prepends the transform from local to world, then the @param ict, then from world to local.
Throws:
`Exception`
• #### shortest

```public static final String shortest(float f,
float precision)```
Returns the shortest possible String representation of a float number, according to the desired decimal @param precision.
• #### appendShortest

```public static final void appendShortest(float f,
float precision,
StringBuilder sb)```
Appends to @param sb the shortest possible String representation of a float number, according to the desired decimal @param precision.
• #### computeSegmentsIntersection

```public static final float[] computeSegmentsIntersection(float ax0,
float ay0,
float ax1,
float ay1,
float bx0,
float by0,
float bx1,
float by1)```
Returns:
the point of intersection of the two segments a and b, or null if they don't intersect.
• #### splitArea

```public static final Area[] splitArea(Area a,
PolygonRoi proi,
Rectangle world)```
Returns an array of two Area objects, or of 1 if the @param proi doesn't intersect @param a.
• #### asVectorString2D

```public static final VectorString2D asVectorString2D(Polygon pol,
double z)
throws Exception```
Throws:
`Exception`
• #### volumeOfTruncatedCone

```public static final double volumeOfTruncatedCone(double r1,
double r2,
double height)```
• #### lateralAreaOfTruncatedCone

```public static final double lateralAreaOfTruncatedCone(double r1,
double r2,
double height)```
• #### totalAreaOfTruncatedCone

```public static final double totalAreaOfTruncatedCone(double r1,
double r2,
double height)```
The lateral area plus the two circles.
• #### convolveGaussianSigma1

```public static final void convolveGaussianSigma1(float[] in,
float[] out,
CircularSequence seq)```
• #### createInterpolatedPolygon

```public static final ij.process.FloatPolygon createInterpolatedPolygon(ij.process.FloatPolygon p,
double interval,
boolean isLine)```
Copied from ImageJ's ij.gui.PolygonRoi.getInterpolatedPolygon, by Wayne Rasband and collaborators. The reason I copied this method is that creating a new PolygonRoi just to get an interpolated polygon processes the float[] arrays of the coordinates, subtracting the minimum x,y. Not only it is an extra operation but it is also in place, altering data arrays. Fortunately FloatPolygon does not touch the arrays.