List of usage examples for java.lang Math toRadians
public static double toRadians(double angdeg)
From source file:org.jrman.parser.Parser.java
public void addTorus(final float majorRadius, final float minorRadius, float pMin, float pMax, float tMax, final ParameterList parameters) { if (inAreaLightSource) return;/*from w ww .j ava 2 s . c om*/ final float phiMin = (float) Math.toRadians(pMin); final float phiMax = (float) Math.toRadians(pMax); final float thetaMax = (float) Math.toRadians(tMax); if (!inObject) { renderer.addPrimitive( new Torus(majorRadius, minorRadius, phiMin, phiMax, 0f, thetaMax, parameters, getAttributes())); torusCount++; } else { final Transform transform = currentAttributes.getTransform(); currentObjectInstanceList.addPrimitiveCreator(new ObjectInstanceList.PrimitiveCreator() { public Primitive create(Attributes attributes) { torusCount++; return new Torus(majorRadius, minorRadius, phiMin, phiMax, 0f, thetaMax, parameters, createAttributes(transform, attributes)); } }); } }
From source file:AppearanceExplorer.java
Shape3D createNGCube(float creaseAngle) { // color cube int[] indices = { 0, 3, 4, 2, // left face x = -1 0, 1, 5, 3, // bottom face y = -1 0, 2, 6, 1, // back face z = -1 7, 5, 1, 6, // right face x = 1 7, 6, 2, 4, // top face y = 1 7, 4, 3, 5 // front face z = 1 };//from w w w .j a va 2 s . co m Point3f pts[] = new Point3f[8]; pts[0] = new Point3f(-1.0f, -1.0f, -1.0f); pts[1] = new Point3f(1.0f, -1.0f, -1.0f); pts[2] = new Point3f(-1.0f, 1.0f, -1.0f); pts[3] = new Point3f(-1.0f, -1.0f, 1.0f); pts[4] = new Point3f(-1.0f, 1.0f, 1.0f); pts[5] = new Point3f(1.0f, -1.0f, 1.0f); pts[6] = new Point3f(1.0f, 1.0f, -1.0f); pts[7] = new Point3f(1.0f, 1.0f, 1.0f); GeometryInfo gi = new GeometryInfo(GeometryInfo.QUAD_ARRAY); gi.setCoordinates(pts); gi.setCoordinateIndices(indices); NormalGenerator ng = new NormalGenerator(); ng.setCreaseAngle((float) Math.toRadians(creaseAngle)); ng.generateNormals(gi); GeometryArray cube = gi.getGeometryArray(); return new Shape3D(cube, appearance); }
From source file:fr.inria.wimmics.prissma.selection.Matcher.java
/** * Compute geographic distance with the haversine formula. * Earth radius expressed in Km.// w ww. java2s .co m * @param lat1 * @param lng1 * @param lat2 * @param lng2 * @return distance in Km */ private double haversineDistance(double lat1, double lng1, double lat2, double lng2) { double earthRadius = 6371; // Km double dLat = Math.toRadians(lat2 - lat1); double dLng = Math.toRadians(lng2 - lng1); double sindLat = Math.sin(dLat / 2); double sindLng = Math.sin(dLng / 2); double a = Math.pow(sindLat, 2) + Math.pow(sindLng, 2) * Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); double dist = earthRadius * c; return dist; }
From source file:org.cryptsecure.Utility.java
/** * Gets the tile number for OpenStreetMap. * /*ww w.j a va 2 s. c o m*/ * @param lat * the lat * @param lon * the lon * @param zoom * the zoom * @return the tile number */ public static String getTileNumber(double lat, double lon, final int zoom) { // if (zoom == 17) { //250 // lat += 0.0002000; // lon -= 0.0015000; // // lon -= 0.001000; // } // else if (zoom == 16) { //500 // lat += 0.0008000; // lon -= 0.0008000; // // lon -= 2*0.001000; // } int xtile = (int) Math.floor(((lon + 180) / 360) * (1 << zoom)); int ytile = (int) Math .floor((1 - Math.log(Math.tan(Math.toRadians(lat)) + 1 / Math.cos(Math.toRadians(lat))) / Math.PI) / 2 * (1 << zoom)); if (xtile < 0) xtile = 0; if (xtile >= (1 << zoom)) xtile = ((1 << zoom) - 1); if (ytile < 0) ytile = 0; if (ytile >= (1 << zoom)) ytile = ((1 << zoom) - 1); return ("" + zoom + "/" + xtile + "/" + ytile); }
From source file:jp.furplag.util.commons.NumberUtilsTest.java
/** * {@link jp.furplag.util.commons.NumberUtils#cos(java.lang.Number, boolean)}. *///from ww w.ja v a2 s .c o m @SuppressWarnings("unchecked") @Test public void testCosNumberBoolean() { // [TODO] // assertEquals("null", null, cos(null, false)); // assertEquals("null", (Object) Math.cos(Math.toRadians(0d)), cos(null, true)); for (Class<?> type : NUMBERS) { int i = ObjectUtils.isAny(type, byte.class, Byte.class) ? -128 : -720; while (i <= (ObjectUtils.isAny(type, byte.class, Byte.class) ? 127 : 720)) { assertEquals("deg: " + i + ": " + type.getSimpleName(), (Object) Math.cos(Math.toRadians(i)), cos(valueOf(i, (Class<? extends Number>) type), false)); assertEquals("deg: " + i + ": " + type.getSimpleName(), (Object) Math.cos(Math.toRadians(i)), cos(toRadians(valueOf(i, (Class<? extends Number>) type)), true)); i++; } } }
From source file:com.google.vrtoolkit.cardboard.samples.treasurehunt.MainActivity.java
/** * Find a new random position for the object. * * <p>We'll rotate it around the Y-axis so it's out of sight, and then up or down by a little bit. *//*from w w w. j av a 2 s .c o m*/ private void hideObject() { float[] rotationMatrix = new float[16]; float[] posVec = new float[4]; // First rotate in XZ plane, between 90 and 270 deg away, and scale so that we vary // the object's distance from the user. float angleXZ = (float) Math.random() * 180 + 90; Matrix.setRotateM(rotationMatrix, 0, angleXZ, 0f, 1f, 0f); float oldObjectDistance = objectDistance; objectDistance = (float) Math.random() * (MAX_MODEL_DISTANCE - MIN_MODEL_DISTANCE) + MIN_MODEL_DISTANCE; float objectScalingFactor = objectDistance / oldObjectDistance; Matrix.scaleM(rotationMatrix, 0, objectScalingFactor, objectScalingFactor, objectScalingFactor); Matrix.multiplyMV(posVec, 0, rotationMatrix, 0, modelCube, 12); float angleY = (float) Math.random() * 80 - 40; // Angle in Y plane, between -40 and 40. angleY = (float) Math.toRadians(angleY); float newY = (float) Math.tan(angleY) * objectDistance; modelPosition[0] = posVec[0]; modelPosition[1] = newY; modelPosition[2] = posVec[2]; updateModelPosition(); }
From source file:code.Servlet.java
private void getSteps(String idEvent, HttpServletResponse response, Statement stmt, PrintWriter out) throws IOException, SQLException { System.out.println("getSteps"); String query = "SELECT * FROM event join city where event.city_name=city.name and event.idEvent=" + idEvent + "'"; ResultSet res = stmt.executeQuery(query); if (!res.next()) { System.out.println("Nessun evento"); }// ww w . j a v a 2s .c o m Location start = new Location(Double.parseDouble(res.getString("start_lat")), Double.parseDouble(res.getString("start_lon"))); query = "select count(*) as num from step where Event_idEvent=" + idEvent + "'"; res = stmt.executeQuery(query); if (!res.next()) { System.out.println("Nessuno steps nell' evento 1"); } int N = Integer.parseInt(res.getString("num")) - 1; if (N == -1) { System.out.println("Nessuno steps nell' evento 2"); } query = "select * from step where Event_idEvent=" + idEvent + "' order by rand()"; res = stmt.executeQuery(query); if (!res.next()) { System.out.println("Nessuno step nell' evento"); } double ai, bi; double[] tete = new double[N + 1]; Location[] indizzi = new Location[N + 1]; String resp = ""; for (int i = 0; i < N + 1; i++) { tete[i] = Double.parseDouble(res.getString("angle")); bi = lenPasso * Math.cos(Math.toRadians(computeTeta(tete[i]))); if (tete[i] > 90 && tete[i] < 270) { bi *= -1; } ai = lenPasso * Math.sin(Math.toRadians(computeTeta(tete[i]))); if (tete[i] > 180 && tete[i] < 360) { ai *= -1; } System.out.println(i + " -> bi: " + bi + " ai:" + ai + " teta: " + tete[i]); indizzi[i] = new Location(); if (i == 0) { indizzi[i].lat = start.lat + bi * kmToLat; indizzi[i].lon = start.lon + ai * kmToLon; } else { indizzi[i].lat = indizzi[i - 1].lat + bi * kmToLat; indizzi[i].lon = indizzi[i - 1].lon + ai * kmToLon; } resp += indizzi[i].lat + "," + indizzi[i].lon + "," + res.getString("idStep") + ";"; res.next(); } resp += "" + (N + 1); System.out.println("fine getSteps: " + resp); // *** System.out.flush(); response.setContentType("text/plain"); response.setContentLength(resp.length()); PrintWriter reply = response.getWriter(); reply.println(resp); out.close(); //non so se serve out out.flush(); }
From source file:org.jrman.parser.Parser.java
public void addCylinder(final float radius, final float zmin, final float zmax, float tMax, final ParameterList parameters) { if (inAreaLightSource) return;/*from w w w . ja v a2 s . c o m*/ final float thetaMax = (float) Math.toRadians(tMax); if (!inObject) { renderer.addPrimitive(new Cylinder(radius, zmin, zmax, 0f, thetaMax, parameters, getAttributes())); cylinderCount++; } else { final Transform transform = currentAttributes.getTransform(); currentObjectInstanceList.addPrimitiveCreator(new ObjectInstanceList.PrimitiveCreator() { public Primitive create(Attributes attributes) { cylinderCount++; return new Cylinder(radius, zmin, zmax, 0f, thetaMax, parameters, createAttributes(transform, attributes)); } }); } }
From source file:lucee.runtime.img.Image.java
public void rotateAxis(double angle) throws ExpressionException { getGraphics().rotate(Math.toRadians(angle)); }
From source file:org.jrman.parser.Parser.java
public void addCone(final float height, final float radius, float tMax, final ParameterList parameters) { if (inAreaLightSource) return;/*from www . java 2 s.c om*/ final float thetaMax = (float) Math.toRadians(tMax); if (!inObject) { renderer.addPrimitive(new Cone(radius, 0f, height, 0f, thetaMax, height, parameters, getAttributes())); coneCount++; } else { final Transform transform = currentAttributes.getTransform(); currentObjectInstanceList.addPrimitiveCreator(new ObjectInstanceList.PrimitiveCreator() { public Primitive create(Attributes attributes) { coneCount++; return new Cone(radius, 0f, height, 0f, thetaMax, height, parameters, createAttributes(transform, attributes)); } }); } }