List of usage examples for java.lang Math toRadians
public static double toRadians(double angdeg)
From source file:com.bc.jexp.impl.DefaultNamespace.java
private void registerDefaultFunctions() { registerFunction(new AbstractFunction.D("sin", 1) { public double evalD(final EvalEnv env, final Term[] args) { return FastMath.sin(args[0].evalD(env)); }//w ww. j ava 2 s . c om }); registerFunction(new AbstractFunction.D("cos", 1) { public double evalD(final EvalEnv env, final Term[] args) { return FastMath.cos(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("tan", 1) { public double evalD(final EvalEnv env, final Term[] args) { return FastMath.tan(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("asin", 1) { public double evalD(final EvalEnv env, final Term[] args) { return FastMath.asin(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("acos", 1) { public double evalD(final EvalEnv env, final Term[] args) { return FastMath.acos(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("atan", 1) { public double evalD(final EvalEnv env, final Term[] args) { return FastMath.atan(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("atan2", 2) { public double evalD(final EvalEnv env, final Term[] args) { return Math.atan2(args[0].evalD(env), args[1].evalD(env)); } }); registerFunction(new AbstractFunction.D("log", 1) { public double evalD(final EvalEnv env, final Term[] args) { return Math.log(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("log10", 1) { public double evalD(EvalEnv env, Term[] args) throws EvalException { return Math.log10(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("exp", 1) { public double evalD(final EvalEnv env, final Term[] args) { return FastMath.exp(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("exp10", 1) { public double evalD(EvalEnv env, Term[] args) throws EvalException { return FastMath.pow(10.0, args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("sqr", 1) { public double evalD(final EvalEnv env, final Term[] args) { double v = args[0].evalD(env); return v * v; } }); registerFunction(new AbstractFunction.D("sqrt", 1) { public double evalD(final EvalEnv env, final Term[] args) { return Math.sqrt(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("pow", 2) { public double evalD(final EvalEnv env, final Term[] args) { return FastMath.pow(args[0].evalD(env), args[1].evalD(env)); } }); registerFunction(new AbstractFunction.I("min", 2) { public int evalI(final EvalEnv env, final Term[] args) { return Math.min(args[0].evalI(env), args[1].evalI(env)); } }); registerFunction(new AbstractFunction.D("min", 2) { public double evalD(final EvalEnv env, final Term[] args) { return Math.min(args[0].evalD(env), args[1].evalD(env)); } }); registerFunction(new AbstractFunction.I("max", 2) { public int evalI(final EvalEnv env, final Term[] args) { return Math.max(args[0].evalI(env), args[1].evalI(env)); } }); registerFunction(new AbstractFunction.D("max", 2) { public double evalD(final EvalEnv env, final Term[] args) { return Math.max(args[0].evalD(env), args[1].evalD(env)); } }); registerFunction(new AbstractFunction.D("floor", 1) { public double evalD(EvalEnv env, Term[] args) throws EvalException { return Math.floor(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("round", 1) { public double evalD(EvalEnv env, Term[] args) throws EvalException { return Math.round(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("ceil", 1) { public double evalD(EvalEnv env, Term[] args) throws EvalException { return Math.ceil(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("rint", 1) { public double evalD(EvalEnv env, Term[] args) throws EvalException { return Math.rint(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.I("sign", 1) { public int evalI(final EvalEnv env, final Term[] args) { return ExtMath.sign(args[0].evalI(env)); } }); registerFunction(new AbstractFunction.D("sign", 1) { public double evalD(final EvalEnv env, final Term[] args) { return ExtMath.sign(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.I("abs", 1) { public int evalI(final EvalEnv env, final Term[] args) { return Math.abs(args[0].evalI(env)); } }); registerFunction(new AbstractFunction.D("abs", 1) { public double evalD(final EvalEnv env, final Term[] args) { return Math.abs(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("deg", 1) { public double evalD(final EvalEnv env, final Term[] args) { return Math.toDegrees(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("rad", 1) { public double evalD(final EvalEnv env, final Term[] args) { return Math.toRadians(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("ampl", 2) { public double evalD(final EvalEnv env, final Term[] args) { final double a = args[0].evalD(env); final double b = args[1].evalD(env); return Math.sqrt(a * a + b * b); } }); registerFunction(new AbstractFunction.D("phase", 2) { public double evalD(final EvalEnv env, final Term[] args) { final double a = args[0].evalD(env); final double b = args[1].evalD(env); return Math.atan2(b, a); } }); registerFunction(new AbstractFunction.B("feq", 2) { public boolean evalB(EvalEnv env, Term[] args) throws EvalException { final double x1 = args[0].evalD(env); final double x2 = args[1].evalD(env); return ExtMath.feq(x1, x2, EPS); } }); registerFunction(new AbstractFunction.B("feq", 3) { public boolean evalB(EvalEnv env, Term[] args) throws EvalException { final double x1 = args[0].evalD(env); final double x2 = args[1].evalD(env); final double eps = args[2].evalD(env); return ExtMath.feq(x1, x2, eps); } }); registerFunction(new AbstractFunction.B("fneq", 2) { public boolean evalB(EvalEnv env, Term[] args) throws EvalException { final double x1 = args[0].evalD(env); final double x2 = args[1].evalD(env); return ExtMath.fneq(x1, x2, EPS); } }); registerFunction(new AbstractFunction.B("fneq", 3) { public boolean evalB(EvalEnv env, Term[] args) throws EvalException { final double x1 = args[0].evalD(env); final double x2 = args[1].evalD(env); final double eps = args[2].evalD(env); return ExtMath.fneq(x1, x2, eps); } }); registerFunction(new AbstractFunction.B("inf", 1) { public boolean evalB(EvalEnv env, Term[] args) throws EvalException { return Double.isInfinite(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.B("nan", 1) { public boolean evalB(EvalEnv env, Term[] args) throws EvalException { return Double.isNaN(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("distance", -1) { public double evalD(final EvalEnv env, final Term[] args) { double sqrSum = 0.0; final int n = args.length / 2; for (int i = 0; i < n; i++) { final double v = args[i + n].evalD(env) - args[i].evalD(env); sqrSum += v * v; } return Math.sqrt(sqrSum); } }); registerFunction(new AbstractFunction.D("distance_deriv", -1) { public double evalD(final EvalEnv env, final Term[] args) { double sqrSum = 0.0; final int n = args.length / 2; for (int i = 0; i < n - 1; i++) { final double v1 = args[i + 1].evalD(env) - args[i].evalD(env); final double v2 = args[i + n + 1].evalD(env) - args[i + n].evalD(env); sqrSum += (v1 - v2) * (v1 - v2); } return Math.sqrt(sqrSum); } }); registerFunction(new AbstractFunction.D("distance_integ", -1) { public double evalD(final EvalEnv env, final Term[] args) { double sqrSum = 0.0; double v1Sum = 0.0; double v2Sum = 0.0; final int n = args.length / 2; for (int i = 0; i < n; i++) { v1Sum += args[i].evalD(env); v2Sum += args[i + n].evalD(env); sqrSum += (v2Sum - v1Sum) * (v2Sum - v1Sum); } return Math.sqrt(sqrSum); } }); registerFunction(new AbstractFunction.B("inrange", -1) { public boolean evalB(final EvalEnv env, final Term[] args) { final int n1 = args.length / 3; final int n2 = n1 + args.length / 3; for (int i = 0; i < n1; i++) { final double v = args[i].evalD(env); final double v1 = args[i + n1].evalD(env); final double v2 = args[i + n2].evalD(env); if (v < v1 || v > v2) { return false; } } return true; } }); registerFunction(new AbstractFunction.B("inrange_deriv", -1) { public boolean evalB(final EvalEnv env, final Term[] args) { final int n1 = args.length / 3; final int n2 = 2 * n1; for (int i = 0; i < n1 - 1; i++) { final double v = args[i + 1].evalD(env) - args[i].evalD(env); final double v1 = args[i + n1 + 1].evalD(env) - args[i + n1].evalD(env); final double v2 = args[i + n2 + 1].evalD(env) - args[i + n2].evalD(env); if (v < v1 || v > v2) { return false; } } return true; } }); registerFunction(new AbstractFunction.B("inrange_integ", -1) { public boolean evalB(final EvalEnv env, final Term[] args) { final int n1 = args.length / 3; final int n2 = 2 * n1; double vSum = 0.0; double v1Sum = 0.0; double v2Sum = 0.0; for (int i = 0; i < n1; i++) { vSum += args[i].evalD(env); v1Sum += args[i + n1].evalD(env); v2Sum += args[i + n2].evalD(env); if (vSum < v1Sum || vSum > v2Sum) { return false; } } return true; } }); }
From source file:io.github.data4all.handler.TagSuggestionHandler.java
/** * Get a bounding box of the location./*ww w. j av a 2s. c o m*/ * * @param lat * latitude of the location * @param lon * longitude of the location * @param radius * distance to bounds from location * @return a boundingBox */ private static double[] getBoundingBox(double lat, double lon, double radius) { final double result[] = new double[4]; result[0] = lat - Math.toDegrees(radius / (double) EARTH_RADIUS); // s result[1] = lon - Math.toDegrees(radius / (double) EARTH_RADIUS / Math.cos(Math.toRadians(lat))); // w result[2] = lat + Math.toDegrees(radius / (double) EARTH_RADIUS); // n result[3] = lon + Math.toDegrees(radius / (double) EARTH_RADIUS / Math.cos(Math.toRadians(lat))); // e return result; }
From source file:EnvironmentExplorer.java
void setupLights() { lightGroup = new Group(); // Set up the ambient light lightAmbient = new AmbientLight(darkGrey); lightAmbient.setInfluencingBounds(infiniteBounds); lightAmbient.setCapability(Light.ALLOW_STATE_WRITE); lightAmbient.setEnable(true);//www .java 2 s . c o m lightGroup.addChild(lightAmbient); // Set up the directional light Vector3f lightDirection = new Vector3f(0.65f, -0.65f, -0.40f); lightDirectional = new DirectionalLight(white, lightDirection); lightDirectional.setInfluencingBounds(infiniteBounds); lightDirectional.setEnable(true); lightDirectional.setCapability(Light.ALLOW_STATE_WRITE); lightGroup.addChild(lightDirectional); // Set up the point light Point3f lightPosition = new Point3f(-1.0f, 1.0f, 0.6f); lightPoint = new PointLight(white, lightPosition, attenuation); lightPoint.setInfluencingBounds(infiniteBounds); lightPoint.setEnable(false); lightPoint.setCapability(Light.ALLOW_STATE_WRITE); lightPoint.setCapability(PointLight.ALLOW_ATTENUATION_WRITE); lightGroup.addChild(lightPoint); // Set up the spot light // Point the light back at the origin lightSpot = new SpotLight(white, lightPosition, attenuation, lightDirection, (float) Math.toRadians(spotSpreadAngle), spotConcentration); lightSpot.setInfluencingBounds(infiniteBounds); lightSpot.setEnable(false); lightSpot.setCapability(Light.ALLOW_STATE_WRITE); lightSpot.setCapability(PointLight.ALLOW_ATTENUATION_WRITE); lightSpot.setCapability(SpotLight.ALLOW_CONCENTRATION_WRITE); lightSpot.setCapability(SpotLight.ALLOW_SPREAD_ANGLE_WRITE); lightGroup.addChild(lightSpot); }
From source file:nova.core.render.model.TechneModelProvider.java
@Override public void load(InputStream stream) { try {/*from w ww. j a v a 2s . c om*/ Map<String, byte[]> zipContents = new HashMap<>(); ZipInputStream zipInput = new ZipInputStream(stream); ZipEntry entry; while ((entry = zipInput.getNextEntry()) != null) { byte[] data = new byte[(int) entry.getSize()]; // For some reason, using read(byte[]) makes reading stall upon reaching a 0x1E byte int i = 0; while (zipInput.available() > 0 && i < data.length) { data[i++] = (byte) zipInput.read(); } zipContents.put(entry.getName(), data); } byte[] modelXml = zipContents.get("model.xml"); if (modelXml == null) { throw new RenderException("Model " + name + " contains no model.xml file"); } DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.parse(new ByteArrayInputStream(modelXml)); NodeList nodeListTechne = document.getElementsByTagName("Techne"); if (nodeListTechne.getLength() < 1) { throw new RenderException("Model " + name + " contains no Techne tag"); } NodeList nodeListModel = document.getElementsByTagName("Model"); if (nodeListModel.getLength() < 1) { throw new RenderException("Model " + name + " contains no Model tag"); } NamedNodeMap modelAttributes = nodeListModel.item(0).getAttributes(); if (modelAttributes == null) { throw new RenderException("Model " + name + " contains a Model tag with no attributes"); } NodeList textureSize = document.getElementsByTagName("TextureSize"); if (textureSize.getLength() == 0) throw new RenderException("Model has no texture size"); String[] textureDimensions = textureSize.item(0).getTextContent().split(","); double textureWidth = Integer.parseInt(textureDimensions[0]); double textureHeight = Integer.parseInt(textureDimensions[1]); NodeList shapes = document.getElementsByTagName("Shape"); for (int i = 0; i < shapes.getLength(); i++) { Node shape = shapes.item(i); NamedNodeMap shapeAttributes = shape.getAttributes(); if (shapeAttributes == null) { throw new RenderException("Shape #" + (i + 1) + " in " + name + " has no attributes"); } Node name = shapeAttributes.getNamedItem("name"); String shapeName = null; if (name != null) { shapeName = name.getNodeValue(); } if (shapeName == null) { shapeName = "Shape #" + (i + 1); } String shapeType = null; Node type = shapeAttributes.getNamedItem("type"); if (type != null) { shapeType = type.getNodeValue(); } if (shapeType != null && !cubeIDs.contains(shapeType)) { System.out.println( "Model shape [" + shapeName + "] in " + this.name + " is not a cube, ignoring"); continue; } boolean mirrored = false; String[] offset = new String[3]; String[] position = new String[3]; String[] rotation = new String[3]; String[] size = new String[3]; String[] textureOffset = new String[2]; NodeList shapeChildren = shape.getChildNodes(); for (int j = 0; j < shapeChildren.getLength(); j++) { Node shapeChild = shapeChildren.item(j); String shapeChildName = shapeChild.getNodeName(); String shapeChildValue = shapeChild.getTextContent(); if (shapeChildValue != null) { shapeChildValue = shapeChildValue.trim(); switch (shapeChildName) { case "IsMirrored": mirrored = !shapeChildValue.equals("False"); break; case "Offset": offset = shapeChildValue.split(","); break; case "Position": position = shapeChildValue.split(","); break; case "Rotation": rotation = shapeChildValue.split(","); break; case "Size": size = shapeChildValue.split(","); break; case "TextureOffset": textureOffset = shapeChildValue.split(","); break; } } } /* Generate new models Models in Techne are based on cubes. Each cube is, by default, skewed to the side. They are not centered. Everything is scaled by a factor of 16. The y coordinate is inversed, y = 24 is the surface The z coordinate is inverted, too. */ double positionX = Double.parseDouble(position[0]) / 16d; double positionY = (16 - Double.parseDouble(position[1])) / 16d; double positionZ = -Double.parseDouble(position[2]) / 16d; double sizeX = Double.parseDouble(size[0]) / 16d; double sizeY = Double.parseDouble(size[1]) / 16d; double sizeZ = Double.parseDouble(size[2]) / 16d; double offsetX = Double.parseDouble(offset[0]) / 16d; double offsetY = -Double.parseDouble(offset[1]) / 16d; double offsetZ = -Double.parseDouble(offset[2]) / 16d; double angleX = -Math.toRadians(Double.parseDouble(rotation[0])); double angleY = Math.toRadians(Double.parseDouble(rotation[1])); double angleZ = Math.toRadians(Double.parseDouble(rotation[2])); double textureOffsetU = Double.parseDouble(textureOffset[0]); double textureOffsetV = Double.parseDouble(textureOffset[1]); CubeTextureCoordinates textureCoordinates = new TechneCubeTextureCoordinates(textureWidth, textureHeight, textureOffsetU, textureOffsetV, sizeX, sizeY, sizeZ); final String modelName = shapeName; MeshModel modelPart = new MeshModel(modelName); BlockRenderPipeline.drawCube(modelPart, offsetX, offsetY - sizeY, offsetZ - sizeZ, offsetX + sizeX, offsetY, offsetZ, textureCoordinates); MatrixStack ms = new MatrixStack(); ms.translate(positionX, positionY, positionZ); ms.rotate(Vector3D.PLUS_J, angleY); ms.rotate(Vector3D.PLUS_I, angleX); ms.rotate(Vector3D.PLUS_K, angleZ); modelPart.matrix = ms; modelPart.textureOffset = new Vector2D(Integer.parseInt(textureOffset[0]), Integer.parseInt(textureOffset[1])); if (model.children.stream().anyMatch(m -> m.name.equals(modelName))) { throw new RenderException( "Model contained duplicate part name: '" + shapeName + "' node #" + i); } model.children.add(modelPart); } } catch (ZipException e) { throw new RenderException("Model " + name + " is not a valid zip file"); } catch (IOException e) { throw new RenderException("Model " + name + " could not be read", e); } catch (SAXException e) { throw new RenderException("Model " + name + " contains invalid XML", e); } catch (Exception e) { e.printStackTrace(); } }
From source file:YoungDoubleSlit.YoungDoubleSlit.java
public JFreeChart getResultChart() { // XY ?./* w w w .j a v a 2 s .c om*/ XYSeries series = new XYSeries("Histogram of light amplitude"); Integer radius_size = ((UpperViewPane) upperView).getRadius().size(); Integer wavelength_value = ((UpperViewPane) upperView).getWavelengths().get(0); Double bin_width = 31.0 / bin_size; for (int i = 0; i < bin_size; i++) { double theta = Math.toRadians(-15.5 + bin_width * i); //double alpha = Math.PI* slit_width/wavelength_value*Math.sin(theta); //double beta = Math.PI* slit_distance/wavelength_value*Math.sin(theta); double alpha = Math.PI * slit_width * Math.sin(theta); double beta = Math.PI * slit_distance * Math.sin(theta); double amplitude = Math.cos(beta) * Math.cos(beta) * (Math.sin(alpha) / alpha) * (Math.sin(alpha) / alpha); // series? (x,y) ? series.add(theta, amplitude); } // XY Dataset XYSeriesCollection data = new XYSeriesCollection(series); final JFreeChart chart = ChartFactory.createXYLineChart("Amplitude of Light", "Angle", "Amp.", data, PlotOrientation.VERTICAL, true, true, false); chart.setTitle("Amplitude of light"); // ? return chart; }
From source file:org.envirocar.app.util.Util.java
/** * Returns the distance of two points in kilometers. * /*from ww w . jav a2 s. co m*/ * @param lat1 * @param lng1 * @param lat2 * @param lng2 * @return distance in km */ public static double getDistance(double lat1, double lng1, double lat2, double lng2) { double earthRadius = 6369; double dLat = Math.toRadians(lat2 - lat1); double dLng = Math.toRadians(lng2 - lng1); double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) * Math.sin(dLng / 2) * Math.sin(dLng / 2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); double dist = earthRadius * c; return dist; }
From source file:magma.agent.behavior.complex.GoalieBehavior.java
private boolean checkAngle(double angle) { return equals(goalie.getHorizontalAngle(), Angle.deg(zAngle), Math.toRadians(10)) || equals(goalie.getHorizontalAngle(), Angle.deg(-zAngle), Math.toRadians(10)); }
From source file:com.alvermont.terraj.planet.ProjectionParameters.java
/** * Getter for property longitudeRadians. * @return Value of property lon./* www . j a v a 2s.c o m*/ */ public double getLongitudeRadians() { double longitude = this.lon; if (longitude > 180.0) { longitude -= 360.0; } return Math.toRadians(longitude); }
From source file:Tester2.java
private boolean isNightTime(final SpacecraftState s) { // https://celestrak.com/columns/v03n01/ // when the sun's center is 6 degrees below the horizon, it is considered dark // enough to see earth satellites. try {//from w w w. j av a2s .c o m // origin is the center of the Earth Vector3D curSunPos = sun.getPVCoordinates(s.getDate(), this.earthFrame).getPosition(); // origin has been offset to the ground station Vector3D stationToSun = curSunPos.subtract(this.stationPos); Vector3D stationZenith = this.groundstationFrame.getZenith(); double sunAngle = Vector3D.angle(stationToSun, stationZenith); // Sun center to station to zenith // angle required for darkness measured from observer's zenith double darkAngle = Math.PI / 2 + Math.toRadians(4.5); //System.out.println("--------------------------------- " + sunAngle + " >= " + darkAngle); return sunAngle >= darkAngle; } catch (OrekitException e) { // TODO Auto-generated catch block e.printStackTrace(); System.out.println("This broke"); return false; } }
From source file:com.dlazaro66.wheelindicatorview.WheelIndicatorView.java
private void draw(WheelIndicatorItem indicatorItem, RectF surfaceRectF, float angle, Canvas canvas) { itemArcPaint.setColor(indicatorItem.getColor()); itemEndPointsPaint.setColor(indicatorItem.getColor()); // Draw arc/*from w ww . j a v a2s . co m*/ canvas.drawArc(surfaceRectF, ANGLE_INIT_OFFSET, angle, false, itemArcPaint); // Draw top circle canvas.drawCircle(minDistViewSize / 2, 0 + itemsLineWidth, itemsLineWidth, itemEndPointsPaint); int topPosition = minDistViewSize / 2 - itemsLineWidth; // Draw end circle canvas.drawCircle( (float) (Math.cos(Math.toRadians(angle + ANGLE_INIT_OFFSET)) * topPosition + topPosition + itemsLineWidth), (float) (Math.sin(Math.toRadians((angle + ANGLE_INIT_OFFSET))) * topPosition + topPosition + itemsLineWidth), itemsLineWidth, itemEndPointsPaint); }