List of usage examples for java.lang Math toDegrees
public static double toDegrees(double angrad)
From source file:ucar.unidata.idv.flythrough.Flythrough.java
/** * _more_// w w w . j a v a 2s . com * * @param pt1 _more_ * @param xyz1 _more_ * @param xyz2 _more_ * @param actualPoint _more_ * @param animateMove _more_ */ protected void goTo(FlythroughPoint pt1, double[] xyz1, double[] xyz2, double[] actualPoint, boolean animateMove) { currentHeading = 180; if (actualPoint == null) { actualPoint = xyz2; } NavigatedDisplay navDisplay = viewManager.getNavigatedDisplay(); MouseBehavior mouseBehavior = navDisplay.getMouseBehavior(); double[] currentMatrix = navDisplay.getProjectionMatrix(); double[] aspect = navDisplay.getDisplayAspect(); try { if (pt1.getDescription() != null) { getHtmlView().setText(pt1.getDescription()); } else { getHtmlView().setText(""); } processReadout(pt1); float x1 = (float) xyz1[0]; float y1 = (float) xyz1[1]; float z1 = (float) xyz1[2]; float x2 = (float) xyz2[0]; float y2 = (float) xyz2[1]; float z2 = (float) xyz2[2]; double zoom = (pt1.hasZoom() ? pt1.getZoom() : getZoom()); if (zoom == 0) { zoom = 0.1; } double tiltx = (pt1.hasTiltX() ? pt1.getTiltX() : tilt[0]); double tilty = (pt1.hasTiltY() ? pt1.getTiltY() : tilt[1]); double tiltz = (pt1.hasTiltZ() ? pt1.getTiltZ() : tilt[2]); //Check for nans if ((x2 != x2) || (y2 != y2) || (z2 != z2)) { return; } if ((x1 != x1) || (y1 != y1) || (z1 != z1)) { return; } double[] m = pt1.getMatrix(); if (m == null) { m = new double[16]; Transform3D t = new Transform3D(); if (orientation.equals(ORIENT_UP)) { y2 = y1 + 100; x2 = x1; } else if (orientation.equals(ORIENT_DOWN)) { y2 = y1 - 100; x2 = x1; } else if (orientation.equals(ORIENT_LEFT)) { x2 = x1 - 100; y2 = y1; } else if (orientation.equals(ORIENT_RIGHT)) { x2 = x1 + 100; y2 = y1; } if ((x1 == x2) && (y1 == y2) && (z1 == z2)) { return; } Vector3d upVector; if (doGlobe()) { upVector = new Vector3d(x1, y1, z1); } else { upVector = new Vector3d(0, 0, 1); } //Keep flat in z for non globe Point3d p1 = new Point3d(x1, y1, z1); Point3d p2 = new Point3d(x2, y2, ((!getUseFixedZ() || doGlobe()) ? z2 : z1)); t.lookAt(p1, p2, upVector); t.get(m); EarthLocation el1 = navDisplay.getEarthLocation(p1.x, p1.y, p1.z, false); EarthLocation el2 = navDisplay.getEarthLocation(p2.x, p2.y, p2.z, false); Bearing bearing = Bearing.calculateBearing(new LatLonPointImpl(getLat(el1), getLon(el1)), new LatLonPointImpl(getLat(el2), getLon(el2)), null); currentHeading = bearing.getAngle(); double[] tiltMatrix = mouseBehavior.make_matrix(tiltx, tilty, tiltz, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0); m = mouseBehavior.multiply_matrix(tiltMatrix, m); if (aspect != null) { double[] aspectMatrix = mouseBehavior.make_matrix(0.0, 0.0, 0.0, aspect[0], aspect[1], aspect[2], 0.0, 0.0, 0.0); // m = mouseBehavior.multiply_matrix(aspectMatrix, m); } double[] scaleMatrix = mouseBehavior.make_matrix(0.0, 0.0, 0.0, zoom, 0.0, 0.0, 0.0); m = mouseBehavior.multiply_matrix(scaleMatrix, m); } currentPoint = pt1; location = currentPoint.getEarthLocation(); if (doGlobe()) { setPts(locationLine, 0, x1 * 2, 0, y1 * 2, 0, z1 * 2); // setPts(locationLine2, 0, x2 * 2, 0, y2 * 2, 0, z2 * 2); } else { setPts(locationLine, x1, x1, y1, y1, 1, -1); } RealTuple markerLocation = new RealTuple(RealTupleType.SpatialCartesian3DTuple, new double[] { x1, y1, z1 }); if (xyz1[0] != xyz2[0]) { Transform3D rotTransform; VisADGeometryArray marker = (VisADGeometryArray) getMarker().clone(); double rotx = 0; double roty = 0; double rotz = 0; rotz = -Math.toDegrees(Math.atan2(actualPoint[1] - xyz1[1], actualPoint[0] - xyz1[0])) + 90; if (doGlobe()) { Vector3d upVector = new Vector3d(x1, y1, z1); rotTransform = new Transform3D(); rotTransform.lookAt(new Point3d(x1, y1, z1), new Point3d(x2, y2, z2), upVector); Matrix3d m3d = new Matrix3d(); rotTransform.get(m3d); rotTransform = new Transform3D(m3d, new Vector3d(0, 0, 0), 1); rotTransform.invert(); // ShapeUtility.rotate(marker, rotTransform,(float)x1,(float)y1,(float)z1); ShapeUtility.rotate(marker, rotTransform); } else { double[] markerM = navDisplay.getMouseBehavior().make_matrix(rotx, roty, rotz, 1.0, 0.0, 0.0, 0.0); rotTransform = new Transform3D(markerM); ShapeUtility.rotate(marker, rotTransform); } locationMarker.setPoint(markerLocation, marker); } else { locationMarker.setPoint(markerLocation); } locationLine.setVisible(showLine); // locationLine2.setVisible(showLine); locationMarker.setVisible(showMarker); if (hasTimes && getShowTimes()) { DateTime dttm = pt1.getDateTime(); if (dttm != null) { viewManager.getAnimationWidget().setTimeFromUser(dttm); } } if (changeViewpointCbx.isSelected()) { if (animateMove) { navDisplay.animateMatrix(m, animationSpeed); } else { navDisplay.setProjectionMatrix(m); } } if (!Misc.equals(lastLocation, pt1.getEarthLocation())) { lastLocation = pt1.getEarthLocation(); EarthLocationTuple tuplePosition = new EarthLocationTuple(lastLocation.getLatitude(), lastLocation.getLongitude(), lastLocation.getAltitude()); doShare(ucar.unidata.idv.control.ProbeControl.SHARE_POSITION, tuplePosition); } } catch (NumberFormatException exc) { logException("Error parsing number:" + exc, exc); } catch (javax.media.j3d.BadTransformException bte) { try { navDisplay.setProjectionMatrix(currentMatrix); } catch (Exception ignore) { } } catch (Exception exc) { logException("Error", exc); if (animationWidget != null) { animationWidget.setRunning(false); } return; } }
From source file:com.example.sensingapp.SensingApp.java
private boolean calculateOrientation() { float[] arrfValues = new float[3]; float[] arrfR = new float[9]; float[] arrfI = new float[9]; if ((m_arrfAcclValues == null) || (m_arrfMagnetValues == null)) { return false; }/* w w w . jav a 2s .c o m*/ //if (SensorManager.getRotationMatrix(arrfR, null, m_arrfAcclValues, m_arrfMagnetValues)) { //Ignore inclintion matrix calculation will make the execution faster if (SensorManager.getRotationMatrix(arrfR, arrfI, m_arrfAcclValues, m_arrfMagnetValues)) { SensorManager.getOrientation(arrfR, arrfValues); m_arrfOrientValues[0] = (float) Math.toDegrees(arrfValues[0]); m_arrfOrientValues[1] = (float) Math.toDegrees(arrfValues[1]); m_arrfOrientValues[2] = (float) Math.toDegrees(arrfValues[2]); if (m_arrfOrientValues[0] < 0) { m_arrfOrientValues[0] = m_arrfOrientValues[0] + 360; // Make Azimuth 0 ~ 360 } return true; } else { return false; } }
From source file:org.eclipse.january.dataset.Maths.java
/** * Create a dataset of the arguments from a complex dataset * @param a/*from w w w . j a va 2 s .co m*/ * @param inDegrees if true then return angles in degrees else in radians * @param o output can be null - in which case, a new dataset is created * @return dataset of angles */ public static Dataset angle(final Object a, final boolean inDegrees, final Dataset o) { final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a); if (!da.isComplex()) { throw new UnsupportedOperationException("angle does not support this dataset type"); } final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true, false, false); final Dataset result = it.getOutput(); final int is = result.getElementsPerItem(); final int dt = result.getDType(); switch (dt) { case Dataset.INT8: final byte[] oi8data = ((ByteDataset) result).data; it.setOutputDouble(false); if (inDegrees) { while (it.hasNext()) { oi8data[it.oIndex] = (byte) toLong( Math.toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble))); } } else { while (it.hasNext()) { oi8data[it.oIndex] = (byte) toLong( Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble)); } } break; case Dataset.INT16: final short[] oi16data = ((ShortDataset) result).data; it.setOutputDouble(false); if (inDegrees) { while (it.hasNext()) { oi16data[it.oIndex] = (short) toLong( Math.toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble))); } } else { while (it.hasNext()) { oi16data[it.oIndex] = (short) toLong( Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble)); } } break; case Dataset.INT32: final int[] oi32data = ((IntegerDataset) result).data; it.setOutputDouble(false); if (inDegrees) { while (it.hasNext()) { oi32data[it.oIndex] = (int) toLong( Math.toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble))); } } else { while (it.hasNext()) { oi32data[it.oIndex] = (int) toLong( Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble)); } } break; case Dataset.INT64: final long[] oi64data = ((LongDataset) result).data; it.setOutputDouble(false); if (inDegrees) { while (it.hasNext()) { oi64data[it.oIndex] = toLong( Math.toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble))); } } else { while (it.hasNext()) { oi64data[it.oIndex] = toLong(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble)); } } break; case Dataset.ARRAYINT8: final byte[] oai8data = ((CompoundByteDataset) result).data; it.setOutputDouble(false); if (inDegrees) { while (it.hasNext()) { final byte ox = (byte) toLong( Math.toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble))); for (int j = 0; j < is; j++) { oai8data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final byte ox = (byte) toLong(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble)); for (int j = 0; j < is; j++) { oai8data[it.oIndex + j] = ox; } } } break; case Dataset.ARRAYINT16: final short[] oai16data = ((CompoundShortDataset) result).data; it.setOutputDouble(false); if (inDegrees) { while (it.hasNext()) { final short ox = (short) toLong( Math.toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble))); for (int j = 0; j < is; j++) { oai16data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final short ox = (short) toLong(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble)); for (int j = 0; j < is; j++) { oai16data[it.oIndex + j] = ox; } } } break; case Dataset.ARRAYINT32: final int[] oai32data = ((CompoundIntegerDataset) result).data; it.setOutputDouble(false); if (inDegrees) { while (it.hasNext()) { final int ox = (int) toLong( Math.toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble))); for (int j = 0; j < is; j++) { oai32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final int ox = (int) toLong(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble)); for (int j = 0; j < is; j++) { oai32data[it.oIndex + j] = ox; } } } break; case Dataset.ARRAYINT64: final long[] oai64data = ((CompoundLongDataset) result).data; it.setOutputDouble(false); if (inDegrees) { while (it.hasNext()) { final long ox = toLong( Math.toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble))); for (int j = 0; j < is; j++) { oai64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ox = toLong(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble)); for (int j = 0; j < is; j++) { oai64data[it.oIndex + j] = ox; } } } break; case Dataset.FLOAT32: final float[] of32data = ((FloatDataset) result).data; if (inDegrees) { while (it.hasNext()) { of32data[it.oIndex] = (float) Math .toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble)); } } else { while (it.hasNext()) { of32data[it.oIndex] = (float) Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble); } } break; case Dataset.FLOAT64: final double[] of64data = ((DoubleDataset) result).data; if (inDegrees) { while (it.hasNext()) { of64data[it.oIndex] = Math .toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble)); } } else { while (it.hasNext()) { of64data[it.oIndex] = Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble); } } break; case Dataset.ARRAYFLOAT32: final float[] oaf32data = ((CompoundFloatDataset) result).data; if (inDegrees) { while (it.hasNext()) { final float ox = (float) Math .toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble)); for (int j = 0; j < is; j++) { oaf32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final float ox = (float) Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble); for (int j = 0; j < is; j++) { oaf32data[it.oIndex + j] = ox; } } } break; case Dataset.ARRAYFLOAT64: final double[] oaf64data = ((CompoundDoubleDataset) result).data; if (inDegrees) { while (it.hasNext()) { final double ox = Math.toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble)); for (int j = 0; j < is; j++) { oaf64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final double ox = Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble); for (int j = 0; j < is; j++) { oaf64data[it.oIndex + j] = ox; } } } break; case Dataset.COMPLEX64: final float[] oc64data = ((ComplexFloatDataset) result).data; if (inDegrees) { while (it.hasNext()) { oc64data[it.oIndex] = (float) Math .toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble)); oc64data[it.oIndex + 1] = 0; } } else { while (it.hasNext()) { oc64data[it.oIndex] = (float) Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble); oc64data[it.oIndex + 1] = 0; } } break; case Dataset.COMPLEX128: final double[] oc128data = ((ComplexDoubleDataset) result).data; if (inDegrees) { while (it.hasNext()) { oc128data[it.oIndex] = Math .toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble)); oc128data[it.oIndex + 1] = 0; } } else { while (it.hasNext()) { oc128data[it.oIndex] = Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble); oc128data[it.oIndex + 1] = 0; } } break; default: throw new IllegalArgumentException("angle does not support this dataset type"); } addFunctionName(result, "angle"); return result; }
From source file:org.eclipse.dataset.Maths.java
/** * Create a dataset of the arguments from a complex dataset * @param a// ww w . j av a 2s . c o m * @param inDegrees if true then return angles in degrees else in radians * @param o output can be null - in which case, a new dataset is created * @return dataset of angles */ public static Dataset angle(final Object a, final boolean inDegrees, final Dataset o) { final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a); if (!da.isComplex()) { throw new UnsupportedOperationException("angle does not support this dataset type"); } final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true, false, false); final Dataset result = it.getOutput(); final int is = result.getElementsPerItem(); final int dt = result.getDtype(); switch (dt) { case Dataset.INT8: final byte[] oi8data = ((ByteDataset) result).data; it.setOutputDouble(false); if (inDegrees) { while (it.hasNext()) { oi8data[it.oIndex] = (byte) toLong( Math.toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble))); } } else { while (it.hasNext()) { oi8data[it.oIndex] = (byte) toLong( Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble)); } } break; case Dataset.INT16: final short[] oi16data = ((ShortDataset) result).data; it.setOutputDouble(false); if (inDegrees) { while (it.hasNext()) { oi16data[it.oIndex] = (short) toLong( Math.toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble))); } } else { while (it.hasNext()) { oi16data[it.oIndex] = (short) toLong( Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble)); } } break; case Dataset.INT32: final int[] oi32data = ((IntegerDataset) result).data; it.setOutputDouble(false); if (inDegrees) { while (it.hasNext()) { oi32data[it.oIndex] = (int) toLong( Math.toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble))); } } else { while (it.hasNext()) { oi32data[it.oIndex] = (int) toLong( Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble)); } } break; case Dataset.INT64: final long[] oi64data = ((LongDataset) result).data; it.setOutputDouble(false); if (inDegrees) { while (it.hasNext()) { oi64data[it.oIndex] = toLong( Math.toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble))); } } else { while (it.hasNext()) { oi64data[it.oIndex] = toLong(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble)); } } break; case Dataset.ARRAYINT8: final byte[] oai8data = ((CompoundByteDataset) result).data; it.setOutputDouble(false); if (inDegrees) { while (it.hasNext()) { final byte ox = (byte) toLong( Math.toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble))); for (int j = 0; j < is; j++) { oai8data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final byte ox = (byte) toLong(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble)); for (int j = 0; j < is; j++) { oai8data[it.oIndex + j] = ox; } } } break; case Dataset.ARRAYINT16: final short[] oai16data = ((CompoundShortDataset) result).data; it.setOutputDouble(false); if (inDegrees) { while (it.hasNext()) { final short ox = (short) toLong( Math.toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble))); for (int j = 0; j < is; j++) { oai16data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final short ox = (short) toLong(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble)); for (int j = 0; j < is; j++) { oai16data[it.oIndex + j] = ox; } } } break; case Dataset.ARRAYINT32: final int[] oai32data = ((CompoundIntegerDataset) result).data; it.setOutputDouble(false); if (inDegrees) { while (it.hasNext()) { final int ox = (int) toLong( Math.toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble))); for (int j = 0; j < is; j++) { oai32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final int ox = (int) toLong(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble)); for (int j = 0; j < is; j++) { oai32data[it.oIndex + j] = ox; } } } break; case Dataset.ARRAYINT64: final long[] oai64data = ((CompoundLongDataset) result).data; it.setOutputDouble(false); if (inDegrees) { while (it.hasNext()) { final long ox = toLong( Math.toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble))); for (int j = 0; j < is; j++) { oai64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ox = toLong(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble)); for (int j = 0; j < is; j++) { oai64data[it.oIndex + j] = ox; } } } break; case Dataset.FLOAT32: final float[] of32data = ((FloatDataset) result).data; if (inDegrees) { while (it.hasNext()) { of32data[it.oIndex] = (float) Math .toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble)); } } else { while (it.hasNext()) { of32data[it.oIndex] = (float) Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble); } } break; case Dataset.FLOAT64: final double[] of64data = ((DoubleDataset) result).data; if (inDegrees) { while (it.hasNext()) { of64data[it.oIndex] = Math .toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble)); } } else { while (it.hasNext()) { of64data[it.oIndex] = Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble); } } break; case Dataset.ARRAYFLOAT32: final float[] oaf32data = ((CompoundFloatDataset) result).data; if (inDegrees) { while (it.hasNext()) { final float ox = (float) Math .toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble)); for (int j = 0; j < is; j++) { oaf32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final float ox = (float) Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble); for (int j = 0; j < is; j++) { oaf32data[it.oIndex + j] = ox; } } } break; case Dataset.ARRAYFLOAT64: final double[] oaf64data = ((CompoundDoubleDataset) result).data; if (inDegrees) { while (it.hasNext()) { final double ox = Math.toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble)); for (int j = 0; j < is; j++) { oaf64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final double ox = Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble); for (int j = 0; j < is; j++) { oaf64data[it.oIndex + j] = ox; } } } break; case Dataset.COMPLEX64: final float[] oc64data = ((ComplexFloatDataset) result).data; if (inDegrees) { while (it.hasNext()) { oc64data[it.oIndex] = (float) Math .toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble)); oc64data[it.oIndex + 1] = 0; } } else { while (it.hasNext()) { oc64data[it.oIndex] = (float) Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble); oc64data[it.oIndex + 1] = 0; } } break; case Dataset.COMPLEX128: final double[] oc128data = ((ComplexDoubleDataset) result).data; if (inDegrees) { while (it.hasNext()) { oc128data[it.oIndex] = Math .toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble)); oc128data[it.oIndex + 1] = 0; } } else { while (it.hasNext()) { oc128data[it.oIndex] = Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble); oc128data[it.oIndex + 1] = 0; } } break; default: throw new IllegalArgumentException("angle does not support this dataset type"); } addFunctionName(result, "angle"); return result; }
From source file:com.example.sensingapp.SensingApp.java
public void recordSensingInfo(SensorData senData) { String sRecordLine;//from w ww .j ava2 s .co m String sTimeField; Date dtCurDate; int i; long lStartTime = 0; long lCurrentTime = 0; SimpleDateFormat spdRecordTime, spdCurDateTime; final String DATE_FORMAT = "yyyyMMddHHmmss"; final String DATE_FORMAT_S = "yyMMddHHmmssSSS"; //"yyyyMMddHHmmssSSS" int nSensorReadingType = SENSOR_EVENT_NULL; int nSensorDataType; if (m_blnRecordStatus == false) { //Stopped return; } dtCurDate = new Date(); // Timestamp for the record spdRecordTime = new SimpleDateFormat(DATE_FORMAT_S); sTimeField = spdRecordTime.format(dtCurDate); nSensorDataType = senData.getSensorDataType(); if (nSensorDataType == DATA_TYPE_SENSOR) { SensorEvent event; event = senData.getSensorEvent(); synchronized (this) { switch (event.sensor.getType()) { case Sensor.TYPE_ACCELEROMETER: //X, Y, Z if (m_blnAcclEnabled) { m_sAccl = Float.toString(event.values[0]) + "," + Float.toString(event.values[1]) + "," + Float.toString(event.values[2]) + ","; nSensorReadingType = SENSOR_EVENT_ACCL; } // if (m_blnOrientEnabled) { // m_arrfAcclValues = event.values.clone(); // // if (calculateOrientation()) { // //Azimuth (rotation around z-axis); Pitch (rotation around x-axis), Roll (rotation around y-axis) // m_sOrient = Float.toString(m_arrfOrientValues[0]) + "," + // Float.toString(m_arrfOrientValues[1]) + "," + // Float.toString(m_arrfOrientValues[2]) + ","; // // nSensorReadingType = SENSOR_EVENT_ORIENT; // // } // } break; case Sensor.TYPE_LINEAR_ACCELERATION: //X,Y,Z if (m_blnLinearAcclEnabled) { m_sLinearAccl = Float.toString(event.values[0]) + "," + Float.toString(event.values[1]) + "," + Float.toString(event.values[2]) + ","; nSensorReadingType = SENSOR_EVENT_LINEAR_ACCL; } break; case Sensor.TYPE_GRAVITY: //X,Y,Z if (m_blnGravityEnabled) { m_sGravity = Float.toString(event.values[0]) + "," + Float.toString(event.values[1]) + "," + Float.toString(event.values[2]) + ","; nSensorReadingType = SENSOR_EVENT_GRAVITY; } break; case Sensor.TYPE_GYROSCOPE: //X,Y,Z m_sGyro = Float.toString(event.values[0]) + "," + Float.toString(event.values[1]) + "," + Float.toString(event.values[2]) + ","; nSensorReadingType = SENSOR_EVENT_GYRO; break; case Sensor.TYPE_MAGNETIC_FIELD: // Values are in micro-Tesla (uT) and measure the ambient magnetic field if (m_blnMagnetEnabled) { m_sMagnet = Float.toString(event.values[0]) + "," + Float.toString(event.values[1]) + "," + Float.toString(event.values[2]) + ","; nSensorReadingType = SENSOR_EVENT_MAGNET; } // if (m_blnOrientEnabled) { // m_arrfMagnetValues = event.values.clone(); // // if (calculateOrientation()) { // //Azimuth (rotation around z-axis); Pitch (rotation around x-axis), Roll (rotation around y-axis) // m_sOrient = Float.toString(m_arrfOrientValues[0]) + "," + // Float.toString(m_arrfOrientValues[1]) + "," + // Float.toString(m_arrfOrientValues[2]) + ","; // // if (nSensorReadingType != SENSOR_EVENT_MAGNET) { // nSensorReadingType = SENSOR_EVENT_ORIENT; // } // } // } break; case Sensor.TYPE_ROTATION_VECTOR: //Added on 20150910 if (m_blnOrientEnabled) { float[] arrfRotVal = new float[3]; float[] arrfR = new float[9]; float[] arrfValues = new float[3]; try { System.arraycopy(event.values, 0, arrfRotVal, 0, event.values.length); } catch (IllegalArgumentException e) { //Hardcode the size to handle a bug on Samsung devices System.arraycopy(event.values, 0, arrfRotVal, 0, 3); } SensorManager.getRotationMatrixFromVector(arrfR, arrfRotVal); SensorManager.getOrientation(arrfR, arrfValues); m_arrfOrientValues[0] = (float) Math.toDegrees(arrfValues[0]); m_arrfOrientValues[1] = (float) Math.toDegrees(arrfValues[1]); m_arrfOrientValues[2] = (float) Math.toDegrees(arrfValues[2]); if (m_arrfOrientValues[0] < 0) { m_arrfOrientValues[0] = m_arrfOrientValues[0] + 360; // Make Azimuth 0 ~ 360 } // //Azimuth (rotation around z-axis); Pitch (rotation around x-axis), Roll (rotation around y-axis) m_sOrient = Float.toString(m_arrfOrientValues[0]) + "," + Float.toString(m_arrfOrientValues[1]) + "," + Float.toString(m_arrfOrientValues[2]) + ","; //m_tvGpsUp.setText(m_sOrient); //Show orientation nSensorReadingType = SENSOR_EVENT_ORIENT; } break; case Sensor.TYPE_LIGHT: // Ambient light level in SI lux units m_sLight = Float.toString(event.values[0]) + ","; nSensorReadingType = SENSOR_EVENT_LIGHT; break; case Sensor.TYPE_PRESSURE: // Atmospheric pressure in hPa (millibar) m_sBarometer = Float.toString(event.values[0]) + ","; nSensorReadingType = SENSOR_EVENT_BAROMETER; break; } } } else if (nSensorDataType == DATA_TYPE_GPS) { Location locationGps; locationGps = senData.getGpsLocation(); if (locationGps != null) { m_location = new Location(locationGps); //Change from double to float m_sGPS = Float.valueOf((float) (locationGps.getLatitude())).toString() + "," + Float.valueOf((float) (locationGps.getLongitude())).toString() + ","; if (locationGps.hasAltitude()) { m_sGPS = m_sGPS + Float.valueOf((float) (locationGps.getAltitude())).toString() + ","; GeomagneticField geoField = new GeomagneticField( Double.valueOf(locationGps.getLatitude()).floatValue(), Double.valueOf(locationGps.getLongitude()).floatValue(), Double.valueOf(locationGps.getAltitude()).floatValue(), System.currentTimeMillis()); // Append Declination, in Degree m_sGPS = m_sGPS + Float.valueOf((float) (geoField.getDeclination())).toString() + "," + Float.valueOf((float) (geoField.getInclination())).toString() + ","; } else { m_sGPS = m_sGPS + ",,,"; //m_sGPS = m_sGPS + ","; } //New add 201408270009 if (locationGps.hasSpeed()) { m_sGPS = m_sGPS + Float.valueOf((float) (locationGps.getSpeed())).toString() + ","; } else { m_sGPS = m_sGPS + ","; } if (locationGps.hasBearing()) { m_sGPS = m_sGPS + Float.valueOf((float) (locationGps.getBearing())).toString() + ","; } else { m_sGPS = m_sGPS + ","; } nSensorReadingType = SENSOR_EVENT_GPS; m_blnGpsUp = true; show_screen5_GpsUp(); } else { m_blnGpsUp = false; show_screen5_GpsUp(); } } else if (nSensorDataType == DATA_TYPE_MIC) { double fSoundLevelDb; fSoundLevelDb = senData.getSoundLevelDb(); m_sSouldLevel = new BigDecimal(fSoundLevelDb).setScale(0, BigDecimal.ROUND_HALF_UP) + ","; nSensorReadingType = SENSOR_EVENT_MIC; } else if (nSensorDataType == DATA_TYPE_CELLULAR) { int nCellId; nCellId = senData.getCellId(); m_sCellId = Integer.valueOf(nCellId).toString() + ","; nSensorReadingType = SENSOR_EVENT_CELLULAR; } else if (nSensorDataType == DATA_TYPE_WIFI) { List<WifiData> lstWifiData = senData.getListWifiData(); int nWifiCnt = Math.min(WIFI_COUNT, lstWifiData.size()); m_sWifi = ""; for (i = 0; i < nWifiCnt; i++) { //m_sWifi = m_sWifi + lstWifiData.get(i).getSSID() + "," + lstWifiData.get(i).getBSSID() + "," + lstWifiData.get(i).getSignalLevel() + ","; m_sWifi = m_sWifi + lstWifiData.get(i).getBSSID() + "," + lstWifiData.get(i).getSignalLevel() + ","; } for (i = 1; i <= WIFI_COUNT - nWifiCnt; i++) { //m_sWifi = m_sWifi + ",,,"; m_sWifi = m_sWifi + ",,"; } nSensorReadingType = SENSOR_EVENT_WIFI; } if (nSensorReadingType == SENSOR_EVENT_NULL) { return; } sRecordLine = sTimeField + ","; if (m_blnNoLabel == false) { sRecordLine = sRecordLine + m_sCurrentLabel + ","; } sRecordLine = sRecordLine + Integer.valueOf(nSensorReadingType) + ","; //New: Every field always there //Field in each line: /* * 1) Timestamp * 2) Label * 3) SensingEventType * 4-6) Accl * 7-9) Linear Accl * 10-12) Gravity * 13-15) Gyro * 16-18) Orientation * 19-21) Magnet * 22) Light * 23) Barometer * 24) Sould Level (Decibel) * 25) Cell ID * 26-32) GPS (Lat, Long, Alt, Declination, Inclination, Speed, Bearing) * 33-72) WiFi (<BSSID, Level>) */ // sRecordLine = sRecordLine + m_sAccl + m_sGyro + m_sOrient + m_sMagnet + // m_sLight + m_sBarometer + // m_sSouldLevel + m_sCellId + // m_sGPS + m_sWifi; sRecordLine = sRecordLine + m_sAccl + m_sLinearAccl + m_sGravity + m_sGyro + m_sOrient + m_sMagnet + m_sLight + m_sBarometer + m_sSouldLevel + m_sCellId + m_sGPS + m_sWifi; //////////////////////////// // String sAngle = calculateRot(m_sAccl, m_sGravity); // String sarrAngle[] = sAngle.split(","); // String sShow = sarrAngle[0] + "\n" + sarrAngle[1]; // String sShow = ""; // if (m_sGravity.length() > 3) { // String sarrAngle[] = m_sGravity.split(","); // double fX = Double.valueOf(sarrAngle[0]).doubleValue(); // double fY = Double.valueOf(sarrAngle[1]).doubleValue(); // double fZ = Double.valueOf(sarrAngle[2]).doubleValue(); // // double fTotal = Math.sqrt(fX*fX + fY*fY + fZ*fZ); // // double fAngleZ = Math.acos(fZ/fTotal)/Math.PI*180; // double fAngleY = 90 - Math.acos(fY/fTotal)/Math.PI*180; // double fAngleX = 90 - Math.acos(fX/fTotal)/Math.PI*180; // // sShow = "X: " + fAngleX + "\n"; // sShow = sShow + "Y: " + fAngleY + "\n"; // sShow = sShow + "Z: " + fAngleZ; // // // } // if (m_sGravity.length() > 3) { // String sarrAngle[] = m_sGravity.split(","); // double fX = Double.valueOf(sarrAngle[0]).doubleValue(); // double fY = Double.valueOf(sarrAngle[1]).doubleValue(); // double fZ = Double.valueOf(sarrAngle[2]).doubleValue(); // // int nSymbol = 0; // if (fX < 0) { // sShow = sShow + "- X" + "\n"; // } else if (fX > 0) { // sShow = sShow + "+ X" + "\n"; // } // // if (fY < 0) { // sShow = sShow + "- Y" + "\n"; // } else if (fY > 0) { // sShow = sShow + "+ Y" + "\n"; // } // // if (fZ < 0) { // sShow = sShow + "- Z"; // } else if (fZ > 0) { // sShow = sShow + "+ Z"; // } // // } // // if (m_sGyro.length() > 3) { // String sarrAngle[] = m_sGyro.split(","); // double fX = Double.valueOf(sarrAngle[0]).doubleValue(); // double fY = Double.valueOf(sarrAngle[1]).doubleValue(); // double fZ = Double.valueOf(sarrAngle[2]).doubleValue(); // // int nSymbol = 0; // if (fX < 0) { // nSymbol = -1; // } else if (fX > 0) { // nSymbol = 1; // } // // if (fY < 0) { // nSymbol = nSymbol + (-1); // } else if (fY > 0) { // nSymbol = nSymbol + 1; // } // // if (fZ < 0) { // nSymbol = nSymbol + (-1); // } else if (fZ > 0) { // nSymbol = nSymbol + 1; // } // // if (nSymbol < 0) { // nSymbol = -1; // } else if (nSymbol > 0) { // nSymbol = 1; // } // // sShow = sShow + "\n\n" + nSymbol + ""; // } // m_tvSensingInfo.setText(sShow); //////////////////////////// sRecordLine = sRecordLine + System.getProperty("line.separator"); if (m_fwSensorRecord != null) { //Write information into file //Compose information into recordLine try { m_fwSensorRecord.write(sRecordLine); } catch (IOException e) { } } }
From source file:geogebra.kernel.Kernel.java
final public StringBuilder formatAngle(double phi, double precision) { sbFormatAngle.setLength(0);/*from w w w.java 2 s . c o m*/ switch (casPrintForm) { case ExpressionNode.STRING_TYPE_MATH_PIPER: case ExpressionNode.STRING_TYPE_JASYMCA: case ExpressionNode.STRING_TYPE_MPREDUCE: if (angleUnit == ANGLE_DEGREE) { sbFormatAngle.append("("); // STANDARD_PRECISION * 10 as we need a little leeway as we've converted from radians sbFormatAngle.append(format(checkDecimalFraction(Math.toDegrees(phi), precision))); sbFormatAngle.append("*"); sbFormatAngle.append("\u00b0"); sbFormatAngle.append(")"); } else { sbFormatAngle.append(format(phi)); } return sbFormatAngle; default: // STRING_TYPE_GEOGEBRA_XML // STRING_TYPE_GEOGEBRA if (Double.isNaN(phi)) { sbFormatAngle.append("?"); return sbFormatAngle; } if (angleUnit == ANGLE_DEGREE) { boolean rtl = app.isRightToLeftDigits(); if (rtl) { sbFormatAngle.append(Unicode.degreeChar); } phi = Math.toDegrees(phi); if (phi < 0) phi += 360; else if (phi > 360) phi = phi % 360; // STANDARD_PRECISION * 10 as we need a little leeway as we've converted from radians sbFormatAngle.append(format(checkDecimalFraction(phi, precision))); if (casPrintForm == ExpressionNode.STRING_TYPE_GEOGEBRA_XML) { sbFormatAngle.append("*"); } if (!rtl) sbFormatAngle.append(Unicode.degreeChar); return sbFormatAngle; } else { // RADIANS sbFormatAngle.append(format(phi)); if (casPrintForm != ExpressionNode.STRING_TYPE_GEOGEBRA_XML) { sbFormatAngle.append(" rad"); } return sbFormatAngle; } } }
From source file:uk.ac.diamond.scisoft.analysis.dataset.Maths.java
/** * toDegrees - convert to degrees//from ww w .j ava2 s. c o m * @param a * @return dataset */ @SuppressWarnings("cast") public static AbstractDataset toDegrees(final AbstractDataset a) { final int isize; final IndexIterator it = a.getIterator(); AbstractDataset ds; final int dt = a.getDtype(); switch (dt) { case AbstractDataset.INT8: ds = AbstractDataset.zeros(a, AbstractDataset.FLOAT32); final byte[] i8data = ((ByteDataset) a).data; final float[] oi8data = ((FloatDataset) ds).getData(); for (int i = 0; it.hasNext();) { final byte ix = i8data[it.index]; float ox; ox = (float) (Math.toDegrees(ix)); oi8data[i++] = ox; } break; case AbstractDataset.INT16: ds = AbstractDataset.zeros(a, AbstractDataset.FLOAT32); final short[] i16data = ((ShortDataset) a).data; final float[] oi16data = ((FloatDataset) ds).getData(); for (int i = 0; it.hasNext();) { final short ix = i16data[it.index]; float ox; ox = (float) (Math.toDegrees(ix)); oi16data[i++] = ox; } break; case AbstractDataset.INT32: ds = AbstractDataset.zeros(a, AbstractDataset.FLOAT64); final int[] i32data = ((IntegerDataset) a).data; final double[] oi32data = ((DoubleDataset) ds).getData(); for (int i = 0; it.hasNext();) { final int ix = i32data[it.index]; double ox; ox = (double) (Math.toDegrees(ix)); oi32data[i++] = ox; } break; case AbstractDataset.INT64: ds = AbstractDataset.zeros(a, AbstractDataset.FLOAT64); final long[] i64data = ((LongDataset) a).data; final double[] oi64data = ((DoubleDataset) ds).getData(); for (int i = 0; it.hasNext();) { final long ix = i64data[it.index]; double ox; ox = (double) (Math.toDegrees(ix)); oi64data[i++] = ox; } break; case AbstractDataset.ARRAYINT8: ds = AbstractDataset.zeros(a, AbstractDataset.ARRAYFLOAT32); isize = a.getElementsPerItem(); final byte[] ai8data = ((CompoundByteDataset) a).data; final float[] oai8data = ((CompoundFloatDataset) ds).getData(); for (int i = 0; it.hasNext();) { for (int j = 0; j < isize; j++) { final byte ix = ai8data[it.index + j]; float ox; ox = (float) (Math.toDegrees(ix)); oai8data[i++] = ox; } } break; case AbstractDataset.ARRAYINT16: ds = AbstractDataset.zeros(a, AbstractDataset.ARRAYFLOAT32); isize = a.getElementsPerItem(); final short[] ai16data = ((CompoundShortDataset) a).data; final float[] oai16data = ((CompoundFloatDataset) ds).getData(); for (int i = 0; it.hasNext();) { for (int j = 0; j < isize; j++) { final short ix = ai16data[it.index + j]; float ox; ox = (float) (Math.toDegrees(ix)); oai16data[i++] = ox; } } break; case AbstractDataset.ARRAYINT32: ds = AbstractDataset.zeros(a, AbstractDataset.ARRAYFLOAT64); isize = a.getElementsPerItem(); final int[] ai32data = ((CompoundIntegerDataset) a).data; final double[] oai32data = ((CompoundDoubleDataset) ds).getData(); for (int i = 0; it.hasNext();) { for (int j = 0; j < isize; j++) { final int ix = ai32data[it.index + j]; double ox; ox = (double) (Math.toDegrees(ix)); oai32data[i++] = ox; } } break; case AbstractDataset.ARRAYINT64: ds = AbstractDataset.zeros(a, AbstractDataset.ARRAYFLOAT64); isize = a.getElementsPerItem(); final long[] ai64data = ((CompoundLongDataset) a).data; final double[] oai64data = ((CompoundDoubleDataset) ds).getData(); for (int i = 0; it.hasNext();) { for (int j = 0; j < isize; j++) { final long ix = ai64data[it.index + j]; double ox; ox = (double) (Math.toDegrees(ix)); oai64data[i++] = ox; } } break; case AbstractDataset.FLOAT32: ds = AbstractDataset.zeros(a, AbstractDataset.FLOAT32); final float[] f32data = ((FloatDataset) a).data; final float[] of32data = ((FloatDataset) ds).getData(); for (int i = 0; it.hasNext();) { final float ix = f32data[it.index]; float ox; ox = (float) (Math.toDegrees(ix)); of32data[i++] = ox; } break; case AbstractDataset.FLOAT64: ds = AbstractDataset.zeros(a, AbstractDataset.FLOAT64); final double[] f64data = ((DoubleDataset) a).data; final double[] of64data = ((DoubleDataset) ds).getData(); for (int i = 0; it.hasNext();) { final double ix = f64data[it.index]; double ox; ox = (double) (Math.toDegrees(ix)); of64data[i++] = ox; } break; case AbstractDataset.ARRAYFLOAT32: ds = AbstractDataset.zeros(a, AbstractDataset.ARRAYFLOAT32); isize = a.getElementsPerItem(); final float[] af32data = ((CompoundFloatDataset) a).data; final float[] oaf32data = ((CompoundFloatDataset) ds).getData(); for (int i = 0; it.hasNext();) { for (int j = 0; j < isize; j++) { final float ix = af32data[it.index + j]; float ox; ox = (float) (Math.toDegrees(ix)); oaf32data[i++] = ox; } } break; case AbstractDataset.ARRAYFLOAT64: ds = AbstractDataset.zeros(a, AbstractDataset.ARRAYFLOAT64); isize = a.getElementsPerItem(); final double[] af64data = ((CompoundDoubleDataset) a).data; final double[] oaf64data = ((CompoundDoubleDataset) ds).getData(); for (int i = 0; it.hasNext();) { for (int j = 0; j < isize; j++) { final double ix = af64data[it.index + j]; double ox; ox = (double) (Math.toDegrees(ix)); oaf64data[i++] = ox; } } break; case AbstractDataset.COMPLEX64: ds = AbstractDataset.zeros(a, AbstractDataset.COMPLEX64); final float[] c64data = ((ComplexFloatDataset) a).data; final float[] oc64data = ((ComplexFloatDataset) ds).getData(); for (int i = 0; it.hasNext();) { final float ix = c64data[it.index]; final float iy = c64data[it.index + 1]; float ox; float oy; ox = (float) (Math.toDegrees(ix)); oy = (float) (Math.toDegrees(iy)); oc64data[i++] = ox; oc64data[i++] = oy; } break; case AbstractDataset.COMPLEX128: ds = AbstractDataset.zeros(a, AbstractDataset.COMPLEX128); final double[] c128data = ((ComplexDoubleDataset) a).data; final double[] oc128data = ((ComplexDoubleDataset) ds).getData(); for (int i = 0; it.hasNext();) { final double ix = c128data[it.index]; final double iy = c128data[it.index + 1]; double ox; double oy; ox = (double) (Math.toDegrees(ix)); oy = (double) (Math.toDegrees(iy)); oc128data[i++] = ox; oc128data[i++] = oy; } break; default: throw new IllegalArgumentException( "toDegrees supports integer, compound integer, real, compound real, complex datasets only"); } ds.setName(a.getName()); addFunctionName(ds, "toDegrees"); return ds; }
From source file:org.eclipse.january.dataset.GeneratedMaths.java
/** * toDegrees - convert to degrees/* ww w. jav a 2 s. co m*/ * @param a * @param o output can be null - in which case, a new dataset is created * @return dataset */ public static Dataset toDegrees(final Object a, final Dataset o) { final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a); final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true); final Dataset result = it.getOutput(); final int is = result.getElementsPerItem(); final int as = da.getElementsPerItem(); final int dt = result.getDType(); switch (dt) { case Dataset.INT8: final byte[] oi8data = ((ByteDataset) result).getData(); if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; byte ox; ox = (byte) toLong(Math.toDegrees(ix)); oi8data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; byte ox; ox = (byte) toLong(Math.toDegrees(ix)); oi8data[it.oIndex] = ox; } } break; case Dataset.INT16: final short[] oi16data = ((ShortDataset) result).getData(); if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; short ox; ox = (short) toLong(Math.toDegrees(ix)); oi16data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; short ox; ox = (short) toLong(Math.toDegrees(ix)); oi16data[it.oIndex] = ox; } } break; case Dataset.INT64: final long[] oi64data = ((LongDataset) result).getData(); if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; long ox; ox = toLong(Math.toDegrees(ix)); oi64data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; long ox; ox = toLong(Math.toDegrees(ix)); oi64data[it.oIndex] = ox; } } break; case Dataset.INT32: final int[] oi32data = ((IntegerDataset) result).getData(); if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; int ox; ox = (int) toLong(Math.toDegrees(ix)); oi32data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; int ox; ox = (int) toLong(Math.toDegrees(ix)); oi32data[it.oIndex] = ox; } } break; case Dataset.ARRAYINT8: final byte[] oai8data = ((CompoundByteDataset) result).getData(); if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; byte ox; ox = (byte) toLong(Math.toDegrees(ix)); oai8data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; byte ox; ox = (byte) toLong(Math.toDegrees(ix)); oai8data[it.oIndex] = ox; } } } else if (as == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; byte ox; ox = (byte) toLong(Math.toDegrees(ix)); for (int j = 0; j < is; j++) { oai8data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; byte ox; ox = (byte) toLong(Math.toDegrees(ix)); for (int j = 0; j < is; j++) { oai8data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); byte ox; ox = (byte) toLong(Math.toDegrees(ix)); oai8data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); byte ox; ox = (byte) toLong(Math.toDegrees(ix)); oai8data[it.oIndex + j] = ox; } } } } break; case Dataset.ARRAYINT16: final short[] oai16data = ((CompoundShortDataset) result).getData(); if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; short ox; ox = (short) toLong(Math.toDegrees(ix)); oai16data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; short ox; ox = (short) toLong(Math.toDegrees(ix)); oai16data[it.oIndex] = ox; } } } else if (as == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; short ox; ox = (short) toLong(Math.toDegrees(ix)); for (int j = 0; j < is; j++) { oai16data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; short ox; ox = (short) toLong(Math.toDegrees(ix)); for (int j = 0; j < is; j++) { oai16data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); short ox; ox = (short) toLong(Math.toDegrees(ix)); oai16data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); short ox; ox = (short) toLong(Math.toDegrees(ix)); oai16data[it.oIndex + j] = ox; } } } } break; case Dataset.ARRAYINT64: final long[] oai64data = ((CompoundLongDataset) result).getData(); if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; long ox; ox = toLong(Math.toDegrees(ix)); oai64data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; long ox; ox = toLong(Math.toDegrees(ix)); oai64data[it.oIndex] = ox; } } } else if (as == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; long ox; ox = toLong(Math.toDegrees(ix)); for (int j = 0; j < is; j++) { oai64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; long ox; ox = toLong(Math.toDegrees(ix)); for (int j = 0; j < is; j++) { oai64data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); long ox; ox = toLong(Math.toDegrees(ix)); oai64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); long ox; ox = toLong(Math.toDegrees(ix)); oai64data[it.oIndex + j] = ox; } } } } break; case Dataset.ARRAYINT32: final int[] oai32data = ((CompoundIntegerDataset) result).getData(); if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; int ox; ox = (int) toLong(Math.toDegrees(ix)); oai32data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; int ox; ox = (int) toLong(Math.toDegrees(ix)); oai32data[it.oIndex] = ox; } } } else if (as == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; int ox; ox = (int) toLong(Math.toDegrees(ix)); for (int j = 0; j < is; j++) { oai32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; int ox; ox = (int) toLong(Math.toDegrees(ix)); for (int j = 0; j < is; j++) { oai32data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); int ox; ox = (int) toLong(Math.toDegrees(ix)); oai32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); int ox; ox = (int) toLong(Math.toDegrees(ix)); oai32data[it.oIndex + j] = ox; } } } } break; case Dataset.FLOAT32: final float[] of32data = ((FloatDataset) result).getData(); if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; float ox; ox = (float) (Math.toDegrees(ix)); of32data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; float ox; ox = (float) (Math.toDegrees(ix)); of32data[it.oIndex] = ox; } } break; case Dataset.FLOAT64: final double[] of64data = ((DoubleDataset) result).getData(); if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; double ox; ox = (Math.toDegrees(ix)); of64data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; double ox; ox = (Math.toDegrees(ix)); of64data[it.oIndex] = ox; } } break; case Dataset.ARRAYFLOAT32: final float[] oaf32data = ((CompoundFloatDataset) result).getData(); if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; float ox; ox = (float) (Math.toDegrees(ix)); oaf32data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; float ox; ox = (float) (Math.toDegrees(ix)); oaf32data[it.oIndex] = ox; } } } else if (as == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; float ox; ox = (float) (Math.toDegrees(ix)); for (int j = 0; j < is; j++) { oaf32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; float ox; ox = (float) (Math.toDegrees(ix)); for (int j = 0; j < is; j++) { oaf32data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); float ox; ox = (float) (Math.toDegrees(ix)); oaf32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); float ox; ox = (float) (Math.toDegrees(ix)); oaf32data[it.oIndex + j] = ox; } } } } break; case Dataset.ARRAYFLOAT64: final double[] oaf64data = ((CompoundDoubleDataset) result).getData(); if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; double ox; ox = (Math.toDegrees(ix)); oaf64data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; double ox; ox = (Math.toDegrees(ix)); oaf64data[it.oIndex] = ox; } } } else if (as == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; double ox; ox = (Math.toDegrees(ix)); for (int j = 0; j < is; j++) { oaf64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; double ox; ox = (Math.toDegrees(ix)); for (int j = 0; j < is; j++) { oaf64data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); double ox; ox = (Math.toDegrees(ix)); oaf64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); double ox; ox = (Math.toDegrees(ix)); oaf64data[it.oIndex + j] = ox; } } } } break; case Dataset.COMPLEX64: final float[] oc64data = ((ComplexFloatDataset) result).getData(); if (as == 1) { final double iy = 0; while (it.hasNext()) { final double ix = it.aDouble; float ox; float oy; ox = (float) (Math.toDegrees(ix)); oy = (float) (Math.toDegrees(iy)); oc64data[it.oIndex] = ox; oc64data[it.oIndex + 1] = oy; } } else { while (it.hasNext()) { final double ix = it.aDouble; final double iy = da.getElementDoubleAbs(it.aIndex + 1); float ox; float oy; ox = (float) (Math.toDegrees(ix)); oy = (float) (Math.toDegrees(iy)); oc64data[it.oIndex] = ox; oc64data[it.oIndex + 1] = oy; } } break; case Dataset.COMPLEX128: final double[] oc128data = ((ComplexDoubleDataset) result).getData(); if (as == 1) { final double iy = 0; while (it.hasNext()) { final double ix = it.aDouble; double ox; double oy; ox = (Math.toDegrees(ix)); oy = (Math.toDegrees(iy)); oc128data[it.oIndex] = ox; oc128data[it.oIndex + 1] = oy; } } else { while (it.hasNext()) { final double ix = it.aDouble; final double iy = da.getElementDoubleAbs(it.aIndex + 1); double ox; double oy; ox = (Math.toDegrees(ix)); oy = (Math.toDegrees(iy)); oc128data[it.oIndex] = ox; oc128data[it.oIndex + 1] = oy; } } break; default: throw new IllegalArgumentException( "toDegrees supports integer, compound integer, real, compound real, complex datasets only"); } addFunctionName(result, "toDegrees"); return result; }
From source file:org.eclipse.january.dataset.Maths.java
/** * toDegrees - convert to degrees//w ww. j a v a 2 s.co m * @param a * @param o output can be null - in which case, a new dataset is created * @return dataset */ public static Dataset toDegrees(final Object a, final Dataset o) { final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a); final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true); final Dataset result = it.getOutput(); final int is = result.getElementsPerItem(); final int dt = result.getDType(); switch (dt) { case Dataset.INT8: final byte[] oi8data = ((ByteDataset) result).data; if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; byte ox; ox = (byte) toLong(Math.toDegrees(ix)); oi8data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; byte ox; ox = (byte) toLong(Math.toDegrees(ix)); oi8data[it.oIndex] = ox; } } break; case Dataset.INT16: final short[] oi16data = ((ShortDataset) result).data; if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; short ox; ox = (short) toLong(Math.toDegrees(ix)); oi16data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; short ox; ox = (short) toLong(Math.toDegrees(ix)); oi16data[it.oIndex] = ox; } } break; case Dataset.INT64: final long[] oi64data = ((LongDataset) result).data; if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; long ox; ox = toLong(Math.toDegrees(ix)); oi64data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; long ox; ox = toLong(Math.toDegrees(ix)); oi64data[it.oIndex] = ox; } } break; case Dataset.INT32: final int[] oi32data = ((IntegerDataset) result).data; if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; int ox; ox = (int) toLong(Math.toDegrees(ix)); oi32data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; int ox; ox = (int) toLong(Math.toDegrees(ix)); oi32data[it.oIndex] = ox; } } break; case Dataset.ARRAYINT8: final byte[] oai8data = ((CompoundByteDataset) result).data; if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; byte ox; ox = (byte) toLong(Math.toDegrees(ix)); oai8data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; byte ox; ox = (byte) toLong(Math.toDegrees(ix)); oai8data[it.oIndex] = ox; } } } else if (da.getElementsPerItem() == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; byte ox; ox = (byte) toLong(Math.toDegrees(ix)); for (int j = 0; j < is; j++) { oai8data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; byte ox; ox = (byte) toLong(Math.toDegrees(ix)); for (int j = 0; j < is; j++) { oai8data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); byte ox; ox = (byte) toLong(Math.toDegrees(ix)); oai8data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); byte ox; ox = (byte) toLong(Math.toDegrees(ix)); oai8data[it.oIndex + j] = ox; } } } } break; case Dataset.ARRAYINT16: final short[] oai16data = ((CompoundShortDataset) result).data; if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; short ox; ox = (short) toLong(Math.toDegrees(ix)); oai16data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; short ox; ox = (short) toLong(Math.toDegrees(ix)); oai16data[it.oIndex] = ox; } } } else if (da.getElementsPerItem() == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; short ox; ox = (short) toLong(Math.toDegrees(ix)); for (int j = 0; j < is; j++) { oai16data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; short ox; ox = (short) toLong(Math.toDegrees(ix)); for (int j = 0; j < is; j++) { oai16data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); short ox; ox = (short) toLong(Math.toDegrees(ix)); oai16data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); short ox; ox = (short) toLong(Math.toDegrees(ix)); oai16data[it.oIndex + j] = ox; } } } } break; case Dataset.ARRAYINT64: final long[] oai64data = ((CompoundLongDataset) result).data; if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; long ox; ox = toLong(Math.toDegrees(ix)); oai64data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; long ox; ox = toLong(Math.toDegrees(ix)); oai64data[it.oIndex] = ox; } } } else if (da.getElementsPerItem() == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; long ox; ox = toLong(Math.toDegrees(ix)); for (int j = 0; j < is; j++) { oai64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; long ox; ox = toLong(Math.toDegrees(ix)); for (int j = 0; j < is; j++) { oai64data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); long ox; ox = toLong(Math.toDegrees(ix)); oai64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); long ox; ox = toLong(Math.toDegrees(ix)); oai64data[it.oIndex + j] = ox; } } } } break; case Dataset.ARRAYINT32: final int[] oai32data = ((CompoundIntegerDataset) result).data; if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; int ox; ox = (int) toLong(Math.toDegrees(ix)); oai32data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; int ox; ox = (int) toLong(Math.toDegrees(ix)); oai32data[it.oIndex] = ox; } } } else if (da.getElementsPerItem() == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; int ox; ox = (int) toLong(Math.toDegrees(ix)); for (int j = 0; j < is; j++) { oai32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; int ox; ox = (int) toLong(Math.toDegrees(ix)); for (int j = 0; j < is; j++) { oai32data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); int ox; ox = (int) toLong(Math.toDegrees(ix)); oai32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); int ox; ox = (int) toLong(Math.toDegrees(ix)); oai32data[it.oIndex + j] = ox; } } } } break; case Dataset.FLOAT32: final float[] of32data = ((FloatDataset) result).data; if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; float ox; ox = (float) (Math.toDegrees(ix)); of32data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; float ox; ox = (float) (Math.toDegrees(ix)); of32data[it.oIndex] = ox; } } break; case Dataset.FLOAT64: final double[] of64data = ((DoubleDataset) result).data; if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; double ox; ox = (Math.toDegrees(ix)); of64data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; double ox; ox = (Math.toDegrees(ix)); of64data[it.oIndex] = ox; } } break; case Dataset.ARRAYFLOAT32: final float[] oaf32data = ((CompoundFloatDataset) result).data; if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; float ox; ox = (float) (Math.toDegrees(ix)); oaf32data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; float ox; ox = (float) (Math.toDegrees(ix)); oaf32data[it.oIndex] = ox; } } } else if (da.getElementsPerItem() == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; float ox; ox = (float) (Math.toDegrees(ix)); for (int j = 0; j < is; j++) { oaf32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; float ox; ox = (float) (Math.toDegrees(ix)); for (int j = 0; j < is; j++) { oaf32data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); float ox; ox = (float) (Math.toDegrees(ix)); oaf32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); float ox; ox = (float) (Math.toDegrees(ix)); oaf32data[it.oIndex + j] = ox; } } } } break; case Dataset.ARRAYFLOAT64: final double[] oaf64data = ((CompoundDoubleDataset) result).data; if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; double ox; ox = (Math.toDegrees(ix)); oaf64data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; double ox; ox = (Math.toDegrees(ix)); oaf64data[it.oIndex] = ox; } } } else if (da.getElementsPerItem() == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; double ox; ox = (Math.toDegrees(ix)); for (int j = 0; j < is; j++) { oaf64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; double ox; ox = (Math.toDegrees(ix)); for (int j = 0; j < is; j++) { oaf64data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); double ox; ox = (Math.toDegrees(ix)); oaf64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); double ox; ox = (Math.toDegrees(ix)); oaf64data[it.oIndex + j] = ox; } } } } break; case Dataset.COMPLEX64: final float[] oc64data = ((ComplexFloatDataset) result).data; if (da.getElementsPerItem() == 1) { final double iy = 0; while (it.hasNext()) { final double ix = it.aDouble; float ox; float oy; ox = (float) (Math.toDegrees(ix)); oy = (float) (Math.toDegrees(iy)); oc64data[it.oIndex] = ox; oc64data[it.oIndex + 1] = oy; } } else { while (it.hasNext()) { final double ix = it.aDouble; final double iy = da.getElementDoubleAbs(it.aIndex + 1); float ox; float oy; ox = (float) (Math.toDegrees(ix)); oy = (float) (Math.toDegrees(iy)); oc64data[it.oIndex] = ox; oc64data[it.oIndex + 1] = oy; } } break; case Dataset.COMPLEX128: final double[] oc128data = ((ComplexDoubleDataset) result).data; if (da.getElementsPerItem() == 1) { final double iy = 0; while (it.hasNext()) { final double ix = it.aDouble; double ox; double oy; ox = (Math.toDegrees(ix)); oy = (Math.toDegrees(iy)); oc128data[it.oIndex] = ox; oc128data[it.oIndex + 1] = oy; } } else { while (it.hasNext()) { final double ix = it.aDouble; final double iy = da.getElementDoubleAbs(it.aIndex + 1); double ox; double oy; ox = (Math.toDegrees(ix)); oy = (Math.toDegrees(iy)); oc128data[it.oIndex] = ox; oc128data[it.oIndex + 1] = oy; } } break; default: throw new IllegalArgumentException( "toDegrees supports integer, compound integer, real, compound real, complex datasets only"); } addFunctionName(result, "toDegrees"); return result; }
From source file:org.eclipse.dataset.Maths.java
/** * toDegrees - convert to degrees//from w w w.ja v a 2s .c o m * @param a * @param o output can be null - in which case, a new dataset is created * @return dataset */ public static Dataset toDegrees(final Object a, final Dataset o) { final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a); final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true); final Dataset result = it.getOutput(); final int is = result.getElementsPerItem(); final int dt = result.getDtype(); switch (dt) { case Dataset.INT8: final byte[] oi8data = ((ByteDataset) result).data; if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; byte ox; ox = (byte) toLong(Math.toDegrees(ix)); oi8data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; byte ox; ox = (byte) toLong(Math.toDegrees(ix)); oi8data[it.oIndex] = ox; } } break; case Dataset.INT16: final short[] oi16data = ((ShortDataset) result).data; if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; short ox; ox = (short) toLong(Math.toDegrees(ix)); oi16data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; short ox; ox = (short) toLong(Math.toDegrees(ix)); oi16data[it.oIndex] = ox; } } break; case Dataset.INT64: final long[] oi64data = ((LongDataset) result).data; if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; long ox; ox = toLong(Math.toDegrees(ix)); oi64data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; long ox; ox = toLong(Math.toDegrees(ix)); oi64data[it.oIndex] = ox; } } break; case Dataset.INT32: final int[] oi32data = ((IntegerDataset) result).data; if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; int ox; ox = (int) toLong(Math.toDegrees(ix)); oi32data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; int ox; ox = (int) toLong(Math.toDegrees(ix)); oi32data[it.oIndex] = ox; } } break; case Dataset.ARRAYINT8: final byte[] oai8data = ((CompoundByteDataset) result).data; if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; byte ox; ox = (byte) toLong(Math.toDegrees(ix)); oai8data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; byte ox; ox = (byte) toLong(Math.toDegrees(ix)); oai8data[it.oIndex] = ox; } } } else if (da.getElementsPerItem() == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; byte ox; ox = (byte) toLong(Math.toDegrees(ix)); for (int j = 0; j < is; j++) { oai8data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; byte ox; ox = (byte) toLong(Math.toDegrees(ix)); for (int j = 0; j < is; j++) { oai8data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); byte ox; ox = (byte) toLong(Math.toDegrees(ix)); oai8data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); byte ox; ox = (byte) toLong(Math.toDegrees(ix)); oai8data[it.oIndex + j] = ox; } } } } break; case Dataset.ARRAYINT16: final short[] oai16data = ((CompoundShortDataset) result).data; if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; short ox; ox = (short) toLong(Math.toDegrees(ix)); oai16data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; short ox; ox = (short) toLong(Math.toDegrees(ix)); oai16data[it.oIndex] = ox; } } } else if (da.getElementsPerItem() == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; short ox; ox = (short) toLong(Math.toDegrees(ix)); for (int j = 0; j < is; j++) { oai16data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; short ox; ox = (short) toLong(Math.toDegrees(ix)); for (int j = 0; j < is; j++) { oai16data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); short ox; ox = (short) toLong(Math.toDegrees(ix)); oai16data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); short ox; ox = (short) toLong(Math.toDegrees(ix)); oai16data[it.oIndex + j] = ox; } } } } break; case Dataset.ARRAYINT64: final long[] oai64data = ((CompoundLongDataset) result).data; if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; long ox; ox = toLong(Math.toDegrees(ix)); oai64data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; long ox; ox = toLong(Math.toDegrees(ix)); oai64data[it.oIndex] = ox; } } } else if (da.getElementsPerItem() == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; long ox; ox = toLong(Math.toDegrees(ix)); for (int j = 0; j < is; j++) { oai64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; long ox; ox = toLong(Math.toDegrees(ix)); for (int j = 0; j < is; j++) { oai64data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); long ox; ox = toLong(Math.toDegrees(ix)); oai64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); long ox; ox = toLong(Math.toDegrees(ix)); oai64data[it.oIndex + j] = ox; } } } } break; case Dataset.ARRAYINT32: final int[] oai32data = ((CompoundIntegerDataset) result).data; if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; int ox; ox = (int) toLong(Math.toDegrees(ix)); oai32data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; int ox; ox = (int) toLong(Math.toDegrees(ix)); oai32data[it.oIndex] = ox; } } } else if (da.getElementsPerItem() == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; int ox; ox = (int) toLong(Math.toDegrees(ix)); for (int j = 0; j < is; j++) { oai32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; int ox; ox = (int) toLong(Math.toDegrees(ix)); for (int j = 0; j < is; j++) { oai32data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); int ox; ox = (int) toLong(Math.toDegrees(ix)); oai32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); int ox; ox = (int) toLong(Math.toDegrees(ix)); oai32data[it.oIndex + j] = ox; } } } } break; case Dataset.FLOAT32: final float[] of32data = ((FloatDataset) result).data; if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; float ox; ox = (float) (Math.toDegrees(ix)); of32data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; float ox; ox = (float) (Math.toDegrees(ix)); of32data[it.oIndex] = ox; } } break; case Dataset.FLOAT64: final double[] of64data = ((DoubleDataset) result).data; if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; double ox; ox = (Math.toDegrees(ix)); of64data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; double ox; ox = (Math.toDegrees(ix)); of64data[it.oIndex] = ox; } } break; case Dataset.ARRAYFLOAT32: final float[] oaf32data = ((CompoundFloatDataset) result).data; if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; float ox; ox = (float) (Math.toDegrees(ix)); oaf32data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; float ox; ox = (float) (Math.toDegrees(ix)); oaf32data[it.oIndex] = ox; } } } else if (da.getElementsPerItem() == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; float ox; ox = (float) (Math.toDegrees(ix)); for (int j = 0; j < is; j++) { oaf32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; float ox; ox = (float) (Math.toDegrees(ix)); for (int j = 0; j < is; j++) { oaf32data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); float ox; ox = (float) (Math.toDegrees(ix)); oaf32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); float ox; ox = (float) (Math.toDegrees(ix)); oaf32data[it.oIndex + j] = ox; } } } } break; case Dataset.ARRAYFLOAT64: final double[] oaf64data = ((CompoundDoubleDataset) result).data; if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; double ox; ox = (Math.toDegrees(ix)); oaf64data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; double ox; ox = (Math.toDegrees(ix)); oaf64data[it.oIndex] = ox; } } } else if (da.getElementsPerItem() == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; double ox; ox = (Math.toDegrees(ix)); for (int j = 0; j < is; j++) { oaf64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; double ox; ox = (Math.toDegrees(ix)); for (int j = 0; j < is; j++) { oaf64data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); double ox; ox = (Math.toDegrees(ix)); oaf64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); double ox; ox = (Math.toDegrees(ix)); oaf64data[it.oIndex + j] = ox; } } } } break; case Dataset.COMPLEX64: final float[] oc64data = ((ComplexFloatDataset) result).data; if (da.getElementsPerItem() == 1) { final double iy = 0; while (it.hasNext()) { final double ix = it.aDouble; float ox; float oy; ox = (float) (Math.toDegrees(ix)); oy = (float) (Math.toDegrees(iy)); oc64data[it.oIndex] = ox; oc64data[it.oIndex + 1] = oy; } } else { while (it.hasNext()) { final double ix = it.aDouble; final double iy = da.getElementDoubleAbs(it.aIndex + 1); float ox; float oy; ox = (float) (Math.toDegrees(ix)); oy = (float) (Math.toDegrees(iy)); oc64data[it.oIndex] = ox; oc64data[it.oIndex + 1] = oy; } } break; case Dataset.COMPLEX128: final double[] oc128data = ((ComplexDoubleDataset) result).data; if (da.getElementsPerItem() == 1) { final double iy = 0; while (it.hasNext()) { final double ix = it.aDouble; double ox; double oy; ox = (Math.toDegrees(ix)); oy = (Math.toDegrees(iy)); oc128data[it.oIndex] = ox; oc128data[it.oIndex + 1] = oy; } } else { while (it.hasNext()) { final double ix = it.aDouble; final double iy = da.getElementDoubleAbs(it.aIndex + 1); double ox; double oy; ox = (Math.toDegrees(ix)); oy = (Math.toDegrees(iy)); oc128data[it.oIndex] = ox; oc128data[it.oIndex + 1] = oy; } } break; default: throw new IllegalArgumentException( "toDegrees supports integer, compound integer, real, compound real, complex datasets only"); } addFunctionName(result, "toDegrees"); return result; }