本文整理汇总了Java中org.apache.commons.math3.util.MathUtils.TWO_PI属性的典型用法代码示例。如果您正苦于以下问题:Java MathUtils.TWO_PI属性的具体用法?Java MathUtils.TWO_PI怎么用?Java MathUtils.TWO_PI使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.commons.math3.util.MathUtils
的用法示例。
在下文中一共展示了MathUtils.TWO_PI属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: logBinomialProbability
/**
* Compute the logarithm of the PMF for a binomial distribution
* using the saddle point expansion.
*
* @param x the value at which the probability is evaluated.
* @param n the number of trials.
* @param p the probability of success.
* @param q the probability of failure (1 - p).
* @return log(p(x)).
*/
static double logBinomialProbability(int x, int n, double p, double q) {
double ret;
if (x == 0) {
if (p < 0.1) {
ret = -getDeviancePart(n, n * q) - n * p;
} else {
ret = n * FastMath.log(q);
}
} else if (x == n) {
if (q < 0.1) {
ret = -getDeviancePart(n, n * p) - n * q;
} else {
ret = n * FastMath.log(p);
}
} else {
ret = getStirlingError(n) - getStirlingError(x) -
getStirlingError(n - x) - getDeviancePart(x, n * p) -
getDeviancePart(n - x, n * q);
double f = (MathUtils.TWO_PI * x * (n - x)) / n;
ret = -0.5 * FastMath.log(f) + ret;
}
return ret;
}
示例2: Arc
/** Simple constructor.
* <p>
* If either {@code lower} is equals to {@code upper} or
* the interval exceeds \( 2 \pi \), the arc is considered
* to be the full circle and its initial defining boundaries
* will be forgotten. {@code lower} is not allowed to be
* greater than {@code upper} (an exception is thrown in this case).
* {@code lower} will be canonicalized between 0 and \( 2 \pi \), and
* upper shifted accordingly, so the {@link #getInf()} and {@link #getSup()}
* may not return the value used at instance construction.
* </p>
* @param lower lower angular bound of the arc
* @param upper upper angular bound of the arc
* @param tolerance tolerance below which angles are considered identical
* @exception NumberIsTooLargeException if lower is greater than upper
*/
public Arc(final double lower, final double upper, final double tolerance)
throws NumberIsTooLargeException {
this.tolerance = tolerance;
if (Precision.equals(lower, upper, 0) || (upper - lower) >= MathUtils.TWO_PI) {
// the arc must cover the whole circle
this.lower = 0;
this.upper = MathUtils.TWO_PI;
this.middle = FastMath.PI;
} else if (lower <= upper) {
this.lower = MathUtils.normalizeAngle(lower, FastMath.PI);
this.upper = this.lower + (upper - lower);
this.middle = 0.5 * (this.lower + this.upper);
} else {
throw new NumberIsTooLargeException(LocalizedFormats.ENDPOINTS_NOT_AN_INTERVAL,
lower, upper, true);
}
}
示例3: SubArcsIterator
/** Simple constructor.
*/
SubArcsIterator() {
firstStart = getFirstArcStart();
current = firstStart;
if (firstStart == null) {
// all the leaf tree nodes share the same inside/outside status
if ((Boolean) getFirstLeaf(getTree(false)).getAttribute()) {
// it is an inside node, it represents the full circle
pending = new double[] {
0, MathUtils.TWO_PI
};
} else {
pending = null;
}
} else {
selectPending();
}
}
示例4: checkPoint
/** Check a point with respect to the arc.
* @param point point to check
* @return a code representing the point status: either {@link
* Location#INSIDE}, {@link Location#OUTSIDE} or {@link Location#BOUNDARY}
*/
public Location checkPoint(final double point) {
final double normalizedPoint = MathUtils.normalizeAngle(point, middle);
if (normalizedPoint < lower - tolerance || normalizedPoint > upper + tolerance) {
return Location.OUTSIDE;
} else if (normalizedPoint > lower + tolerance && normalizedPoint < upper - tolerance) {
return Location.INSIDE;
} else {
return (getSize() >= MathUtils.TWO_PI - tolerance) ? Location.INSIDE : Location.BOUNDARY;
}
}
示例5: createRegularPolygonVertices
/** Build the vertices representing a regular polygon.
* @param center center of the polygon (the center is in the inside half)
* @param meridian point defining the reference meridian for first polygon vertex
* @param outsideRadius distance of the vertices to the center
* @param n number of sides of the polygon
* @return vertices array
*/
private static S2Point[] createRegularPolygonVertices(final Vector3D center, final Vector3D meridian,
final double outsideRadius, final int n) {
final S2Point[] array = new S2Point[n];
final Rotation r0 = new Rotation(Vector3D.crossProduct(center, meridian),
outsideRadius, RotationConvention.VECTOR_OPERATOR);
array[0] = new S2Point(r0.applyTo(center));
final Rotation r = new Rotation(center, MathUtils.TWO_PI / n, RotationConvention.VECTOR_OPERATOR);
for (int i = 1; i < n; ++i) {
array[i] = new S2Point(r.applyTo(array[i - 1].getVector()));
}
return array;
}
示例6: convexCellArea
/** 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;
}
示例7: getModelFunction
/**
* 模型方程
*
* @return the model function
*/
public MultivariateVectorFunction getModelFunction() {
return new MultivariateVectorFunction() {
@Override
public double[] value(double[] point) throws IllegalArgumentException {
final double cx = point[0];
final double cy = point[1];
final double r = point[2];
final double[] model = new double[points.size() * 2];
final double deltaTheta = MathUtils.TWO_PI / resolution;
for (int i = 0; i < points.size(); i++) {
final double[] p = points.get(i);
final double px = p[0];
final double py = p[1];
double bestX = 0;
double bestY = 0;
double dMin = Double.POSITIVE_INFINITY;
// Find the angle for which the circle passes closest to the
// current point (using a resolution of 100 points along the
// circumference).
for (double theta = 0; theta <= MathUtils.TWO_PI; theta += deltaTheta) {
final double currentX = cx + r * FastMath.cos(theta);
final double currentY = cy + r * FastMath.sin(theta);
final double dX = currentX - px;
final double dY = currentY - py;
final double d = dX * dX + dY * dY;
if (d < dMin) {
dMin = d;
bestX = currentX;
bestY = currentY;
}
}
final int index = i * 2;
model[index] = bestX;
model[index + 1] = bestY;
}
return model;
}
};
}
示例8: selectPending
/** Walk the tree to select the pending sub-arc.
*/
private void selectPending() {
// look for the start of the arc
BSPTree<Sphere1D> start = current;
while (start != null && !isArcStart(start)) {
start = nextInternalNode(start);
}
if (start == null) {
// we have exhausted the iterator
current = null;
pending = null;
return;
}
// look for the end of the arc
BSPTree<Sphere1D> end = start;
while (end != null && !isArcEnd(end)) {
end = nextInternalNode(end);
}
if (end != null) {
// we have identified the arc
pending = new double[] {
getAngle(start), getAngle(end)
};
// prepare search for next arc
current = end;
} else {
// the final arc wraps around 2\pi, its end is before the first start
end = firstStart;
while (end != null && !isArcEnd(end)) {
end = previousInternalNode(end);
}
if (end == null) {
// this should never happen
throw new MathInternalError();
}
// we have identified the last arc
pending = new double[] {
getAngle(start), getAngle(end) + MathUtils.TWO_PI
};
// there won't be any other arcs
current = null;
}
}
示例9: split
/** Split the edge.
* <p>
* Once split, this edge is not referenced anymore by the vertices,
* it is replaced by the two or three sub-edges and intermediate splitting
* vertices are introduced to connect these sub-edges together.
* </p>
* @param splitCircle circle splitting the edge in several parts
* @param outsideList list where to put parts that are outside of the split circle
* @param insideList list where to put parts that are inside the split circle
*/
void split(final Circle splitCircle,
final List<Edge> outsideList, final List<Edge> insideList) {
// get the inside arc, synchronizing its phase with the edge itself
final double edgeStart = circle.getPhase(start.getLocation().getVector());
final Arc arc = circle.getInsideArc(splitCircle);
final double arcRelativeStart = MathUtils.normalizeAngle(arc.getInf(), edgeStart + FastMath.PI) - edgeStart;
final double arcRelativeEnd = arcRelativeStart + arc.getSize();
final double unwrappedEnd = arcRelativeEnd - MathUtils.TWO_PI;
// build the sub-edges
final double tolerance = circle.getTolerance();
Vertex previousVertex = start;
if (unwrappedEnd >= length - tolerance) {
// the edge is entirely contained inside the circle
// we don't split anything
insideList.add(this);
} else {
// there are at least some parts of the edge that should be outside
// (even is they are later be filtered out as being too small)
double alreadyManagedLength = 0;
if (unwrappedEnd >= 0) {
// the start of the edge is inside the circle
previousVertex = addSubEdge(previousVertex,
new Vertex(new S2Point(circle.getPointAt(edgeStart + unwrappedEnd))),
unwrappedEnd, insideList, splitCircle);
alreadyManagedLength = unwrappedEnd;
}
if (arcRelativeStart >= length - tolerance) {
// the edge ends while still outside of the circle
if (unwrappedEnd >= 0) {
previousVertex = addSubEdge(previousVertex, end,
length - alreadyManagedLength, outsideList, splitCircle);
} else {
// the edge is entirely outside of the circle
// we don't split anything
outsideList.add(this);
}
} else {
// the edge is long enough to enter inside the circle
previousVertex = addSubEdge(previousVertex,
new Vertex(new S2Point(circle.getPointAt(edgeStart + arcRelativeStart))),
arcRelativeStart - alreadyManagedLength, outsideList, splitCircle);
alreadyManagedLength = arcRelativeStart;
if (arcRelativeEnd >= length - tolerance) {
// the edge ends while still inside of the circle
previousVertex = addSubEdge(previousVertex, end,
length - alreadyManagedLength, insideList, splitCircle);
} else {
// the edge is long enough to exit outside of the circle
previousVertex = addSubEdge(previousVertex,
new Vertex(new S2Point(circle.getPointAt(edgeStart + arcRelativeStart))),
arcRelativeStart - alreadyManagedLength, insideList, splitCircle);
alreadyManagedLength = arcRelativeStart;
previousVertex = addSubEdge(previousVertex, end,
length - alreadyManagedLength, outsideList, splitCircle);
}
}
}
}
示例10: InterpolatingMicrosphere2D
/**
* Create a sphere from vectors regularly sampled around a circle.
*
* @param size Number of surface elements of the sphere.
* @param maxDarkFraction Maximum fraction of the facets that can be dark.
* If the fraction of "non-illuminated" facets is larger, no estimation
* of the value will be performed, and the {@code background} value will
* be returned instead.
* @param darkThreshold Value of the illumination below which a facet is
* considered dark.
* @param background Value returned when the {@code maxDarkFraction}
* threshold is exceeded.
* @throws org.apache.commons.math3.exception.NotStrictlyPositiveException
* if {@code size <= 0}.
* @throws org.apache.commons.math3.exception.NotPositiveException if
* {@code darkThreshold < 0}.
* @throws org.apache.commons.math3.exception.OutOfRangeException if
* {@code maxDarkFraction} does not belong to the interval {@code [0, 1]}.
*/
public InterpolatingMicrosphere2D(int size,
double maxDarkFraction,
double darkThreshold,
double background) {
super(DIMENSION, size, maxDarkFraction, darkThreshold, background);
// Generate the microsphere normals.
for (int i = 0; i < size; i++) {
final double angle = i * MathUtils.TWO_PI / size;
add(new double[] { FastMath.cos(angle),
FastMath.sin(angle) },
false);
}
}