本文整理汇总了Java中org.apache.commons.math.util.FastMath.PI属性的典型用法代码示例。如果您正苦于以下问题:Java FastMath.PI属性的具体用法?Java FastMath.PI怎么用?Java FastMath.PI使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.commons.math.util.FastMath
的用法示例。
在下文中一共展示了FastMath.PI属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testContains
@Test
public void testContains() {
Vector3D p1 = new Vector3D(0, 0, 1);
Line l = new Line(p1, new Vector3D(0, 0, 1));
Assert.assertTrue(l.contains(p1));
Assert.assertTrue(l.contains(new Vector3D(1.0, p1, 0.3, l.getDirection())));
Vector3D u = l.getDirection().orthogonal();
Vector3D v = Vector3D.crossProduct(l.getDirection(), u);
for (double alpha = 0; alpha < 2 * FastMath.PI; alpha += 0.3) {
Assert.assertTrue(! l.contains(p1.add(new Vector3D(FastMath.cos(alpha), u,
FastMath.sin(alpha), v))));
}
}
示例2: reset
/** Reset the instance as if built from two points.
* <p>The line is oriented from p1 to p2</p>
* @param p1 first point
* @param p2 second point
*/
public void reset(final Vector2D p1, final Vector2D p2) {
final double dx = p2.getX() - p1.getX();
final double dy = p2.getY() - p1.getY();
final double d = FastMath.hypot(dx, dy);
if (d == 0.0) {
angle = 0.0;
cos = 1.0;
sin = 0.0;
originOffset = p1.getY();
} else {
angle = FastMath.PI + FastMath.atan2(-dy, -dx);
cos = FastMath.cos(angle);
sin = FastMath.sin(angle);
originOffset = (p2.getX() * p1.getY() - p1.getX() * p2.getY()) / d;
}
}
示例3: testSinFunction
/**
* Test of transformer for the sine function.
*/
@Test
public void testSinFunction() {
UnivariateRealFunction f = new SinFunction();
FastCosineTransformer transformer = new FastCosineTransformer();
double min, max, result[], tolerance = 1E-12; int N = 9;
double expected[] = { 0.0, 3.26197262739567, 0.0,
-2.17958042710327, 0.0, -0.648846697642915,
0.0, -0.433545502649478, 0.0 };
min = 0.0; max = 2.0 * FastMath.PI * N / (N-1);
result = transformer.transform(f, min, max, N);
for (int i = 0; i < N; i++) {
Assert.assertEquals(expected[i], result[i], tolerance);
}
min = -FastMath.PI; max = FastMath.PI * (N+1) / (N-1);
result = transformer.transform(f, min, max, N);
for (int i = 0; i < N; i++) {
Assert.assertEquals(-expected[i], result[i], tolerance);
}
}
示例4: testSinFunction
/**
* Test of interpolator for the sine function.
* <p>
* |sin^(n)(zeta)| <= 1.0, zeta in [0, 2*PI]
*/
public void testSinFunction() {
UnivariateRealFunction f = new SinFunction();
UnivariateRealInterpolator interpolator = new DividedDifferenceInterpolator();
double x[], y[], z, expected, result, tolerance;
// 6 interpolating points on interval [0, 2*PI]
int n = 6;
double min = 0.0, max = 2 * FastMath.PI;
x = new double[n];
y = new double[n];
for (int i = 0; i < n; i++) {
x[i] = min + i * (max - min) / n;
y[i] = f.value(x[i]);
}
double derivativebound = 1.0;
UnivariateRealFunction p = interpolator.interpolate(x, y);
z = FastMath.PI / 4; expected = f.value(z); result = p.value(z);
tolerance = FastMath.abs(derivativebound * partialerror(x, z));
assertEquals(expected, result, tolerance);
z = FastMath.PI * 1.5; expected = f.value(z); result = p.value(z);
tolerance = FastMath.abs(derivativebound * partialerror(x, z));
assertEquals(expected, result, tolerance);
}
示例5: testSinFunction
@Test
public void testSinFunction() throws MathException {
UnivariateRealFunction f = new SinFunction();
UnivariateRealIntegratorImpl integrator = new LegendreGaussIntegrator(5, 64);
integrator.setAbsoluteAccuracy(1.0e-10);
integrator.setRelativeAccuracy(1.0e-14);
integrator.setMinimalIterationCount(2);
integrator.setMaximalIterationCount(15);
double min, max, expected, result, tolerance;
min = 0; max = FastMath.PI; expected = 2;
tolerance = FastMath.max(integrator.getAbsoluteAccuracy(),
FastMath.abs(expected * integrator.getRelativeAccuracy()));
result = integrator.integrate(f, min, max);
Assert.assertEquals(expected, result, tolerance);
min = -FastMath.PI/3; max = 0; expected = -0.5;
tolerance = FastMath.max(integrator.getAbsoluteAccuracy(),
FastMath.abs(expected * integrator.getRelativeAccuracy()));
result = integrator.integrate(f, min, max);
Assert.assertEquals(expected, result, tolerance);
}
示例6: testSinFunction
/**
* Test of solver for the sine function.
*/
@Test
public void testSinFunction() {
UnivariateRealFunction f = new SinFunction();
UnivariateRealSolver solver = new MullerSolver();
double min, max, expected, result, tolerance;
min = 3.0; max = 4.0; expected = FastMath.PI;
tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
FastMath.abs(expected * solver.getRelativeAccuracy()));
result = solver.solve(100, f, min, max);
Assert.assertEquals(expected, result, tolerance);
min = -1.0; max = 1.5; expected = 0.0;
tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
FastMath.abs(expected * solver.getRelativeAccuracy()));
result = solver.solve(100, f, min, max);
Assert.assertEquals(expected, result, tolerance);
}
示例7: testSerial
@Test
public void testSerial() throws FractionConversionException {
BigFraction[] fractions = {
new BigFraction(3, 4), BigFraction.ONE, BigFraction.ZERO,
new BigFraction(17), new BigFraction(FastMath.PI, 1000),
new BigFraction(-5, 2)
};
for (BigFraction fraction : fractions) {
Assert.assertEquals(fraction, TestUtils.serializeAndRecover(fraction));
}
}
示例8: nthRoot
/**
* Computes the n-th roots of this complex number.
* The nth roots are defined by the formula:
* <pre>
* <code>
* z<sub>k</sub> = abs<sup>1/n</sup> (cos(phi + 2πk/n) + i (sin(phi + 2πk/n))
* </code>
* </pre>
* for <i>{@code k=0, 1, ..., n-1}</i>, where {@code abs} and {@code phi}
* are respectively the {@link #abs() modulus} and
* {@link #getArgument() argument} of this complex number.
* <br/>
* If one or both parts of this complex number is NaN, a list with just
* one element, {@link #NaN} is returned.
* if neither part is NaN, but at least one part is infinite, the result
* is a one-element list containing {@link #INF}.
*
* @param n Degree of root.
* @return a List<Complex> of all {@code n}-th roots of {@code this}.
* @throws NotPositiveException if {@code n <= 0}.
* @since 2.0
*/
public List<Complex> nthRoot(int n) {
if (n <= 0) {
throw new NotPositiveException(LocalizedFormats.CANNOT_COMPUTE_NTH_ROOT_FOR_NEGATIVE_N,
n);
}
final List<Complex> result = new ArrayList<Complex>();
if (isNaN) {
result.add(NaN);
return result;
}
if (isInfinite()) {
result.add(INF);
return result;
}
// nth root of abs -- faster / more accurate to use a solver here?
final double nthRootOfAbs = FastMath.pow(abs(), 1.0 / n);
// Compute nth roots of complex number with k = 0, 1, ... n-1
final double nthPhi = getArgument() / n;
final double slice = 2 * FastMath.PI / n;
double innerPart = nthPhi;
for (int k = 0; k < n ; k++) {
// inner part
final double realPart = nthRootOfAbs * FastMath.cos(innerPart);
final double imaginaryPart = nthRootOfAbs * FastMath.sin(innerPart);
result.add(createComplex(realPart, imaginaryPart));
innerPart += slice;
}
return result;
}
示例9: nthRoot
/**
* <p>Computes the n-th roots of this complex number.
* </p>
* <p>The nth roots are defined by the formula: <pre>
* <code> z<sub>k</sub> = abs<sup> 1/n</sup> (cos(phi + 2πk/n) + i (sin(phi + 2πk/n))</code></pre>
* for <i><code>k=0, 1, ..., n-1</code></i>, where <code>abs</code> and <code>phi</code> are
* respectively the {@link #abs() modulus} and {@link #getArgument() argument} of this complex number.
* </p>
* <p>If one or both parts of this complex number is NaN, a list with just one element,
* {@link #NaN} is returned.</p>
* <p>if neither part is NaN, but at least one part is infinite, the result is a one-element
* list containing {@link #INF}.</p>
*
* @param n degree of root
* @return List<Complex> all nth roots of this complex number
* @throws IllegalArgumentException if parameter n is less than or equal to 0
* @since 2.0
*/
public List<Complex> nthRoot(int n) throws IllegalArgumentException {
if (n <= 0) {
throw MathRuntimeException.createIllegalArgumentException(
LocalizedFormats.CANNOT_COMPUTE_NTH_ROOT_FOR_NEGATIVE_N,
n);
}
List<Complex> result = new ArrayList<Complex>();
if (isNaN()) {
result.add(Complex.NaN);
return result;
}
if (isInfinite()) {
result.add(Complex.INF);
return result;
}
// nth root of abs -- faster / more accurate to use a solver here?
final double nthRootOfAbs = FastMath.pow(abs(), 1.0 / n);
// Compute nth roots of complex number with k = 0, 1, ... n-1
final double nthPhi = getArgument()/n;
final double slice = 2 * FastMath.PI / n;
double innerPart = nthPhi;
for (int k = 0; k < n ; k++) {
// inner part
final double realPart = nthRootOfAbs * FastMath.cos(innerPart);
final double imaginaryPart = nthRootOfAbs * FastMath.sin(innerPart);
result.add(createComplex(realPart, imaginaryPart));
innerPart += slice;
}
return result;
}
示例10: testSinFunction
/**
* Test of interpolator for the sine function.
* <p>
* |sin^(n)(zeta)| <= 1.0, zeta in [0, 2*PI]
*/
@Test
public void testSinFunction() {
UnivariateRealFunction f = new SinFunction();
UnivariateRealInterpolator interpolator = new DividedDifferenceInterpolator();
double x[], y[], z, expected, result, tolerance;
// 6 interpolating points on interval [0, 2*PI]
int n = 6;
double min = 0.0, max = 2 * FastMath.PI;
x = new double[n];
y = new double[n];
for (int i = 0; i < n; i++) {
x[i] = min + i * (max - min) / n;
y[i] = f.value(x[i]);
}
double derivativebound = 1.0;
UnivariateRealFunction p = interpolator.interpolate(x, y);
z = FastMath.PI / 4; expected = f.value(z); result = p.value(z);
tolerance = FastMath.abs(derivativebound * partialerror(x, z));
Assert.assertEquals(expected, result, tolerance);
z = FastMath.PI * 1.5; expected = f.value(z); result = p.value(z);
tolerance = FastMath.abs(derivativebound * partialerror(x, z));
Assert.assertEquals(expected, result, tolerance);
}
示例11: computeOmega
/** Computes the n<sup>th</sup> roots of unity.
* <p>The computed omega[] = { 1, w, w<sup>2</sup>, ... w<sup>(n-1)</sup> } where
* w = exp(-2 π i / n), i = &sqrt;(-1).</p>
* <p>Note that n is positive for
* forward transform and negative for inverse transform.</p>
* @param n number of roots of unity to compute,
* positive for forward transform, negative for inverse transform
* @throws IllegalArgumentException if n = 0
*/
public synchronized void computeOmega(int n) throws IllegalArgumentException {
if (n == 0) {
throw MathRuntimeException.createIllegalArgumentException(
LocalizedFormats.CANNOT_COMPUTE_0TH_ROOT_OF_UNITY);
}
isForward = n > 0;
// avoid repetitive calculations
final int absN = FastMath.abs(n);
if (absN == omegaCount) {
return;
}
// calculate everything from scratch, for both forward and inverse versions
final double t = 2.0 * FastMath.PI / absN;
final double cosT = FastMath.cos(t);
final double sinT = FastMath.sin(t);
omegaReal = new double[absN];
omegaImaginaryForward = new double[absN];
omegaImaginaryInverse = new double[absN];
omegaReal[0] = 1.0;
omegaImaginaryForward[0] = 0.0;
omegaImaginaryInverse[0] = 0.0;
for (int i = 1; i < absN; i++) {
omegaReal[i] =
omegaReal[i-1] * cosT + omegaImaginaryForward[i-1] * sinT;
omegaImaginaryForward[i] =
omegaImaginaryForward[i-1] * cosT - omegaReal[i-1] * sinT;
omegaImaginaryInverse[i] = -omegaImaginaryForward[i];
}
omegaCount = absN;
}
示例12: getTheoreticalEventsTimes
/**
* Get the theoretical events times.
* @return theoretical events times
*/
@Override
public double[] getTheoreticalEventsTimes() {
return new double[] {
1 * FastMath.PI - a,
2 * FastMath.PI - a,
3 * FastMath.PI - a,
4 * FastMath.PI - a,
12.0
};
}
示例13: testAxisAngle
@Test
public void testAxisAngle() {
Rotation r = new Rotation(new Vector3D(10, 10, 10), 2 * FastMath.PI / 3);
checkVector(r.applyTo(Vector3D.PLUS_I), Vector3D.PLUS_J);
checkVector(r.applyTo(Vector3D.PLUS_J), Vector3D.PLUS_K);
checkVector(r.applyTo(Vector3D.PLUS_K), Vector3D.PLUS_I);
double s = 1 / FastMath.sqrt(3);
checkVector(r.getAxis(), new Vector3D(s, s, s));
checkAngle(r.getAngle(), 2 * FastMath.PI / 3);
try {
new Rotation(new Vector3D(0, 0, 0), 2 * FastMath.PI / 3);
Assert.fail("an exception should have been thrown");
} catch (ArithmeticException e) {
}
r = new Rotation(Vector3D.PLUS_K, 1.5 * FastMath.PI);
checkVector(r.getAxis(), new Vector3D(0, 0, -1));
checkAngle(r.getAngle(), 0.5 * FastMath.PI);
r = new Rotation(Vector3D.PLUS_J, FastMath.PI);
checkVector(r.getAxis(), Vector3D.PLUS_J);
checkAngle(r.getAngle(), FastMath.PI);
checkVector(Rotation.IDENTITY.getAxis(), Vector3D.PLUS_I);
}
示例14: testChoppedHexagon
@Test
public void testChoppedHexagon() {
double pi6 = FastMath.PI / 6.0;
double sqrt3 = FastMath.sqrt(3.0);
SubLine[] hyp = {
new Line(new Vector2D( 0.0, 1.0), 5 * pi6).wholeHyperplane(),
new Line(new Vector2D(-sqrt3, 1.0), 7 * pi6).wholeHyperplane(),
new Line(new Vector2D(-sqrt3, 1.0), 9 * pi6).wholeHyperplane(),
new Line(new Vector2D(-sqrt3, 0.0), 11 * pi6).wholeHyperplane(),
new Line(new Vector2D( 0.0, 0.0), 13 * pi6).wholeHyperplane(),
new Line(new Vector2D( 0.0, 1.0), 3 * pi6).wholeHyperplane(),
new Line(new Vector2D(-5.0 * sqrt3 / 6.0, 0.0), 9 * pi6).wholeHyperplane()
};
hyp[1] = (SubLine) hyp[1].split(hyp[0].getHyperplane()).getMinus();
hyp[2] = (SubLine) hyp[2].split(hyp[1].getHyperplane()).getMinus();
hyp[3] = (SubLine) hyp[3].split(hyp[2].getHyperplane()).getMinus();
hyp[4] = (SubLine) hyp[4].split(hyp[3].getHyperplane()).getMinus().split(hyp[0].getHyperplane()).getMinus();
hyp[5] = (SubLine) hyp[5].split(hyp[4].getHyperplane()).getMinus().split(hyp[0].getHyperplane()).getMinus();
hyp[6] = (SubLine) hyp[6].split(hyp[3].getHyperplane()).getMinus().split(hyp[1].getHyperplane()).getMinus();
BSPTree<Euclidean2D> tree = new BSPTree<Euclidean2D>(Boolean.TRUE);
for (int i = hyp.length - 1; i >= 0; --i) {
tree = new BSPTree<Euclidean2D>(hyp[i], new BSPTree<Euclidean2D>(Boolean.FALSE), tree, null);
}
PolygonsSet set = new PolygonsSet(tree);
SubLine splitter =
new Line(new Vector2D(-2.0 * sqrt3 / 3.0, 0.0), 9 * pi6).wholeHyperplane();
PolygonsSet slice =
new PolygonsSet(new BSPTree<Euclidean2D>(splitter,
set.getTree(false).split(splitter).getPlus(),
new BSPTree<Euclidean2D>(Boolean.FALSE), null));
Assert.assertEquals(Region.Location.OUTSIDE,
slice.checkPoint(new Vector2D(0.1, 0.5)));
Assert.assertEquals(11.0 / 3.0, slice.getBoundarySize(), 1.0e-10);
}
示例15: density
/**
* {@inheritDoc}
*/
@Override
public double density(double x) {
final double dev = x - median;
return (1 / FastMath.PI) * (scale / (dev * dev + scale * scale));
}