diff --git a/src/main/java/jme3utilities/math/MyMath.java b/src/main/java/jme3utilities/math/MyMath.java index d5f40d3b..535ff639 100644 --- a/src/main/java/jme3utilities/math/MyMath.java +++ b/src/main/java/jme3utilities/math/MyMath.java @@ -1,5 +1,5 @@ /* - Copyright (c) 2013-2024, Stephen Gold + Copyright (c) 2013-2024 Stephen Gold All rights reserved. Redistribution and use in source and binary forms, with or without @@ -73,6 +73,44 @@ private MyMath() { // ************************************************************************* // new methods exposed + /** + * Return the circle function {@code sqrt(1 - x^2)} for a double-precision + * value. + * + * @param abscissa input (≤1, ≥-1) + * @return positive ordinate of the unit circle at the abscissa (≤1, + * ≥0) + */ + public static double circle(double abscissa) { + assert Validate.inRange(abscissa, "abscissa", -1.0, 1.0); + + double y = Math.sqrt(1.0 - abscissa * abscissa); + + assert y >= 0.0 : y; + assert y <= 1.0 : y; + return y; + } + + /** + * Return the circle function {@code sqrt(1 - x^2)} for a single-precision + * value. Double-precision arithmetic is used to reduce the risk of + * overflow. + * + * @param abscissa input (≤1, ≥-1) + * @return positive ordinate of the unit circle at the abscissa (≤1, + * ≥0) + */ + public static float circle(float abscissa) { + assert Validate.inRange(abscissa, "abscissa", -1f, 1f); + + double x = abscissa; + float y = (float) circle(x); + + assert y >= 0f : y; + assert y <= 1f : y; + return y; + } + /** * Clamp a double-precision value between 2 limits. *