List of usage examples for java.lang Math cos
@HotSpotIntrinsicCandidate public static double cos(double a)
From source file:msi.gama.common.geometry.Rotation3D.java
/** * By default around the Z axis (PLUS_K) * //www. ja v a2 s . c o m * @param angle * rotation angle in radians */ public Rotation3D(final double angle) { final double halfAngle = -0.5 * angle; q0 = Math.cos(halfAngle); q1 = 0; q2 = 0; q3 = Math.sin(halfAngle); }
From source file:jat.core.cm.TwoBodyAPL.java
public double eccentricAnomaly(double ta) { double cta = Math.cos(ta); double e0 = Math.acos((e + cta) / (1.0 + e * cta)); return e0;//from w w w .java 2 s . c om }
From source file:com.sk89q.craftbook.sponge.mechanics.BounceBlocks.java
private void doAction(Entity entity, String positionString, Vector3d rotation) { if (entity instanceof Player) { if (!usePermissions.hasPermission((Subject) entity)) { return; }// w w w .ja va 2s. c om } double x = 0; double y; double z = 0; boolean straight = positionString.startsWith("!"); String[] bits = RegexUtil.COMMA_PATTERN.split(StringUtils.replace(positionString, "!", "")); if (bits.length == 0) { y = 0.5; } else if (bits.length == 1) { try { y = Double.parseDouble(bits[0]); } catch (NumberFormatException e) { y = 0.5; } } else { x = Double.parseDouble(bits[0]); y = Double.parseDouble(bits[1]); z = Double.parseDouble(bits[2]); } if (!straight) { double pitch = ((rotation.getX() + 90d) * Math.PI) / 180d; double yaw = ((rotation.getY() + 90d) * Math.PI) / 180d; x *= Math.sin(pitch) * Math.cos(yaw); z *= Math.sin(pitch) * Math.sin(yaw); } entity.setVelocity(new Vector3d(x, y, z)); entity.offer(Keys.FALL_DISTANCE, -20f); }
From source file:com.github.amsacode.predict4java.TLE.java
/** * Constructor.//w w w. j a va 2s. c o m * * @param tle the three line elements * @throws IllegalArgumentException here was something wrong with the TLE */ public TLE(final String[] tle) throws IllegalArgumentException { { if (null == tle) { throw new IllegalArgumentException("TLE was null"); } if (tle.length != THREELINES) { throw new IllegalArgumentException("TLE had " + tle.length + " elements"); } int lineCount = 0; for (final String line : tle) { testArguments(lineCount, line); lineCount++; } catnum = Integer.parseInt(StringUtils.strip(tle[1].substring(2, 7))); name = tle[0].trim(); setnum = Integer.parseInt(StringUtils.strip(tle[1].substring(64, 68))); year = Integer.parseInt(StringUtils.strip(tle[1].substring(18, 20))); refepoch = Double.parseDouble(tle[1].substring(20, 32)); incl = Double.parseDouble(tle[2].substring(8, 16)); raan = Double.parseDouble(tle[2].substring(17, 25)); eccn = 1.0e-07 * Double.parseDouble(tle[2].substring(26, 33)); argper = Double.parseDouble(tle[2].substring(34, 42)); meanan = Double.parseDouble(tle[2].substring(43, 51)); meanmo = Double.parseDouble(tle[2].substring(52, 63)); drag = Double.parseDouble(tle[1].substring(33, 43)); double tempnum = 1.0e-5 * Double.parseDouble(tle[1].substring(44, 50)); nddot6 = tempnum / Math.pow(10.0, Double.parseDouble(tle[1].substring(51, 52))); tempnum = 1.0e-5 * Double.parseDouble(tle[1].substring(53, 59)); bstar = tempnum / Math.pow(10.0, Double.parseDouble(tle[1].substring(60, 61))); orbitnum = Integer.parseInt(StringUtils.strip(tle[2].substring(63, 68))); /* reassign the values to thse which get used in calculations */ epoch = (1000.0 * getYear()) + getRefepoch(); double temp = incl; temp *= DEG2RAD; xincl = temp; temp = raan; temp *= DEG2RAD; xnodeo = temp; eo = eccn; temp = argper; temp *= DEG2RAD; omegao = temp; temp = meanan; temp *= DEG2RAD; xmo = temp; } /* Preprocess tle set */ { double temp; temp = TWO_PI / MINS_PERDAY / MINS_PERDAY; xno = meanmo * temp * MINS_PERDAY; xndt2o = drag * temp; double dd1 = XKE / xno; final double a1 = Math.pow(dd1, TWO_THIRDS); final double r1 = Math.cos(xincl); dd1 = 1.0 - eo * eo; temp = CK2 * 1.5f * (r1 * r1 * 3.0 - 1.0) / Math.pow(dd1, 1.5); final double del1 = temp / (a1 * a1); final double ao = a1 * (1.0 - del1 * (TWO_THIRDS * .5 + del1 * (del1 * 1.654320987654321 + 1.0))); final double delo = temp / (ao * ao); final double xnodp = xno / (delo + 1.0); /* Select a deep-space/near-earth ephemeris */ deepspace = TWO_PI / xnodp / MINS_PERDAY >= 0.15625; } }
From source file:edu.umn.cs.spatialHadoop.nasa.HDFRecordReader3.java
/** * Reads next NASA object from the array * @param key/* ww w . j av a 2s. c o m*/ * @param shape * @return * @throws IOException */ protected boolean nextObject(NASADataset key, NASAShape shape) throws IOException { if (dataArray == null) return false; // Key doesn't need to be changed because all points in the same dataset // have the same key while (position < Array.getLength(dataArray)) { // Set the x and y to longitude and latitude by doing the correct projection int row = position / nasaDataset.resolution; int col = position % nasaDataset.resolution; if (shape instanceof Point) { Point pt = (Point) shape; pt.y = (90 - nasaDataset.v * 10) - (double) row * 10 / nasaDataset.resolution; pt.x = (nasaDataset.h * 10 - 180) + (double) (col) * 10 / nasaDataset.resolution; pt.x /= Math.cos(pt.y * Math.PI / 180); } else if (shape instanceof Rectangle) { Rectangle rect = (Rectangle) shape; rect.y2 = (90 - nasaDataset.v * 10) - (double) row * 10 / nasaDataset.resolution; rect.y1 = (90 - nasaDataset.v * 10) - (double) (row + 1) * 10 / nasaDataset.resolution; double[] xs = new double[4]; xs[0] = xs[1] = (nasaDataset.h * 10 - 180) + (double) (col) * 10 / nasaDataset.resolution; xs[2] = xs[3] = (nasaDataset.h * 10 - 180) + (double) (col + 1) * 10 / nasaDataset.resolution; // Project all four corners and select the min-max for the rectangle xs[0] /= Math.cos(rect.y1 * Math.PI / 180); xs[1] /= Math.cos(rect.y2 * Math.PI / 180); xs[2] /= Math.cos(rect.y1 * Math.PI / 180); xs[3] /= Math.cos(rect.y2 * Math.PI / 180); rect.x1 = rect.x2 = xs[0]; for (double x : xs) { if (x < rect.x1) rect.x1 = x; if (x > rect.x2) rect.x2 = x; } } // if (projector != null) // projector.project(shape); shape.setTimestamp(key.time); // Read next value shape.setValue(dataArray[position]); position++; if (!skipFillValue || shape.getValue() != fillValue) return true; } return false; }
From source file:com.rapidminer.tools.expression.internal.function.AntlrParserTrigonometricTest.java
@Test public void cosInt() { try {/*from w ww. j av a 2 s. co m*/ Expression expression = getExpressionWithFunctionContext("cos(16)"); assertEquals(ExpressionType.DOUBLE, expression.getExpressionType()); assertEquals(Math.cos(16), expression.evaluateNumerical(), 1e-15); } catch (ExpressionException e) { assertNotNull(e.getMessage()); } }
From source file:Satellite.java
public static double[] Convert_To_Lat_Long(double[] posVec) { double Xcomp = posVec[0]; double Ycomp = posVec[1]; double Zcomp = posVec[2]; double longitude; double latitude; double altitude; //Done so all cases of longitudes are right if (Ycomp > 0) { if (Xcomp > 0) { longitude = Math.toDegrees(Math.atan(Ycomp / Xcomp)); } else {/*from www .j a va2s . c o m*/ longitude = 180 - Math.toDegrees(Math.atan(Math.abs(Ycomp / Xcomp))); } } else { if (Xcomp > 0) { longitude = -1 * Math.toDegrees(Math.atan(Math.abs(Ycomp / Xcomp))); } else { longitude = -1 * (180 - Math.toDegrees(Math.atan(Ycomp / Xcomp))); } } //Calculate latitude latitude = Math.toDegrees(Math.atan(Zcomp / Math.sqrt(Xcomp * Xcomp + Ycomp * Ycomp))); //Calculate radius and altitude double EPR = 6356800; //Earth Polar Radius in meters double EER = 6378100; //Earth Equator Radius in meters double earthRadius = Math .sqrt((Math.pow(EPR * EPR * Math.cos(latitude), 2) + Math.pow(EER * EER * Math.cos(latitude), 2)) / (Math.pow(EPR * Math.cos(latitude), 2) + Math.pow(EER * Math.cos(latitude), 2))); double orbitRadius = Math.sqrt(Xcomp * Xcomp + Ycomp * Ycomp + Zcomp * Zcomp); altitude = orbitRadius - earthRadius; return new double[] { latitude, longitude, altitude }; }
From source file:au.com.rsutton.rosjava.differentialDrive.DiffTf.java
@Override public void onStart(ConnectedNode connectedNode) { // log = connectedNode.getLog(); final Publisher<Odometry> odomPub = Topic.ODOM.newPublisher(connectedNode, nameSpace); final Publisher<TransformStamped> odomBroadcaster = Topic.TF.newPublisher(connectedNode, nameSpace); // This CancellableLoop will be canceled automatically when the node // shuts//from w w w .jav a 2s. com // down. connectedNode.executeCancellableLoop(new CancellableLoop() { @Override protected void setup() { } @Override protected void loop() throws InterruptedException { update(); Thread.sleep(rate); } private void update() { long now = System.currentTimeMillis(); if (now > t_next) { long elapsed = now - then; then = now; elapsed /= 1000; // calculate odometry double d_left = 0; double d_right = 0; if (enc_left != null) { d_left = (left - enc_left) / ticks_meter; d_right = (right - enc_right) / ticks_meter; } enc_left = left; enc_right = right; // distance traveled is the average of the two wheels double d = (d_left + d_right) / 2; // this approximation works (in radians) for small angles th = (d_right - d_left) / base_width; // calculate velocities dx = d / elapsed; dr = th / elapsed; if (d != 0) { // calculate distance traveled in x and y x = Math.cos(th) * d; y = -Math.sin(th) * d; // calculate the final position of the robot x = x + (Math.cos(th) * x - Math.sin(th) * y); y = y + (Math.sin(th) * x + Math.cos(th) * y); } if (th != 0) { th = th + th; } // publish the odom information TransformStamped transform = odomBroadcaster.newMessage(); transform.getTransform().getRotation().setX(0); transform.getTransform().getRotation().setY(0); transform.getTransform().getRotation().setZ(Math.sin(th / 2)); transform.getTransform().getRotation().setW(Math.cos(th / 2)); transform.getTransform().getTranslation().setX(x); transform.getTransform().getTranslation().setY(y); transform.getTransform().getTranslation().setZ(0); transform.getHeader().setStamp(new Time()); transform.setChildFrameId(odom_frame_id); transform.getHeader().setFrameId(base_frame_id); odomBroadcaster.publish(transform); Odometry odom = odomPub.newMessage(); odom.getHeader().setStamp(new Time()); odom.getHeader().setFrameId(odom_frame_id); odom.getPose().getPose().getPosition().setX(x); odom.getPose().getPose().getPosition().setY(y); odom.getPose().getPose().getPosition().setZ(0); odom.getPose().getPose().setOrientation(transform.getTransform().getRotation()); odom.setChildFrameId(base_frame_id); odom.getTwist().getTwist().getLinear().setX(dx); odom.getTwist().getTwist().getLinear().setY(0); odom.getTwist().getTwist().getAngular().setZ(dr); odomPub.publish(odom); } } }); Subscriber<Int16> sub_lwheel = Topic.LWHEEL.newSubscriber(connectedNode, nameSpace); sub_lwheel.addMessageListener(new MessageListener<Int16>() { @Override public void onNewMessage(Int16 message) { short enc = message.getData(); if (enc < encoder_low_wrap && prev_lencoder > encoder_high_wrap) { lmult = lmult + 1; } if (enc > encoder_high_wrap && prev_lencoder < encoder_low_wrap) { lmult = lmult - 1; } left = 1.0 * (enc + lmult * (encoder_max - encoder_min)); prev_lencoder = enc; } }); Subscriber<Int16> sub_rwheel = Topic.RWHEEL.newSubscriber(connectedNode, nameSpace); sub_rwheel.addMessageListener(new MessageListener<Int16>() { @Override public void onNewMessage(Int16 message) { short enc = message.getData(); if (enc < encoder_low_wrap && prev_rencoder > encoder_high_wrap) { rmult = rmult + 1; } if (enc > encoder_high_wrap && prev_rencoder < encoder_low_wrap) { rmult = rmult - 1; } right = 1.0 * (enc + rmult * (encoder_max - encoder_min)); prev_rencoder = enc; } }); }
From source file:imagingbook.pub.fd.FourierDescriptor.java
/** * Reconstructs a single spatial point from this FD using * coefficients [mm,...,mp] = [m-,...,m+] at the fractional path position t in [0,1]. *//*w w w .j a va 2 s .c o m*/ private Complex getReconstructionPoint(double t, int mm, int mp) { double x = G[0].re; double y = G[0].im; for (int m = mm; m <= mp; m++) { if (m != 0) { Complex Gm = getCoefficient(m); double A = reconstructionScale * Gm.re; double B = reconstructionScale * Gm.im; double phi = 2 * Math.PI * m * t; double sinPhi = Math.sin(phi); double cosPhi = Math.cos(phi); x = x + A * cosPhi - B * sinPhi; y = y + A * sinPhi + B * cosPhi; } } return new Complex(x, y); }
From source file:es.udc.gii.common.eaf.benchmark.real_param.cec2005.CEC2005ObjectiveFunction.java
public double weierstrass(double[] x, final double a, final double b, final int kMax) { double sum = 0.0d; double sum2 = 0.0d; double sum3 = 0.0d; for (int i = 0; i < x.length; i++) { sum2 = 0.0d;//from www . j a v a2 s. com for (int k = 0; k <= kMax; k++) { sum2 += Math.pow(a, k) * Math.cos(2 * Math.PI * Math.pow(b, k) * (x[i] + 0.5)); } sum += sum2; } for (int k = 0; k <= kMax; k++) { sum3 += Math.pow(a, k) * Math.cos(2 * Math.PI * Math.pow(b, k) * 0.5); } return sum - x.length * sum3; }