Skip to content

Commit

Permalink
MyMath: add 2 circle() methods
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Feb 23, 2024
1 parent b9fecd2 commit ac66231
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion src/main/java/jme3utilities/math/MyMath.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 (&le;1, &ge;-1)
* @return positive ordinate of the unit circle at the abscissa (&le;1,
* &ge;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.
*
Expand Down

0 comments on commit ac66231

Please sign in to comment.