本文整理汇总了Java中org.apache.commons.math.util.FastMath.sin方法的典型用法代码示例。如果您正苦于以下问题:Java FastMath.sin方法的具体用法?Java FastMath.sin怎么用?Java FastMath.sin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math.util.FastMath
的用法示例。
在下文中一共展示了FastMath.sin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: guessPhi
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
* Estimate a first guess of the phase.
*/
private void guessPhi() {
// 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;
}
phi = FastMath.atan2(-fsMean, fcMean);
}
示例2: reset
import org.apache.commons.math.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) {
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: side
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} */
public Side side(final Hyperplane<Euclidean2D> hyperplane) {
final Line thisLine = (Line) getHyperplane();
final Line otherLine = (Line) hyperplane;
final Vector2D crossing = thisLine.intersection(otherLine);
if (crossing == null) {
// the lines are parallel,
final double global = otherLine.getOffset(thisLine);
return (global < -1.0e-10) ? Side.MINUS : ((global > 1.0e-10) ? Side.PLUS : Side.HYPER);
}
// the lines do intersect
final boolean direct = FastMath.sin(thisLine.getAngle() - otherLine.getAngle()) < 0;
final Vector1D x = (Vector1D) thisLine.toSubSpace(crossing);
return getRemainingRegion().side(new OrientedPoint(x, direct));
}
示例4: fst
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
* Perform the FST algorithm (including inverse).
*
* @param f the real data array to be transformed
* @return the real transformed array
* @throws IllegalArgumentException if any parameters are invalid
*/
protected double[] fst(double f[]) throws IllegalArgumentException {
final double transformed[] = new double[f.length];
FastFourierTransformer.verifyDataSet(f);
if (f[0] != 0.0) {
throw MathRuntimeException.createIllegalArgumentException(
LocalizedFormats.FIRST_ELEMENT_NOT_ZERO,
f[0]);
}
final int n = f.length;
if (n == 1) { // trivial case
transformed[0] = 0.0;
return transformed;
}
// construct a new array and perform FFT on it
final double[] x = new double[n];
x[0] = 0.0;
x[n >> 1] = 2.0 * f[n >> 1];
for (int i = 1; i < (n >> 1); i++) {
final double a = FastMath.sin(i * FastMath.PI / n) * (f[i] + f[n-i]);
final double b = 0.5 * (f[i] - f[n-i]);
x[i] = a + b;
x[n - i] = a - b;
}
FastFourierTransformer transformer = new FastFourierTransformer();
Complex y[] = transformer.transform(x);
// reconstruct the FST result for the original array
transformed[0] = 0.0;
transformed[1] = 0.5 * y[0].getReal();
for (int i = 1; i < (n >> 1); i++) {
transformed[2 * i] = -y[i].getImaginary();
transformed[2 * i + 1] = y[i].getReal() + transformed[2 * i - 1];
}
return transformed;
}
示例5: testOnDistortedSine
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
@Test
public void testOnDistortedSine() {
int numPoints = 100;
double[] xval = new double[numPoints];
double[] yval = new double[numPoints];
double xnoise = 0.1;
double ynoise = 0.2;
generateSineData(xval, yval, xnoise, ynoise);
LoessInterpolator li = new LoessInterpolator(0.3, 4, 1e-12);
double[] res = li.smooth(xval, yval);
// Check that the resulting curve differs from
// the "real" sine less than the jittered one
double noisyResidualSum = 0;
double fitResidualSum = 0;
for(int i = 0; i < numPoints; ++i) {
double expected = FastMath.sin(xval[i]);
double noisy = yval[i];
double fit = res[i];
noisyResidualSum += FastMath.pow(noisy - expected, 2);
fitResidualSum += FastMath.pow(fit - expected, 2);
}
Assert.assertTrue(fitResidualSum < noisyResidualSum);
}
示例6: integrateWithSpecifiedStep
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
private double integrateWithSpecifiedStep(double omega,
double t0, double t,
double step)
throws MathUserException, IntegratorException {
double[] y0 = new double[2];
y0[0] = FastMath.sin(omega * t0);
y0[1] = omega * FastMath.cos(omega * t0);
ClassicalRungeKuttaIntegrator i = new ClassicalRungeKuttaIntegrator(step);
double[] y = new double[2];
i.integrate(new FirstOrderConverter(new Equations(1, omega)), t0, y0, t, y);
return y[0];
}
示例7: TestProblem4
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/** Simple constructor. */
public TestProblem4() {
super();
a = 1.2;
double[] y0 = { FastMath.sin(a), FastMath.cos(a) };
setInitialConditions(0.0, y0);
setFinalConditions(15);
double[] errorScale = { 1.0, 0.0 };
setErrorScale(errorScale);
y = new double[y0.length];
}
示例8: computeTheoreticalState
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
@Override
public double[] computeTheoreticalState(double t) {
double sin = FastMath.sin(t + a);
double cos = FastMath.cos(t + a);
y[0] = FastMath.abs(sin);
y[1] = (sin >= 0) ? cos : -cos;
return y;
}
示例9: call
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
public static TypeFloat call(TypeInt x)
{
BigInteger val = x.getValue();
// Check for overflow
if (DOUBLE_MAX.compareTo(val) < 0 || DOUBLE_MIN.compareTo(val) > 0)
throw new ExpressionFault.ValueError("overflow");
Double ret = FastMath.sin(val.doubleValue());
return new TypeFloat(ret);
}
示例10: testSmallStep
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
@Test
public void testSmallStep()
throws MathUserException, IntegratorException {
double error = integrateWithSpecifiedStep(4.0, 0.0, 1.0, 1.0e-4)
- FastMath.sin(4.0);
Assert.assertTrue(FastMath.abs(error) < 1.0e-10);
}
示例11: calculatePower
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
* Use the (hitx,hity) point and given angle to calculate the power needed.
*
* @param angle
* @param hitx
* @param hity
* @return
*/
public static final int calculatePower(int angle, int hitx, int hity, int wind) {
//Caculate the running time
//0.055
//double K = GameDataManager.getInstance().getGameDataAsDouble(GameDataKey.BATTLE_ATTACK_K, 0.059081);
//double F = GameDataManager.getInstance().getGameDataAsDouble(GameDataKey.BATTLE_ATTACK_F, 0.075);
//int g = GameDataManager.getInstance().getGameDataAsInt(GameDataKey.BATTLE_ATTACK_G, 760);
double rad = angle/180.0*Math.PI;
double sin = FastMath.sin(rad);
double cos = FastMath.cos(rad);
double tx = hitx/3;
int ty = 0;
double a = sin;
double b = -ty;
double c = 0;
double d = Math.abs(tx*tx / (2*cos));
int power = (int)MathUtil.solveCubicEquation(a, b, c, d);
logger.debug("a:{},b:{},c:{},d:{},wind:{},power:{}", new Object[]{a, b, c, d,wind, power});
if ( power < 0 ) {
power = -power;
}
if ( power > 100 ) {
power = 100;
}
/**
* wind < 0 风向向右侧
* wind > 0 风向向左侧
*/
if ( wind < 0 && angle > 90 ) {
power += -wind * 2 + 5;
} else if ( wind < 0 && angle < 90 ) {
/**
* 村口小桥顺风情况下计算的力度偏小,所以
* 这里去掉了风力的数值
* 2013-01-14
*/
//power -= -wind * 2 - 5;
} else if ( wind > 0 && angle < 90 ) {
power += wind * 2 + 5;
} else if ( wind > 0 && angle > 90 ) {
power -= wind * 2 - 5;
}
return (int)power;
}
示例12: Rotation
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/** Build a rotation from an axis and an angle.
* <p>We use the convention that angles are oriented according to
* the effect of the rotation on vectors around the axis. That means
* that if (i, j, k) is a direct frame and if we first provide +k as
* the axis and π/2 as the angle to this constructor, and then
* {@link #applyTo(Vector3D) apply} the instance to +i, we will get
* +j.</p>
* <p>Another way to represent our convention is to say that a rotation
* of angle θ about the unit vector (x, y, z) is the same as the
* rotation build from quaternion components { cos(-θ/2),
* x * sin(-θ/2), y * sin(-θ/2), z * sin(-θ/2) }.
* Note the minus sign on the angle!</p>
* <p>On the one hand this convention is consistent with a vectorial
* perspective (moving vectors in fixed frames), on the other hand it
* is different from conventions with a frame perspective (fixed vectors
* viewed from different frames) like the ones used for example in spacecraft
* attitude community or in the graphics community.</p>
* @param axis axis around which to rotate
* @param angle rotation angle.
* @exception ArithmeticException if the axis norm is zero
*/
public Rotation(Vector3D axis, double angle) {
double norm = axis.getNorm();
if (norm == 0) {
throw MathRuntimeException.createArithmeticException(LocalizedFormats.ZERO_NORM_FOR_ROTATION_AXIS);
}
double halfAngle = -0.5 * angle;
double coeff = FastMath.sin(halfAngle) / norm;
q0 = FastMath.cos (halfAngle);
q1 = coeff * axis.getX();
q2 = coeff * axis.getY();
q3 = coeff * axis.getZ();
}
示例13: value
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} */
public double value(double x) {
return FastMath.sin(x);
}
示例14: fct
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
* Perform the FCT algorithm (including inverse).
*
* @param f the real data array to be transformed
* @return the real transformed array
* @throws IllegalArgumentException if any parameters are invalid
*/
protected double[] fct(double f[])
throws IllegalArgumentException {
final double transformed[] = new double[f.length];
final int n = f.length - 1;
if (!FastFourierTransformer.isPowerOf2(n)) {
throw MathRuntimeException.createIllegalArgumentException(
LocalizedFormats.NOT_POWER_OF_TWO_PLUS_ONE,
f.length);
}
if (n == 1) { // trivial case
transformed[0] = 0.5 * (f[0] + f[1]);
transformed[1] = 0.5 * (f[0] - f[1]);
return transformed;
}
// construct a new array and perform FFT on it
final double[] x = new double[n];
x[0] = 0.5 * (f[0] + f[n]);
x[n >> 1] = f[n >> 1];
double t1 = 0.5 * (f[0] - f[n]); // temporary variable for transformed[1]
for (int i = 1; i < (n >> 1); i++) {
final double a = 0.5 * (f[i] + f[n-i]);
final double b = FastMath.sin(i * FastMath.PI / n) * (f[i] - f[n-i]);
final double c = FastMath.cos(i * FastMath.PI / n) * (f[i] - f[n-i]);
x[i] = a - b;
x[n-i] = a + b;
t1 += c;
}
FastFourierTransformer transformer = new FastFourierTransformer();
Complex y[] = transformer.transform(x);
// reconstruct the FCT result for the original array
transformed[0] = y[0].getReal();
transformed[1] = t1;
for (int i = 1; i < (n >> 1); i++) {
transformed[2 * i] = y[i].getReal();
transformed[2 * i + 1] = transformed[2 * i - 1] - y[i].getImaginary();
}
transformed[n] = y[n >> 1].getReal();
return transformed;
}
示例15: value
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} */
public double value(double x) {
return FastMath.abs(x) < 1e-9 ? 1 : FastMath.sin(x) / x;
}