本文整理匯總了Java中org.apache.commons.math3.util.FastMath.atan2方法的典型用法代碼示例。如果您正苦於以下問題:Java FastMath.atan2方法的具體用法?Java FastMath.atan2怎麽用?Java FastMath.atan2使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.math3.util.FastMath
的用法示例。
在下文中一共展示了FastMath.atan2方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: guessPhi
import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/**
* Estimate a first guess of the phase.
*
* @param observations Observations, sorted w.r.t. abscissa.
* @return the guessed phase.
*/
private double guessPhi(WeightedObservedPoint[] observations) {
// initialize the means
double fcMean = 0;
double fsMean = 0;
double currentX = observations[0].getX();
double currentY = observations[0].getY();
for (int i = 1; i < observations.length; ++i) {
// one step forward
final double previousX = currentX;
final double previousY = currentY;
currentX = observations[i].getX();
currentY = observations[i].getY();
final double currentYPrime = (currentY - previousY) / (currentX - previousX);
double omegaX = omega * currentX;
double cosine = FastMath.cos(omegaX);
double sine = FastMath.sin(omegaX);
fcMean += omega * currentY * cosine - currentYPrime * sine;
fsMean += omega * currentY * sine + currentYPrime * cosine;
}
return FastMath.atan2(-fsMean, fcMean);
}
示例2: reset
import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/** 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) {
unlinkReverse();
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 = dx / d;
sin = dy / d;
originOffset = MathArrays.linearCombination(p2.getX(), p1.getY(), -p1.getX(), p2.getY()) / d;
}
}
示例3: convexCellArea
import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/** Compute convex cell area.
* @param start start vertex of the convex cell boundary
* @return area
*/
private double convexCellArea(final Vertex start) {
int n = 0;
double sum = 0;
// loop around the cell
for (Edge e = start.getOutgoing(); n == 0 || e.getStart() != start; e = e.getEnd().getOutgoing()) {
// find path interior angle at vertex
final Vector3D previousPole = e.getCircle().getPole();
final Vector3D nextPole = e.getEnd().getOutgoing().getCircle().getPole();
final Vector3D point = e.getEnd().getLocation().getVector();
double alpha = FastMath.atan2(Vector3D.dotProduct(nextPole, Vector3D.crossProduct(point, previousPole)),
-Vector3D.dotProduct(nextPole, previousPole));
if (alpha < 0) {
alpha += MathUtils.TWO_PI;
}
sum += alpha;
n++;
}
// compute area using extended Girard theorem
// see Spherical Trigonometry: For the Use of Colleges and Schools by I. Todhunter
// article 99 in chapter VIII Area Of a Spherical Triangle. Spherical Excess.
// book available from project Gutenberg at http://www.gutenberg.org/ebooks/19770
return sum - (n - 2) * FastMath.PI;
}
示例4: apply
import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/** {@inheritDoc} */
public Line apply(final Hyperplane<Euclidean2D> hyperplane) {
final Line line = (Line) hyperplane;
final double rOffset = MathArrays.linearCombination(c1X, line.cos, c1Y, line.sin, c11, line.originOffset);
final double rCos = MathArrays.linearCombination(cXX, line.cos, cXY, line.sin);
final double rSin = MathArrays.linearCombination(cYX, line.cos, cYY, line.sin);
final double inv = 1.0 / FastMath.sqrt(rSin * rSin + rCos * rCos);
return new Line(FastMath.PI + FastMath.atan2(-rSin, -rCos),
inv * rCos, inv * rSin,
inv * rOffset, line.tolerance);
}
示例5: value
import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/** {@inheritDoc} */
public double value(double x, double y) {
return FastMath.atan2(x, y);
}
示例6: atan2
import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/** {@inheritDoc} */
public SparseGradient atan2(final SparseGradient x) {
// compute r = sqrt(x^2+y^2)
final SparseGradient r = multiply(this).add(x.multiply(x)).sqrt();
final SparseGradient a;
if (x.value >= 0) {
// compute atan2(y, x) = 2 atan(y / (r + x))
a = divide(r.add(x)).atan().multiply(2);
} else {
// compute atan2(y, x) = +/- pi - 2 atan(y / (r - x))
final SparseGradient tmp = divide(r.subtract(x)).atan().multiply(-2);
a = tmp.add(tmp.value <= 0 ? -FastMath.PI : FastMath.PI);
}
// fix value to take special cases (+0/+0, +0/-0, -0/+0, -0/-0, +/-infinity) correctly
a.value = FastMath.atan2(value, x.value);
return a;
}
示例7: atan2
import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/** Compute two arguments arc tangent of a derivative structure.
* @param y array holding the first operand
* @param yOffset offset of the first operand in its array
* @param x array holding the second operand
* @param xOffset offset of the second operand in its array
* @param result array where result must be stored (for
* two arguments arc tangent the result array <em>cannot</em>
* be the input array)
* @param resultOffset offset of the result in its array
*/
public void atan2(final double[] y, final int yOffset,
final double[] x, final int xOffset,
final double[] result, final int resultOffset) {
// compute r = sqrt(x^2+y^2)
double[] tmp1 = new double[getSize()];
multiply(x, xOffset, x, xOffset, tmp1, 0); // x^2
double[] tmp2 = new double[getSize()];
multiply(y, yOffset, y, yOffset, tmp2, 0); // y^2
add(tmp1, 0, tmp2, 0, tmp2, 0); // x^2 + y^2
rootN(tmp2, 0, 2, tmp1, 0); // r = sqrt(x^2 + y^2)
if (x[xOffset] >= 0) {
// compute atan2(y, x) = 2 atan(y / (r + x))
add(tmp1, 0, x, xOffset, tmp2, 0); // r + x
divide(y, yOffset, tmp2, 0, tmp1, 0); // y /(r + x)
atan(tmp1, 0, tmp2, 0); // atan(y / (r + x))
for (int i = 0; i < tmp2.length; ++i) {
result[resultOffset + i] = 2 * tmp2[i]; // 2 * atan(y / (r + x))
}
} else {
// compute atan2(y, x) = +/- pi - 2 atan(y / (r - x))
subtract(tmp1, 0, x, xOffset, tmp2, 0); // r - x
divide(y, yOffset, tmp2, 0, tmp1, 0); // y /(r - x)
atan(tmp1, 0, tmp2, 0); // atan(y / (r - x))
result[resultOffset] =
((tmp2[0] <= 0) ? -FastMath.PI : FastMath.PI) - 2 * tmp2[0]; // +/-pi - 2 * atan(y / (r - x))
for (int i = 1; i < tmp2.length; ++i) {
result[resultOffset + i] = -2 * tmp2[i]; // +/-pi - 2 * atan(y / (r - x))
}
}
// fix value to take special cases (+0/+0, +0/-0, -0/+0, -0/-0, +/-infinity) correctly
result[resultOffset] = FastMath.atan2(y[yOffset], x[xOffset]);
}
示例8: getPhase
import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/** Get the phase angle of a direction.
* <p>
* The direction may not belong to the circle as the
* phase is computed for the meridian plane between the circle
* pole and the direction.
* </p>
* @param direction direction for which phase is requested
* @return phase angle of the direction around the circle
* @see #toSubSpace(Point)
*/
public double getPhase(final Vector3D direction) {
return FastMath.PI + FastMath.atan2(-direction.dotProduct(y), -direction.dotProduct(x));
}
示例9: S2Point
import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/** Simple constructor.
* Build a vector from its underlying 3D vector
* @param vector 3D vector
* @exception MathArithmeticException if vector norm is zero
*/
public S2Point(final Vector3D vector) throws MathArithmeticException {
this(FastMath.atan2(vector.getY(), vector.getX()), Vector3D.angle(Vector3D.PLUS_K, vector),
vector.normalize());
}
示例10: getAlpha
import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/** Get the azimuth of the vector.
* @return azimuth (α) of the vector, between -π and +π
* @see #Vector3D(double, double)
*/
public double getAlpha() {
return FastMath.atan2(y, x);
}
示例11: getArgument
import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/**
* Compute the argument of this complex number.
* The argument is the angle phi between the positive real axis and
* the point representing this number in the complex plane.
* The value returned is between -PI (not inclusive)
* and PI (inclusive), with negative values returned for numbers with
* negative imaginary parts.
* <p>
* If either real or imaginary part (or both) is NaN, NaN is returned.
* Infinite parts are handled as {@code Math.atan2} handles them,
* essentially treating finite parts as zero in the presence of an
* infinite coordinate and returning a multiple of pi/4 depending on
* the signs of the infinite parts.
* See the javadoc for {@code Math.atan2} for full details.
*
* @return the argument of {@code this}.
*/
public double getArgument() {
return FastMath.atan2(getImaginary(), getReal());
}