MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / acos

Method acos

src/main/java/field/linalg/BaseMath.java:35–55  ·  view source on GitHub ↗

Input-checking inverse cosine. Clamps the input to the domain of acos (i.e. [-1..1]) before evaluating, instead of returning a silent NaN like java.lang.Math.acos. Useful when there's a fear of rounding errors pushing the arg beyond 1 or -1.

(double cos_theta)

Source from the content-addressed store, hash-verified

33 * fear of rounding errors pushing the arg beyond 1 or -1.
34 */
35 public static final double acos(double cos_theta) {
36
37 if (acos_lookup == null) {
38 acos_lookup = new double[1000];
39 for (int i = 0; i < acos_lookup.length; i++)
40 acos_lookup[i] = Math.acos(clamp(-1.0 + 2 * i / (acos_lookup.length - 1f), -1, 1));
41 }
42
43
44 cos_theta = clamp(cos_theta, -1, 1);
45
46 float indx = (float) ((acos_lookup.length - 1f) * (cos_theta + 1) / 2);
47 int left = (int) indx;
48 int right = (int) indx + 1;
49 float alpha = indx - left;
50
51 left = left < 0 ? 0 : (left > acos_lookup.length - 1 ? (acos_lookup.length - 1) : left);
52 right = right < 0 ? 0 : (right > acos_lookup.length - 1 ? (acos_lookup.length - 1) : right);
53
54 return acos_lookup[left] * (1 - alpha) + alpha * acos_lookup[right];
55 }
56
57 /**
58 * Input-checking inverse sine. Clamps the input to the domain of acos [-1..1] before evaluating, instead of returning a silent NaN like java.lang.Math.asin. Useful when there's a fear of

Callers 13

nnFunction · 0.80
d3.min.jsFile · 0.80
nFunction · 0.80
raphael-min.jsFile · 0.80
angleMethod · 0.80
angleMethod · 0.80
slerpMethod · 0.80
AxisAngleMethod · 0.80
setMethod · 0.80
safeAcosMethod · 0.80
angleMethod · 0.80
perspectiveFovMethod · 0.80

Calls 1

clampMethod · 0.95

Tested by

no test coverage detected