List of usage examples for java.lang Math toRadians
public static double toRadians(double angdeg)
From source file:com.alvermont.terraj.planet.project.ConicalProjection.java
/** * Carry out the projection//ww w . ja va 2 s . c o m */ public void project() { setcolours(); final int width = getParameters().getProjectionParameters().getWidth(); final int height = getParameters().getProjectionParameters().getHeight(); final double lat = getParameters().getProjectionParameters().getLatitudeRadians(); final double lon = getParameters().getProjectionParameters().getLongitudeRadians(); final double scale = getParameters().getProjectionParameters().getScale(); final double hgrid = getParameters().getProjectionParameters().getHgrid(); final double vgrid = getParameters().getProjectionParameters().getVgrid(); final boolean doShade = getParameters().getProjectionParameters().isDoShade(); cacheParameters(); colours = new short[width][height]; shades = new short[width][height]; final double sla = Math.sin(lat); final double cla = Math.cos(lat); final double slo = Math.sin(lon); final double clo = Math.cos(lon); depth = (3 * ((int) (log2(scale * height)))) + 6; double k1; double c; double y2; double x; double y; double zz; double x1; double y1; double z1; double theta1; double theta2; double ymin; double ymax; double cos2; int i; int j; ymin = 2.0; ymax = -2.0; if (lat > 0) { k1 = 1.0 / Math.sin(lat); c = k1 * k1; y2 = Math.sqrt((c * (1.0 - Math.sin(lat / k1))) / (1.0 + Math.sin(lat / k1))); progress.progressStart(height, "Generating Terrain"); for (j = 0; j < height; ++j) { progress.progressStep(j); for (i = 0; i < width; ++i) { x = ((2.0 * i) - width) / height / scale; y = (((2.0 * j) - height) / height / scale) + y2; zz = (x * x) + (y * y); if (zz == 0.0) { theta1 = 0.0; } else { theta1 = k1 * Math.atan2(x, y); } if ((theta1 < -Math.PI) || (theta1 > Math.PI)) { colours[i][j] = backgroundColour; if (doShade) { shades[i][j] = 255; } } else { /* theta1 is longitude */ theta1 += (lon - (0.5 * Math.PI)); theta2 = k1 * Math.asin((zz - c) / (zz + c)); /* theta2 is latitude */ if ((theta2 > (0.5 * Math.PI)) || (theta2 < (-0.5 * Math.PI))) { colours[i][j] = backgroundColour; if (doShade) { shades[i][j] = 255; } } else { cos2 = Math.cos(theta2); y = Math.sin(theta2); if (y < ymin) { ymin = y; } if (y > ymax) { ymax = y; } colours[i][j] = (short) planet0(Math.cos(theta1) * cos2, y, -Math.sin(theta1) * cos2); if (doShade) { shades[i][j] = shade; } } } } } progress.progressComplete("Terrain Generated"); if (hgrid != 0.0) { /* draw horizontal gridlines */ for (theta1 = 0.0; theta1 > -90.0; theta1 -= hgrid) ; for (theta1 = theta1; theta1 < 90.0; theta1 += hgrid) { y = Math.sin(Math.toRadians(theta1)); if ((ymin <= y) && (y <= ymax)) { zz = Math.sqrt((c * (1.0 + Math.sin(Math.toRadians(theta1) / k1))) / (1.0 - Math.sin(Math.toRadians(theta1) / k1))); for (theta2 = -Math.PI + lon; theta2 < (Math.PI + lon); theta2 += (0.5 / width / scale)) { z1 = theta2 - lon; x1 = zz * Math.sin(z1 / k1); y1 = zz * Math.cos(z1 / k1); i = (int) (0.5 * ((height * scale * x1) + width)); j = (int) (0.5 * ((height * scale * (y1 - y2)) + height)); if ((0 <= i) && (i < width) && (0 <= j) && (j < height)) { colours[i][j] = BLACK; } } } } } if (vgrid != 0.0) { /* draw vertical gridlines */ for (theta1 = -0.5 * Math.PI; theta1 < (0.5 * Math.PI); theta1 += (0.5 / width / scale)) { y = Math.sin(theta1); if ((ymin <= y) && (y <= ymax)) { zz = Math.sqrt((c * (1.0 + Math.sin(theta1 / k1))) / (1.0 - Math.sin(theta1 / k1))); for (theta2 = 0.0; theta2 > (-180.0 + Math.toDegrees(lon)); theta2 -= vgrid) ; for (theta2 = theta2; theta2 < (180.0 + Math.toDegrees(lon)); theta2 += vgrid) { z1 = Math.toRadians(theta2) - lon; x1 = zz * Math.sin(z1 / k1); y1 = zz * Math.cos(z1 / k1); i = (int) (0.5 * ((height * scale * x1) + width)); j = (int) (0.5 * ((height * scale * (y1 - y2)) + height)); if ((0 <= i) && (i < width) && (0 <= j) && (j < height)) { colours[i][j] = BLACK; } } } } } } else { k1 = 1.0 / Math.sin(lat); c = k1 * k1; y2 = Math.sqrt((c * (1.0 - Math.sin(lat / k1))) / (1.0 + Math.sin(lat / k1))); progress.progressStart(height, "Generating Terrain"); for (j = 0; j < height; ++j) { progress.progressStep(j); for (i = 0; i < width; ++i) { x = ((2.0 * i) - width) / height / scale; y = (((2.0 * j) - height) / height / scale) - y2; zz = (x * x) + (y * y); if (zz == 0.0) { theta1 = 0.0; } else { theta1 = -k1 * Math.atan2(x, -y); } if ((theta1 < -Math.PI) || (theta1 > Math.PI)) { colours[i][j] = backgroundColour; if (doShade) { shades[i][j] = 255; } } else { /* theta1 is longitude */ theta1 += (lon - (0.5 * Math.PI)); theta2 = k1 * Math.asin((zz - c) / (zz + c)); /* theta2 is latitude */ if ((theta2 > (0.5 * Math.PI)) || (theta2 < (-0.5 * Math.PI))) { colours[i][j] = backgroundColour; if (doShade) { shades[i][j] = 255; } } else { cos2 = Math.cos(theta2); y = Math.sin(theta2); if (y < ymin) { ymin = y; } if (y > ymax) { ymax = y; } colours[i][j] = (short) planet0(Math.cos(theta1) * cos2, y, -Math.sin(theta1) * cos2); if (doShade) { shades[i][j] = shade; } } } } } progress.progressComplete("Terrain Generated"); if (hgrid != 0.0) { /* draw horizontal gridlines */ for (theta1 = 0.0; theta1 > -90.0; theta1 -= hgrid) ; for (theta1 = theta1; theta1 < 90.0; theta1 += hgrid) { y = Math.sin(Math.toRadians(theta1)); if ((ymin <= y) && (y <= ymax)) { zz = Math.sqrt((c * (1.0 + Math.sin(Math.toRadians(theta1) / k1))) / (1.0 - Math.sin(Math.toRadians(theta1) / k1))); for (theta2 = -Math.PI + lon; theta2 < (Math.PI + lon); theta2 += (0.5 / width / scale)) { z1 = theta2 - lon; x1 = -zz * Math.sin(z1 / k1); y1 = -zz * Math.cos(z1 / k1); i = (int) (0.5 * ((height * scale * x1) + width)); j = (int) (0.5 * ((height * scale * (y1 + y2)) + height)); if ((0 <= i) && (i < width) && (0 <= j) && (j < height)) { colours[i][j] = BLACK; } } } } } if (vgrid != 0.0) { /* draw vertical gridlines */ for (theta1 = -0.5 * Math.PI; theta1 < (0.5 * Math.PI); theta1 += (0.5 / width / scale)) { y = Math.sin(theta1); if ((ymin <= y) && (y <= ymax)) { zz = Math.sqrt((c * (1.0 + Math.sin(theta1 / k1))) / (1.0 - Math.sin(theta1 / k1))); for (theta2 = 0.0; theta2 > (-180.0 + Math.toDegrees(lon)); theta2 -= vgrid) ; for (theta2 = theta2; theta2 < (180.0 + Math.toDegrees(lon)); theta2 += vgrid) { z1 = Math.toRadians(theta2) - lon; x1 = -zz * Math.sin(z1 / k1); y1 = -zz * Math.cos(z1 / k1); i = (int) (0.5 * ((height * scale * x1) + width)); j = (int) (0.5 * ((height * scale * (y1 + y2)) + height)); if ((0 <= i) && (i < width) && (0 <= j) && (j < height)) { colours[i][j] = BLACK; } } } } } } if (doShade) { smoothshades(); } doOutlining(); }
From source file:org.openecomp.sdc.be.components.impl.CompositionBusinessLogic.java
private void buildCirclePatternForOneGroupOfCps(ImmutablePair<Double, Double> vfcLocation, List<ComponentInstance> cpsGroup, Map<ImmutablePair<Double, Double>, ComponentInstance> componentInstLocations) { final int numberOfCps = cpsGroup.size(); double angleBetweenCps = (!cpsGroup.isEmpty()) ? Math.toRadians(360) / numberOfCps : 0; double currentAngle = 0; Double xCenter = vfcLocation.getLeft(); Double yCenter = vfcLocation.getRight(); for (ComponentInstance currCp : cpsGroup) { double cpXposition = xCenter + CompositionBusinessLogic.CP_RADIUS_FACTOR * Math.cos(currentAngle); double cpYposition = yCenter + CompositionBusinessLogic.CP_RADIUS_FACTOR * Math.sin(currentAngle); componentInstLocations.put(new ImmutablePair<Double, Double>(cpXposition, cpYposition), currCp); currentAngle += angleBetweenCps; }// w w w . ja v a 2s. c o m }
From source file:LightBug.java
void setupLights() { // set up the BoundingSphere for all the lights BoundingSphere bounds = new BoundingSphere(new Point3d(), 100.0); // create the switch and set the default lightSwitch = new Switch(); lightSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE); lightSwitch.setWhichChild(LIGHT_DIRECTIONAL); // Set up the directional light Vector3f lightDirection = new Vector3f(0.0f, 0.0f, -1.0f); lightDirectional = new DirectionalLight(white, lightDirection); lightDirectional.setInfluencingBounds(bounds); lightSwitch.addChild(lightDirectional); // Set up the point light Point3f lightPosition = new Point3f(-1.0f, 1.0f, 0.6f); Point3f lightAttenuation = new Point3f(0.0f, 1.0f, 0.0f); lightPoint = new PointLight(white, lightPosition, lightAttenuation); lightPoint.setInfluencingBounds(bounds); lightSwitch.addChild(lightPoint);/*w ww . j av a 2 s . co m*/ // Set up the spot light // Point the light back at the origin Vector3f lightSpotDirection = new Vector3f(lightPosition); lightSpotDirection.negate(); // point back lightSpotDirection.normalize(); // make unit length float spreadAngle = 60; // degrees float concentration = 5.0f; lightSpot = new SpotLight(white, lightPosition, lightAttenuation, lightSpotDirection, (float) Math.toRadians(spreadAngle), concentration); lightSpot.setInfluencingBounds(bounds); lightSwitch.addChild(lightSpot); }
From source file:rod_design_compute.ShowPanel.java
private void drawBasePoint(Point point, Graphics g) { int x = toScreenX(point.X); int y = toScreenY(point.Y); int lengthTri = 4 * radiusBase; int x1 = (int) (x - lengthTri * Math.sin(Math.toRadians(30))); int y1 = (int) (y + lengthTri * Math.cos(Math.toRadians(30))); int x2 = (int) (x + lengthTri * Math.sin(Math.toRadians(30))); int y2 = (int) (y + lengthTri * Math.cos(Math.toRadians(30))); g.drawLine(x, y, x1, y1);//from ww w .j av a 2s . c om g.drawLine(x, y, x2, y2); g.drawLine(x1 - radiusBase, y1, x2 + radiusBase, y2); g.drawLine(x1, y1, x1 - radiusBase, y1 + radiusBase); g.drawLine(x1 + radiusBase, y1, x1 + radiusBase - radiusBase, y1 + radiusBase); g.drawLine(x1 + 2 * radiusBase, y1, x1 + 2 * radiusBase - radiusBase, y1 + radiusBase); g.drawLine(x1 + 3 * radiusBase, y1, x1 + 3 * radiusBase - radiusBase, y1 + radiusBase); g.drawLine(x1 + 4 * radiusBase, y1, x1 + 4 * radiusBase - radiusBase, y1 + radiusBase); g.setColor(Color.white); g.fillOval(x - radiusBase, y - radiusBase, radiusBase * 2, radiusBase * 2); g.setColor(Color.black); g.drawOval(x - radiusBase, y - radiusBase, radiusBase * 2, radiusBase * 2); }
From source file:fr.amap.viewer3d.object.camera.TrackballCamera.java
public void rotateFromOrientationV2(float offsetX, float offsetY) { //get current theta and phi SphericalCoordinates sc1 = new SphericalCoordinates(); sc1.toSpherical(new Point3d(location.x - target.x, location.y - target.y, location.z - target.z)); float oldTheta = (float) sc1.getAzimut(); float oldPhi = (float) sc1.getZenith(); if (location.x == target.x && location.y == target.y) { SphericalCoordinates sc2 = new SphericalCoordinates(); sc2.toSpherical(upVec.x, upVec.y, upVec.z); double azimut1 = sc2.getAzimut(); oldTheta = (float) -azimut1; if (upVec.y == -1) { offsetY = 0;// ww w .j a v a 2 s . c o m } } //theta doit tre compris entre 0 et 2pi //phi doit tre compris entre entre ]0 et pi[ float theta = 0, phi = 0; forwardVec = getForwardVector(); float radius = Vec3F.length(forwardVec); float thetaStep = (float) Math.toRadians(Math.abs(offsetX)); float phiStep = (float) Math.toRadians(Math.abs(offsetY / 2.0f)); //float thetaStep = (float) ((Math.PI * 2)/360.0f); //1 step //float phiStep = (float) ((Math.PI * 2)/360.0f); //1 step theta += oldTheta; phi += oldPhi; if (offsetX > 0) { theta -= thetaStep; } else if (offsetX < 0) { theta += thetaStep; } //theta = normalizeTheta(theta); if (offsetY > 0) { phi -= phiStep; if (phi < 0) { phi += phiStep; } } else if (offsetY < 0) { if (phi + phiStep < Math.PI) { phi += phiStep; } /*if(phi > Math.PI){ phi -= phiStep + 0.000001; }*/ } //phi = normalizePhi(phi); SphericalCoordinates sc = new SphericalCoordinates(theta, phi, radius); Point3d cartesian = sc.toCartesian(); location.x = target.x + (float) cartesian.getX(); location.y = target.y + (float) cartesian.getY(); location.z = target.z + (float) cartesian.getZ(); updateViewMatrix(); }
From source file:de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers.PDFBoxThumbnailer.java
private BufferedImage convertToImage(final PDPage page, final int imageType, final int thumbWidth, final int thumbHeight)/* */ throws IOException /* */ {/* ww w . ja v a 2 s . c o m*/ /* 707 */ final PDRectangle mBox = page.findMediaBox(); /* 708 */ final float widthPt = mBox.getWidth(); /* 709 */ final float heightPt = mBox.getHeight(); /* 711 */ final int widthPx = thumbWidth; // Math.round(widthPt * scaling); /* 712 */ final int heightPx = thumbHeight; // Math.round(heightPt * scaling); /* 710 */ final double scaling = Math.min((double) thumbWidth / widthPt, (double) thumbHeight / heightPt); // resolution / 72.0F; /* */ /* 714 */ final Dimension pageDimension = new Dimension((int) widthPt, (int) heightPt); /* */ /* 716 */ final BufferedImage retval = new BufferedImage(widthPx, heightPx, imageType); /* 717 */ final Graphics2D graphics = (Graphics2D) retval.getGraphics(); /* 718 */ graphics.setBackground(PDFBoxThumbnailer.TRANSPARENT_WHITE); /* 719 */ graphics.clearRect(0, 0, retval.getWidth(), retval.getHeight()); /* 720 */ graphics.scale(scaling, scaling); /* 721 */ final PageDrawer drawer = new PageDrawer(); /* 722 */ drawer.drawPage(graphics, page, pageDimension); /* */ try /* */ { /* 728 */ final int rotation = page.findRotation(); /* 729 */ if (rotation == 90 || rotation == 270) /* */ { /* 731 */ final int w = retval.getWidth(); /* 732 */ final int h = retval.getHeight(); /* 733 */ final BufferedImage rotatedImg = new BufferedImage(w, h, retval.getType()); /* 734 */ final Graphics2D g = rotatedImg.createGraphics(); /* 735 */ g.rotate(Math.toRadians(rotation), w / 2, h / 2); /* 736 */ g.drawImage(retval, null, 0, 0); /* */ } /* */ } /* */ catch (final ImagingOpException e) /* */ { /* 741 */ //log.warn("Unable to rotate page image", e); /* */ } /* */ /* 744 */ return retval; /* */ }
From source file:com.esri.geoevent.solutions.processor.rangefan.RangeFanProcessor.java
private Geometry constructRangeFan(double x, double y, double range, String unit, double bearing, double traversal) throws Exception { try {/*from www. java2 s .co m*/ Polygon fan = new Polygon(); Point center = new Point(); center.setX(x); center.setY(y); Point centerProj = (Point) GeometryEngine.project(center, srIn, srBuffer); double centerX = centerProj.getX(); double centerY = centerProj.getY(); bearing = GeometryUtility.Geo2Arithmetic(bearing); double leftAngle = bearing - (traversal / 2); double rightAngle = bearing + (traversal / 2); int count = (int) Math.round(Math.abs(leftAngle - rightAngle)); fan.startPath(centerProj); UnitConverter uc = new UnitConverter(); range = uc.Convert(range, unit, srBuffer); for (int i = 0; i < count; ++i) { double d = Math.toRadians(leftAngle + i); double arcX = centerX + (range * Math.cos(d)); double arcY = centerY + (range * Math.sin(d)); Point arcPt = new Point(arcX, arcY); fan.lineTo(arcPt); } fan.closeAllPaths(); return fan; } catch (Exception e) { LOG.error(e.getMessage()); throw e; } }
From source file:org.esa.beam.util.math.FastMathTest.java
@Test public void testMathToRadians() { for (double i = 0; i < numItr; ++i) { double val = Math.toRadians(i); }/*from www . java 2 s . c om*/ }
From source file:ffx.potential.bonded.LoopClosure.java
/** * Initialize Loop Closure.//from w ww .j a v a2 s . co m */ private void initializeLoopClosure() { double[] axis = new double[3]; double[] rr_a1 = new double[3]; double[] rr_c1 = new double[3]; double[] rr_n2 = new double[3]; double[] rr_a2 = new double[3]; double[] rr_n2a2_ref = new double[3]; double[] rr_c1a1 = new double[3]; double[] rr_a1a2 = new double[3]; double[] dr = new double[3]; double[] bb_c1a1 = new double[3]; double[] bb_a1a2 = new double[3]; double[] bb_a2n2 = new double[3]; double[] p = new double[4]; double[][] Us = new double[3][3]; double[] mulpro = new double[3]; double[] tmp_val = new double[3]; //initializing initial length, angle, and torsion arrays len0[0] = 1.52; len0[1] = 1.33; len0[2] = 1.45; len0[3] = 1.52; len0[4] = 1.33; len0[5] = 1.45; b_ang0[0] = Math.toRadians(111.6); b_ang0[1] = Math.toRadians(117.5); b_ang0[2] = Math.toRadians(120.0); b_ang0[3] = Math.toRadians(111.6); b_ang0[4] = Math.toRadians(117.5); b_ang0[5] = Math.toRadians(120.0); b_ang0[6] = Math.toRadians(111.6); t_ang0[0] = Math.PI; t_ang0[1] = Math.PI; for (int i = 0; i < 3; i++) { rr_c1[i] = 0.0; } //initializing axis axis[0] = 1.0; axis[1] = 0.0; axis[2] = 0.0; for (int i = 0; i < 2; i++) { //iniitalizing rr_a1 array rr_a1[0] = cos(b_ang0[3 * i + 1]) * len0[3 * i]; rr_a1[1] = sin(b_ang0[3 * i + 1]) * len0[3 * i]; rr_a1[2] = 0.0e0; //initializing rr_n2 array rr_n2[0] = len0[3 * i + 1]; rr_n2[1] = 0.0e0; rr_n2[2] = 0.0e0; //initializing rr_c1a1 array for (int j = 0; j < 3; j++) { rr_c1a1[j] = rr_a1[j] - rr_c1[j]; } //initializing rr_n2a2_ref array rr_n2a2_ref[0] = -cos(b_ang0[3 * i + 2]) * len0[3 * i + 2]; rr_n2a2_ref[1] = sin(b_ang0[3 * i + 2]) * len0[3 * i + 2]; rr_n2a2_ref[2] = 0.0e0; //quaternion is the quotient of two vectors in 3D space quaternion(axis, t_ang0[i] * 0.25e0, p); //means of representing a rotation of an axis about an origin // with no angular specification rotationMatrix(p, Us); //basic matrix multiplication matMul(Us, rr_n2a2_ref, mulpro); for (int j = 0; j < 3; j++) { rr_a2[j] = mulpro[j] + rr_n2[j]; rr_a1a2[j] = rr_a2[j] - rr_a1[j]; dr[j] = rr_a1a2[j]; } double len2 = dot(dr, dr); double len1 = sqrt(len2); len_aa[i + 1] = len1; for (int j = 0; j < 3; j++) { bb_c1a1[j] = rr_c1a1[j] / len0[3 * i]; bb_a1a2[j] = rr_a1a2[j] / len1; bb_a2n2[j] = (rr_n2[j] - rr_a2[j]) / len0[3 * i + 2]; } for (int j = 0; j < 3; j++) { tmp_val[j] = -bb_a1a2[j]; } calcBondAngle(tmp_val, bb_a2n2, xi[i + 1]); for (int j = 0; j < 3; j++) { tmp_val[j] = -bb_c1a1[j]; } calcBondAngle(bb_a1a2, tmp_val, eta[i]); calcDihedralAngle(bb_c1a1, bb_a1a2, bb_a2n2, delta[i + 1]); delta[i + 1][0] = PI - delta[i + 1][0]; } double a_min = b_ang0[3] - (xi[1][0] + eta[1][0]); double a_max = min((b_ang0[3] + (xi[1][0] + eta[1][0])), PI); aa13_min_sqr = pow(len_aa[1], 2) + pow(len_aa[2], 2) - 2.0 * len_aa[1] * len_aa[2] * cos(a_min); aa13_max_sqr = pow(len_aa[1], 2) + pow(len_aa[2], 2) - 2.0 * len_aa[1] * len_aa[2] * cos(a_max); }
From source file:org.wso2.carbon.iot.android.sense.event.streams.location.LocationDataReader.java
public double CalculationByDistance(double lat1, double lon1, double lat2, double lon2) { double Radius = EARTH_RADIUS; double dLat = Math.toRadians(lat2 - lat1); double dLon = Math.toRadians(lon2 - lon1); double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) * Math.sin(dLon / 2) * Math.sin(dLon / 2); double c = 2 * Math.asin(Math.sqrt(a)); return Radius * c; }