List of usage examples for java.lang Math atan
public static double atan(double a)
From source file:com.opengamma.analytics.financial.model.volatility.smile.function.SABRPaulotVolatilityFunction.java
private double getG(final double a, final double b, final double c, final double xCap, final double rCap, final double beta, final double t) { final double beta1 = 1 - beta; double res = Math.atan(t); final double y = square(a + b * xCap) - square((beta1 * rCap)); if (y > 0) { final double temp = Math.sqrt(y); res -= (a + b * xCap) / temp * Math.atan((c * rCap + t * (a + b * (xCap - rCap))) / temp); } else if (y < 0) { final double temp = Math.sqrt(-y); res += (a + b * xCap) / temp * modAtanh((c * rCap + t * (a + b * (xCap - rCap))) / temp); } else {//from ww w.ja v a2s . co m res += (a + b * xCap) / (c * rCap + t * (a + b * (xCap - rCap))); } return res; }
From source file:com.joliciel.jochre.boundaries.features.TwoPointSlopeDifferenceFeature.java
@Override public FeatureResult<Double> checkInternal(Split split, RuntimeEnvironment env) { FeatureResult<Double> result = null; FeatureResult<Integer> contourDistanceResult = contourDistanceFeature.check(split, env); if (contourDistanceResult != null) { int contourDistance = contourDistanceResult.getOutcome(); int[][] verticalContour = split.getShape().getVerticalContour(); int x = split.getPosition(); Shape shape = split.getShape(); int topStart = verticalContour[x][0]; int bottomStart = verticalContour[x][1]; SimpleRegression topRightRegression = new SimpleRegression(); SimpleRegression bottomRightRegression = new SimpleRegression(); SimpleRegression topLeftRegression = new SimpleRegression(); SimpleRegression bottomLeftRegression = new SimpleRegression(); topRightRegression.addData(x, topStart); topLeftRegression.addData(x, topStart); bottomRightRegression.addData(x, bottomStart); bottomLeftRegression.addData(x, bottomStart); int[] minTopRight = new int[] { x, topStart }; int[] minTopLeft = new int[] { x, topStart }; int[] maxTopRight = new int[] { x, topStart }; int[] maxTopLeft = new int[] { x, topStart }; int[] minBottomRight = new int[] { x, bottomStart }; int[] minBottomLeft = new int[] { x, bottomStart }; int[] maxBottomRight = new int[] { x, bottomStart }; int[] maxBottomLeft = new int[] { x, bottomStart }; for (int i = 1; i <= contourDistance; i++) { if (x + i < shape.getWidth()) { if (verticalContour[x + i][0] < minTopRight[1]) minTopRight = new int[] { x + i, verticalContour[x + i][0] }; if (verticalContour[x + i][0] > maxTopRight[1]) maxTopRight = new int[] { x + i, verticalContour[x + i][0] }; if (verticalContour[x + i][1] < minBottomRight[1]) minBottomRight = new int[] { x + i, verticalContour[x + i][1] }; if (verticalContour[x + i][1] > maxBottomRight[1]) maxBottomRight = new int[] { x + i, verticalContour[x + i][1] }; }// ww w.jav a2 s . c o m if (x - i >= 0) { if (verticalContour[x - i][0] < minTopLeft[1]) minTopLeft = new int[] { x - i, verticalContour[x - i][0] }; if (verticalContour[x - i][0] > maxTopLeft[1]) maxTopLeft = new int[] { x - i, verticalContour[x - i][0] }; if (verticalContour[x - i][1] < minBottomLeft[1]) minBottomLeft = new int[] { x - i, verticalContour[x - i][1] }; if (verticalContour[x - i][1] > maxBottomLeft[1]) maxBottomLeft = new int[] { x - i, verticalContour[x - i][1] }; } } if (minTopRight[0] == x) topRightRegression.addData(maxTopRight[0], maxTopRight[1]); else topRightRegression.addData(minTopRight[0], minTopRight[1]); if (minTopLeft[0] == x) topLeftRegression.addData(maxTopLeft[0], maxTopLeft[1]); else topLeftRegression.addData(minTopLeft[0], minTopLeft[1]); if (maxBottomRight[0] == x) bottomRightRegression.addData(minBottomRight[0], minBottomRight[1]); else bottomRightRegression.addData(maxBottomRight[0], maxBottomRight[1]); if (maxBottomLeft[0] == x) bottomLeftRegression.addData(minBottomLeft[0], minBottomLeft[1]); else bottomLeftRegression.addData(maxBottomLeft[0], maxBottomLeft[1]); // get the slopes double topRightSlope = topRightRegression.getSlope(); double bottomRightSlope = bottomRightRegression.getSlope(); double topLeftSlope = topLeftRegression.getSlope(); double bottomLeftSlope = bottomLeftRegression.getSlope(); // convert slopes to angles double topRightAngle = Math.atan(topRightSlope); double bottomRightAngle = Math.atan(bottomRightSlope); double topLeftAngle = Math.atan(topLeftSlope); double bottomLeftAngle = Math.atan(bottomLeftSlope); // calculate the right & left-hand differences double rightDiff = Math.abs(topRightAngle - bottomRightAngle); double leftDiff = Math.abs(topLeftAngle - bottomLeftAngle); // normalise the differences from 0 to 1 rightDiff = rightDiff / Math.PI; leftDiff = leftDiff / Math.PI; double product = rightDiff * leftDiff; if (LOG.isTraceEnabled()) { LOG.trace("topRightAngle: " + topRightAngle); LOG.trace("bottomRightAngle: " + bottomRightAngle); LOG.trace("topLeftAngle: " + topLeftAngle); LOG.trace("bottomLeftAngle: " + bottomLeftAngle); LOG.trace("rightDiff: " + rightDiff); LOG.trace("leftDiff: " + leftDiff); LOG.trace("product: " + product); } result = this.generateResult(product); } return result; }
From source file:org.kuali.kra.printing.service.impl.WatermarkServiceImpl.java
/** * This method is for setting the properties of watermark Text. * /*from w w w . j a v a 2 s . com*/ * @param pdfContentByte * @param pageWidth * @param pageHeight * @param watermarkBean */ private void decoratePdfWatermarkText(PdfContentByte pdfContentByte, int pageWidth, int pageHeight, WatermarkBean watermarkBean) { float x, y, x1, y1, angle; try { if (watermarkBean.getType().equalsIgnoreCase(WatermarkConstants.WATERMARK_TYPE_TEXT)) { pdfContentByte.beginText(); pdfContentByte.setFontAndSize(watermarkBean.getFont().getBaseFont(), watermarkBean.getFont().getSize()); Color fillColor = watermarkBean.getFont().getColor() == null ? WatermarkConstants.DEFAULT_WATERMARK_COLOR : watermarkBean.getFont().getColor(); pdfContentByte.setColorFill(fillColor); int textWidth = (int) pdfContentByte.getEffectiveStringWidth(watermarkBean.getText(), false); int diagonal = (int) Math.sqrt((pageWidth * pageWidth) + (pageHeight * pageHeight)); int pivotPoint = (diagonal - textWidth) / 2; angle = (float) Math.atan((float) pageHeight / pageWidth); x = (float) (pivotPoint * pageWidth) / diagonal; y = (float) (pivotPoint * pageHeight) / diagonal; x1 = (float) (((float) watermarkBean.getFont().getSize() / 2) * Math.sin(angle)); y1 = (float) (((float) watermarkBean.getFont().getSize() / 2) * Math.cos(angle)); pdfContentByte.showTextAligned(Element.ALIGN_LEFT, watermarkBean.getText(), x + x1, y - y1, (float) Math.toDegrees(angle)); pdfContentByte.endText(); } } catch (Exception exception) { LOG.error("Exception occured in WatermarkServiceImpl. Water mark Exception: " + exception.getMessage()); } }
From source file:org.cirdles.ambapo.LatLongToUTM.java
/** * Eccentricity helps define the shape of the ellipsoidal representation of * the earth/*w w w . jav a 2 s . c o m*/ * * Conformal latitude gives an angle-preserving (conformal) transformation * to the sphere * * It defines a transformation from the ellipsoid to a sphere * of arbitrary radius such that the angle of intersection between any two * lines on the ellipsoid is the same as the corresponding angle on the sphere. * * @param eccentricity * @param latitudeRadians * @return BigDecimal conformal latitude * */ private static BigDecimal calcConformalLatitude(BigDecimal eccentricity, BigDecimal latitudeRadians) { BigDecimal conformalLatitude; double latRadDouble = latitudeRadians.doubleValue(); double eccDouble = eccentricity.doubleValue(); double confLatDouble; Atanh atanh = new Atanh(); Asinh asinh = new Asinh(); confLatDouble = Math.atan(Math.sinh( asinh.value(Math.tan(latRadDouble)) - eccDouble * atanh.value(eccDouble * Math.sin(latRadDouble)))); conformalLatitude = new BigDecimal(confLatDouble); return conformalLatitude; }
From source file:StatFunctions.java
public static double pt(double t, double df) { // ALGORITHM AS 3 APPL. STATIST. (1968) VOL.17, P.189 // Computes P(T<t) double a, b, idf, im2, ioe, s, c, ks, fk, k; double g1 = 0.3183098862;// =1/pi; if (df < 1) throw new IllegalArgumentException("Illegal argument df for pt(t,df)."); idf = df;/* ww w . j ava 2s. c om*/ a = t / Math.sqrt(idf); b = idf / (idf + t * t); im2 = df - 2; ioe = idf % 2; s = 1; c = 1; idf = 1; ks = 2 + ioe; fk = ks; if (im2 >= 2) { for (k = ks; k <= im2; k += 2) { c = c * b * (fk - 1) / fk; s += c; if (s != idf) { idf = s; fk += 2; } } } if (ioe != 1) return 0.5 + 0.5 * a * Math.sqrt(b) * s; if (df == 1) s = 0; return 0.5 + (a * b * s + Math.atan(a)) * g1; }
From source file:org.cirdles.ambapo.LatLongToUTM.java
/** * tau refers to the torsion of a curve// w w w. ja v a 2 s .c om * xi refers to the north-south direction * * @param changeInLongitudeRadians * @param tauPrime * @return BigDecimal xi prime * * */ private static BigDecimal calcXiPrimeNorth(BigDecimal changeInLongitudeRadians, BigDecimal tauPrime) { double cosOfLatRad = Math.cos(changeInLongitudeRadians.doubleValue()); BigDecimal xiPrime = new BigDecimal(Math.atan(tauPrime.doubleValue() / cosOfLatRad)); return xiPrime; }
From source file:com.joliciel.jochre.boundaries.features.TrueContourSlopeDifferenceFeature.java
@Override public FeatureResult<Double> checkInternal(Split split, RuntimeEnvironment env) { FeatureResult<Double> result = null; FeatureResult<Integer> contourDistanceResult = contourDistanceFeature.check(split, env); if (contourDistanceResult != null) { int contourDistance = contourDistanceResult.getOutcome(); int[][] verticalContour = split.getShape().getVerticalContour(); int startX = split.getPosition(); Shape shape = split.getShape(); int topStart = verticalContour[startX][0]; int bottomStart = verticalContour[startX][1]; SimpleRegression topRightRegression = new SimpleRegression(); SimpleRegression bottomRightRegression = new SimpleRegression(); SimpleRegression topLeftRegression = new SimpleRegression(); SimpleRegression bottomLeftRegression = new SimpleRegression(); topRightRegression.addData(startX, topStart); topLeftRegression.addData(startX, topStart); bottomRightRegression.addData(startX, bottomStart); bottomLeftRegression.addData(startX, bottomStart); int lastTopRight = topStart; int lastTopLeft = topStart; int lastBottomRight = bottomStart; int lastBottomLeft = bottomStart; for (int i = 1; i <= contourDistance; i++) { int x = startX + i; if (x < shape.getWidth()) { if (shape.isPixelBlack(x, lastTopRight)) { for (int y = lastTopRight - 1; y >= -1; y--) { if (y < 0 || !shape.isPixelBlack(x, y)) { lastTopRight = y + 1; topRightRegression.addData(x, lastTopRight); break; }// ww w. j a va2 s .co m } } else { for (int y = lastTopRight + 1; y <= shape.getHeight(); y++) { if (y == shape.getHeight() || shape.isPixelBlack(x, y)) { lastTopRight = y; topRightRegression.addData(x, lastTopRight); break; } } } if (shape.isPixelBlack(x, lastBottomRight)) { for (int y = lastBottomRight + 1; y <= shape.getHeight(); y++) { if (y == shape.getHeight() || !shape.isPixelBlack(x, y)) { lastBottomRight = y - 1; bottomRightRegression.addData(x, lastBottomRight); break; } } } else { for (int y = lastBottomRight - 1; y >= -1; y--) { if (y < 0 || shape.isPixelBlack(x, y)) { lastBottomRight = y; bottomRightRegression.addData(x, lastBottomRight); break; } } } } x = startX - i; if (x >= 0) { if (shape.isPixelBlack(x, lastTopLeft)) { for (int y = lastTopLeft - 1; y >= -1; y--) { if (y < 0 || !shape.isPixelBlack(x, y)) { lastTopLeft = y + 1; topLeftRegression.addData(x, lastTopLeft); break; } } } else { for (int y = lastTopLeft + 1; y <= shape.getHeight(); y++) { if (y == shape.getHeight() || shape.isPixelBlack(x, y)) { lastTopLeft = y; topLeftRegression.addData(x, lastTopLeft); break; } } } if (shape.isPixelBlack(x, lastBottomLeft)) { for (int y = lastBottomLeft + 1; y <= shape.getHeight(); y++) { if (y == shape.getHeight() || !shape.isPixelBlack(x, y)) { lastBottomLeft = y - 1; bottomLeftRegression.addData(x, lastBottomLeft); break; } } } else { for (int y = lastBottomLeft - 1; y >= -1; y--) { if (y < 0 || shape.isPixelBlack(x, y)) { lastBottomLeft = y; bottomLeftRegression.addData(x, lastBottomLeft); break; } } } } } // get the slopes double topRightSlope = topRightRegression.getSlope(); double bottomRightSlope = bottomRightRegression.getSlope(); double topLeftSlope = topLeftRegression.getSlope(); double bottomLeftSlope = bottomLeftRegression.getSlope(); // convert slopes to angles double topRightAngle = Math.atan(topRightSlope); double bottomRightAngle = Math.atan(bottomRightSlope); double topLeftAngle = Math.atan(topLeftSlope); double bottomLeftAngle = Math.atan(bottomLeftSlope); // calculate the right & left-hand differences double rightDiff = Math.abs(topRightAngle - bottomRightAngle); double leftDiff = Math.abs(topLeftAngle - bottomLeftAngle); // normalise the differences from 0 to 1 rightDiff = rightDiff / Math.PI; leftDiff = leftDiff / Math.PI; double product = rightDiff * leftDiff; if (LOG.isTraceEnabled()) { LOG.trace("topRightAngle: " + topRightAngle); LOG.trace("bottomRightAngle: " + bottomRightAngle); LOG.trace("topLeftAngle: " + topLeftAngle); LOG.trace("bottomLeftAngle: " + bottomLeftAngle); LOG.trace("rightDiff: " + rightDiff); LOG.trace("leftDiff: " + leftDiff); LOG.trace("product: " + product); } result = this.generateResult(product); } return result; }
From source file:com.facebook.presto.operator.scalar.MathFunctions.java
@Description("arc tangent") @ScalarFunction//from w w w .j av a2 s. c om @SqlType(StandardTypes.DOUBLE) public static double atan(@SqlType(StandardTypes.DOUBLE) double num) { return Math.atan(num); }
From source file:com.chenupt.springindicator.SpringIndicator.java
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { if (position < tabs.size() - 1) { // radius float radiusOffsetHead = 0.5f; if (positionOffset < radiusOffsetHead) { springView.getHeadPoint().setRadius(radiusMin); } else {/*from w ww .j a va 2 s . com*/ springView.getHeadPoint().setRadius( ((positionOffset - radiusOffsetHead) / (1 - radiusOffsetHead) * radiusOffset + radiusMin)); } float radiusOffsetFoot = 0.5f; if (positionOffset < radiusOffsetFoot) { springView.getFootPoint() .setRadius((1 - positionOffset / radiusOffsetFoot) * radiusOffset + radiusMin); } else { springView.getFootPoint().setRadius(radiusMin); } // x float headX = 1f; if (positionOffset < headMoveOffset) { float positionOffsetTemp = positionOffset / headMoveOffset; headX = (float) ((Math.atan(positionOffsetTemp * acceleration * 2 - acceleration) + (Math.atan(acceleration))) / (2 * (Math.atan(acceleration)))); } springView.getHeadPoint().setX(getTabX(position) - headX * getPositionDistance(position)); float footX = 0f; if (positionOffset > footMoveOffset) { float positionOffsetTemp = (positionOffset - footMoveOffset) / (1 - footMoveOffset); footX = (float) ((Math.atan(positionOffsetTemp * acceleration * 2 - acceleration) + (Math.atan(acceleration))) / (2 * (Math.atan(acceleration)))); } springView.getFootPoint().setX(getTabX(position) - footX * getPositionDistance(position)); // reset radius if (positionOffset == 0) { springView.getHeadPoint().setRadius(radiusMax); springView.getFootPoint().setRadius(radiusMax); } } else { springView.getHeadPoint().setX(getTabX(position)); springView.getFootPoint().setX(getTabX(position)); springView.getHeadPoint().setRadius(radiusMax); springView.getFootPoint().setRadius(radiusMax); } // set indicator colors // https://github.com/TaurusXi/GuideBackgroundColorAnimation if (indicatorColorsId != 0) { float length = (position + positionOffset) / viewPager.getAdapter().getCount(); int progress = (int) (length * INDICATOR_ANIM_DURATION); seek(progress); } springView.postInvalidate(); if (delegateListener != null) { delegateListener.onPageScrolled(position, positionOffset, positionOffsetPixels); } }
From source file:com.birdgang.viewpagerheader.indicator.SpringIndicator.java
private void setUpListener() { viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override/*from www . ja v a 2 s. c o m*/ public void onPageSelected(int position) { super.onPageSelected(position); if (delegateListener != null) { delegateListener.onPageSelected(position); } } @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { if (position < tabs.size() - 1) { float radiusOffsetHead = 0.5f; if (positionOffset < radiusOffsetHead) { springView.getHeadPoint().setRadius(radiusMin); } else { springView.getHeadPoint().setRadius( ((positionOffset - radiusOffsetHead) / (1 - radiusOffsetHead) * radiusOffset + radiusMin)); } float radiusOffsetFoot = 0.5f; if (positionOffset < radiusOffsetFoot) { springView.getFootPoint() .setRadius((1 - positionOffset / radiusOffsetFoot) * radiusOffset + radiusMin); } else { springView.getFootPoint().setRadius(radiusMin); } float headX = 1f; if (positionOffset < headMoveOffset) { float positionOffsetTemp = positionOffset / headMoveOffset; headX = (float) ((Math.atan(positionOffsetTemp * acceleration * 2 - acceleration) + (Math.atan(acceleration))) / (2 * (Math.atan(acceleration)))); } springView.getHeadPoint().setX(getTabX(position) - headX * getPositionDistance(position)); float footX = 0f; if (positionOffset > footMoveOffset) { float positionOffsetTemp = (positionOffset - footMoveOffset) / (1 - footMoveOffset); footX = (float) ((Math.atan(positionOffsetTemp * acceleration * 2 - acceleration) + (Math.atan(acceleration))) / (2 * (Math.atan(acceleration)))); } springView.getFootPoint().setX(getTabX(position) - footX * getPositionDistance(position)); if (positionOffset == 0) { springView.getHeadPoint().setRadius(radiusMax); springView.getFootPoint().setRadius(radiusMax); } } else { springView.getHeadPoint().setX(getTabX(position)); springView.getFootPoint().setX(getTabX(position)); springView.getHeadPoint().setRadius(radiusMax); springView.getFootPoint().setRadius(radiusMax); } if (indicatorColorsId != 0) { float length = (position + positionOffset) / viewPager.getAdapter().getCount(); int progress = (int) (length * INDICATOR_ANIM_DURATION); seek(progress); } springView.postInvalidate(); if (delegateListener != null) { delegateListener.onPageScrolled(position, positionOffset, positionOffsetPixels); } } @Override public void onPageScrollStateChanged(int state) { super.onPageScrollStateChanged(state); if (delegateListener != null) { delegateListener.onPageScrollStateChanged(state); } } }); }