Example usage for java.lang Math toRadians

List of usage examples for java.lang Math toRadians

Introduction

In this page you can find the example usage for java.lang Math toRadians.

Prototype

public static double toRadians(double angdeg) 

Source Link

Document

Converts an angle measured in degrees to an approximately equivalent angle measured in radians.

Usage

From source file:com.skumar.flexibleciruclarseekbar.CircularSeekBar.java

/**
 * Method to draw the dots over needle scale
 *
 * @param canvas drawable element/*from  ww w  .  jav a  2 s  .c o  m*/
 */
private void drawDotMarker(Canvas canvas) {
    float cx = canvas.getWidth() / 2;
    float cy = canvas.getHeight() / 2;
    float scaleMarkSize = getResources().getDisplayMetrics().density * 10;
    int radius = mArcRadius + mNeedleDistance + mIncreaseCenterNeedle + 15;

    for (float progress = 0; progress <= mMax; progress += 0.2f) {
        float progressSweep = progress / mMax * mSweepAngle;
        int thumbAngle = (int) (mStartAngle + progressSweep + mRotation);

        float stopX = (float) (cx + (radius + scaleMarkSize) * Math.sin(Math.toRadians(thumbAngle)));
        float stopY = (float) (cy - (radius + scaleMarkSize) * Math.cos(Math.toRadians(thumbAngle)));

        canvas.drawCircle(stopX, stopY, mDotSize, mNeedleScalePaint);
    }
}

From source file:org.uva.itast.blended.omr.BufferedImageUtil.java

/**
 * Rotates 90, -90 deegrees/*from   ww w.  j av  a  2 s .  co  m*/
 * @param imageToRotate
 * @param degrees 90 or -90 rotation.
 * @return
 */
public static BufferedImage rotateImage(BufferedImage imageToRotate, float degrees) {
    if (degrees != 90.0 && degrees != -90.0)
        throw new IllegalArgumentException("Only implemented +90 and -90 rotation");

    BufferedImage rotatedImage = new BufferedImage(imageToRotate.getHeight(null), imageToRotate.getWidth(null),
            imageToRotate.getType());

    Graphics2D g2d = (Graphics2D) rotatedImage.getGraphics();
    g2d.rotate(Math.toRadians(degrees));
    g2d.drawImage(imageToRotate, 0, -rotatedImage.getWidth(null), null);

    return rotatedImage;
}

From source file:org.mixare.MixViewActivity.java

/**
 * Part of Android LifeCycle that gets called when "MixViewActivity" resumes.
 * <br/>//  www .  ja v  a 2s  .  c o m
 * Does:
 * - Acquire Screen Lock
 * - Refreshes Data and Downloads
 * - Initiate four Matrixes that holds user's rotation markerRenderer.
 * - Re-register Sensors. {@link android.hardware.SensorManager SensorManager}
 * - Re-register Location Manager. {@link org.mixare.mgr.location.LocationFinder LocationFinder}
 * - Switch on Download Thread. {@link org.mixare.mgr.downloader.DownloadManager DownloadManager}
 * - restart markerRenderer refresh Timer.
 * <br/>
 * {@inheritDoc}
 */
@Override
protected void onResume() {
    super.onResume();
    if (cubeView != null) {
        //mRenderer.start();
        cubeView.onResume();
    }
    mSensorManager.registerListener(cubeView, mOrienation, SensorManager.SENSOR_DELAY_NORMAL);

    try {
        killOnError();
        MixContext.setActualMixViewActivity(this);
        HttpTools.setContext(MixContext.getInstance());

        //repaint(); //repaint when requested
        getMarkerRenderer().doStart();
        getMarkerRenderer().clearEvents();
        MixContext.getInstance().getNotificationManager().setEnabled(true);
        refreshDownload();

        MixContext.getInstance().getDataSourceManager().refreshDataSources();

        float angleX, angleY;

        int marker_orientation = -90;

        int rotation = Compatibility.getRotation(this);

        // display text from left to right and keep it horizontal
        angleX = (float) Math.toRadians(marker_orientation);
        getMixViewData().getM1().set(1f, 0f, 0f, 0f, (float) Math.cos(angleX), (float) -Math.sin(angleX), 0f,
                (float) Math.sin(angleX), (float) Math.cos(angleX));
        angleX = (float) Math.toRadians(marker_orientation);
        angleY = (float) Math.toRadians(marker_orientation);
        if (rotation == 1) {
            getMixViewData().getM2().set(1f, 0f, 0f, 0f, (float) Math.cos(angleX), (float) -Math.sin(angleX),
                    0f, (float) Math.sin(angleX), (float) Math.cos(angleX));
            getMixViewData().getM3().set((float) Math.cos(angleY), 0f, (float) Math.sin(angleY), 0f, 1f, 0f,
                    (float) -Math.sin(angleY), 0f, (float) Math.cos(angleY));
        } else {
            getMixViewData().getM2().set((float) Math.cos(angleX), 0f, (float) Math.sin(angleX), 0f, 1f, 0f,
                    (float) -Math.sin(angleX), 0f, (float) Math.cos(angleX));
            getMixViewData().getM3().set(1f, 0f, 0f, 0f, (float) Math.cos(angleY), (float) -Math.sin(angleY),
                    0f, (float) Math.sin(angleY), (float) Math.cos(angleY));

        }

        getMixViewData().getM4().toIdentity();

        for (int i = 0; i < getMixViewData().getHistR().length; i++) {
            getMixViewData().getHistR()[i] = new Matrix();
        }

        getMixViewData()
                .addListSensors(getMixViewData().getSensorMgr().getSensorList(Sensor.TYPE_ACCELEROMETER));
        if (getMixViewData().getSensor(0).getType() == Sensor.TYPE_ACCELEROMETER) {
            getMixViewData().setSensorGrav(getMixViewData().getSensor(0));
        } //else report error (unsupported hardware)

        getMixViewData()
                .addListSensors(getMixViewData().getSensorMgr().getSensorList(Sensor.TYPE_MAGNETIC_FIELD));
        if (getMixViewData().getSensor(1).getType() == Sensor.TYPE_MAGNETIC_FIELD) {
            getMixViewData().setSensorMag(getMixViewData().getSensor(1));
        } //else report error (unsupported hardware)

        if (!getMixViewData().getSensorMgr().getSensorList(Sensor.TYPE_GYROSCOPE).isEmpty()) {
            getMixViewData()
                    .addListSensors(getMixViewData().getSensorMgr().getSensorList(Sensor.TYPE_GYROSCOPE));
            if (getMixViewData().getSensor(2).getType() == Sensor.TYPE_GYROSCOPE) {
                getMixViewData().setSensorGyro(getMixViewData().getSensor(2));
            }
            getMixViewData().getSensorMgr().registerListener(this, getMixViewData().getSensorGyro(),
                    SENSOR_DELAY_GAME);
        }

        getMixViewData().getSensorMgr().registerListener(this, getMixViewData().getSensorGrav(),
                SENSOR_DELAY_GAME);
        getMixViewData().getSensorMgr().registerListener(this, getMixViewData().getSensorMag(),
                SENSOR_DELAY_GAME);

        try {
            GeomagneticField gmf = MixContext.getInstance().getLocationFinder().getGeomagneticField();
            angleY = (float) Math.toRadians(-gmf.getDeclination());
            getMixViewData().getM4().set((float) Math.cos(angleY), 0f, (float) Math.sin(angleY), 0f, 1f, 0f,
                    (float) -Math.sin(angleY), 0f, (float) Math.cos(angleY));
        } catch (Exception ex) {
            doError(ex, GPS_ERROR);
        }

        if (!isNetworkAvailable()) {
            Log.d(Config.TAG, "no network");
            doError(null, NO_NETWORK_ERROR);
        } else {
            Log.d(Config.TAG, "network");
        }

        MixContext.getInstance().getDownloadManager().switchOn();
        MixContext.getInstance().getLocationFinder().switchOn();
    } catch (Exception ex) {
        doError(ex, GENERAL_ERROR);
        try {
            if (getMixViewData().getSensorMgr() != null) {
                getMixViewData().getSensorMgr().unregisterListener(this, getMixViewData().getSensorGrav());
                getMixViewData().getSensorMgr().unregisterListener(this, getMixViewData().getSensorMag());
                getMixViewData().getSensorMgr().unregisterListener(this, getMixViewData().getSensorGyro());
                getMixViewData().setSensorMgr(null);
            }

            if (MixContext.getInstance() != null) {
                MixContext.getInstance().getLocationFinder().switchOff();
                MixContext.getInstance().getDownloadManager().switchOff();
            }
        } catch (Exception ignore) {
        }
    } finally {
        //This does not conflict with registered sensors (sensorMag, sensorGrav)
        //This is a place holder to API returned listed of sensors, we registered
        //what we need, the rest is unnecessary.
        getMixViewData().clearAllSensors();
    }

    Log.d(Config.TAG, "resume");
    if (getMarkerRenderer() == null) {
        return;
    }
    if (getMarkerRenderer().isFrozen() && getMixViewData().getSearchNotificationTxt() == null) {
        getMixViewData().setSearchNotificationTxt(new TextView(this));
        getMixViewData().getSearchNotificationTxt().setWidth(getPaintScreen().getWidth());
        getMixViewData().getSearchNotificationTxt().setPadding(10, 2, 0, 0);
        getMixViewData().getSearchNotificationTxt().setText(getString(R.string.search_active_1) + " "
                + DataSourceList.getDataSourcesStringList() + getString(R.string.search_active_2));
        ;
        getMixViewData().getSearchNotificationTxt().setBackgroundColor(Color.DKGRAY);
        getMixViewData().getSearchNotificationTxt().setTextColor(Color.WHITE);

        getMixViewData().getSearchNotificationTxt().setOnTouchListener(this);
        addContentView(getMixViewData().getSearchNotificationTxt(),
                new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    } else if (!getMarkerRenderer().isFrozen() && getMixViewData().getSearchNotificationTxt() != null) {
        getMixViewData().getSearchNotificationTxt().setVisibility(View.GONE);
        getMixViewData().setSearchNotificationTxt(null);
    }
}

From source file:convcao.com.agent.ConvcaoNeptusInteraction.java

private double[] getBeamMeasurement(EstimatedState state, Distance d) {
    double[] ret = new double[4];

    // H = Ca + Cb
    double varH = d.getValue();
    double varCa = Math.cos(DVL_ANGLE) * varH;
    double varCb = Math.sin(DVL_ANGLE) * varH;

    String beamId = d.getEntityName();

    if (beamId == null)
        beamId = "DVL Filtered";

    double tide = 0;

    if (subtractTide) {
        try {// w  w w .  j av  a2  s.  c o  m
            tide = TidePredictionFactory.getTideLevel(state.getDate());
        } catch (Exception e) {
            NeptusLog.pub().warn(e);
        }
    }

    double depth = state.getDepth();
    double heading = state.getPsi();

    /* DVL Beams       
     *   (0) | 
     *       |
     *(3) ---+--- (1)
     *       |
     *       | (2)         
     */

    switch (beamId) {
    // pointing down
    case "DVL Filtered":
        varCb = 0;
        varCa = varH;
        break;
    case "DVL Beam 1":
        heading += Math.toRadians(90);
        break;
    case "DVL Beam 2":
        heading += Math.toRadians(180);
        break;
    case "DVL Beam 3":
        heading += Math.toRadians(270);
        break;
    default:
        break;
    }

    LocationType ground = IMCUtils.getLocation(state);
    ground.setOffsetDistance(varCb);
    ground.setAzimuth(Math.toDegrees(heading));
    ground.convertToAbsoluteLatLonDepth();

    double c[] = coords.convert(ground);
    ret[0] = c[0];
    ret[1] = c[1];
    ret[2] = state.getDepth();
    ret[3] = varCa + depth - tide;

    return ret;
}

From source file:com.jillesvangurp.geo.GeoGeometry.java

private static double lengthOfLongitudeDegreeAtLatitude(final double latitude) {
    final double latitudeInRadians = Math.toRadians(latitude);
    return Math.cos(latitudeInRadians) * EARTH_CIRCUMFERENCE_METERS / 360.0;
}

From source file:cz.yetanotherview.webcamviewer.app.MainActivity.java

private void showSortDialog() {

    int whatMarkToCheck = 0;
    if (sortOrder.contains("position")) {
        whatMarkToCheck = 0;//from w  ww. jav a2s  . co  m
    } else if (sortOrder.contains(" ) ASC")) {
        whatMarkToCheck = 1;
    } else if (sortOrder.contains(" ) DESC")) {
        whatMarkToCheck = 2;
    } else if (sortOrder.contains("created_at ASC")) {
        whatMarkToCheck = 3;
    } else if (sortOrder.contains("created_at DESC")) {
        whatMarkToCheck = 4;
    } else if (sortOrder.contains("UNICODE ASC")) {
        whatMarkToCheck = 5;
    } else if (sortOrder.contains("UNICODE DESC")) {
        whatMarkToCheck = 6;
    }

    materialDialog = new MaterialDialog.Builder(this).title(R.string.action_sort).items(R.array.sort_values)
            .itemsCallbackSingleChoice(whatMarkToCheck, new MaterialDialog.ListCallbackSingleChoice() {
                @Override
                public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {

                    KnownLocation knownLocation;
                    Double fudge;
                    switch (which) {
                    case 0:
                        sortOrder = "position";
                        break;
                    case 1:
                        knownLocation = Utils.getLastKnownLocation(MainActivity.this);
                        fudge = Math.pow(Math.cos(Math.toRadians(knownLocation.getLatitude())), 2);

                        sortOrder = "((" + knownLocation.getLatitude() + " - latitude) * ("
                                + knownLocation.getLatitude() + " - latitude) + ("
                                + knownLocation.getLongitude() + " - longitude) * ("
                                + knownLocation.getLongitude() + " - longitude) * " + fudge + " ) ASC";
                        if (knownLocation.isNotDetected()) {
                            new LocationWarningDialog().show(getFragmentManager(), "LocationWarningDialog");
                        }
                        break;
                    case 2:
                        knownLocation = Utils.getLastKnownLocation(MainActivity.this);
                        fudge = Math.pow(Math.cos(Math.toRadians(knownLocation.getLatitude())), 2);

                        sortOrder = "((" + knownLocation.getLatitude() + " - latitude) * ("
                                + knownLocation.getLatitude() + " - latitude) + ("
                                + knownLocation.getLongitude() + " - longitude) * ("
                                + knownLocation.getLongitude() + " - longitude) * " + fudge + " ) DESC";
                        if (knownLocation.isNotDetected()) {
                            new LocationWarningDialog().show(getFragmentManager(), "LocationWarningDialog");
                        }
                        break;
                    case 3:
                        sortOrder = "created_at ASC";
                        break;
                    case 4:
                        sortOrder = "created_at DESC";
                        break;
                    case 5:
                        sortOrder = "webcam_name COLLATE UNICODE ASC";
                        break;
                    case 6:
                        sortOrder = "webcam_name COLLATE UNICODE DESC";
                        break;
                    default:
                        break;
                    }
                    //reInitializeRecyclerViewAdapter();
                    saveToPref();

                    return true;
                }
            }).negativeText(R.string.close).show();
}

From source file:org.interpss.mapper.bean.aclf.AclfBean2NetMapper.java

private void setPsXfrData(AclfBranchBean branchBean, AclfBranch branch, AclfNetwork aclfNet) {
    // control/adjustment
    if (branchBean.psXfrTapControl != null) {
        PsXfrTapControlBean tcb = branchBean.psXfrTapControl;
        try {/* w w w.ja  v  a2s . com*/
            if (tcb.controlType == TapControlTypeBean.Point_Control) {
                PSXfrPControl psxfr = CoreObjectFactory.createPSXfrPControl(branch,
                        AdjControlType.POINT_CONTROL);
                psxfr.setStatus(tcb.status == 1 ? true : false);
                psxfr.setPSpecified(tcb.desiredControlTarget);
                psxfr.setAngLimit(new LimitType(Math.toRadians(tcb.maxAngle), Math.toRadians(tcb.minAngle)));
                psxfr.setControlOnFromSide(tcb.controlOnFromSide);
                psxfr.setMeteredOnFromSide(tcb.measuredOnFromSide);
                psxfr.setFlowFrom2To(tcb.flowFrom2To);

            } else if (tcb.controlType == TapControlTypeBean.Range_Control) { // range control
                PSXfrPControl psxfr = CoreObjectFactory.createPSXfrPControl(branch,
                        AdjControlType.RANGE_CONTROL);
                psxfr.setStatus(tcb.status == 1 ? true : false);
                psxfr.setControlRange(new LimitType(tcb.upperLimit, tcb.lowerLimit));
                psxfr.setPSpecified(tcb.desiredControlTarget);
                psxfr.setAngLimit(new LimitType(Math.toRadians(tcb.maxAngle), Math.toRadians(tcb.minAngle)));
                psxfr.setControlOnFromSide(tcb.controlOnFromSide);
                psxfr.setMeteredOnFromSide(tcb.measuredOnFromSide);
                psxfr.setFlowFrom2To(tcb.flowFrom2To);
            }
        } catch (InterpssException e) {
            ipssLogger.severe("Error in mapping PsXfr tap control data, " + e.toString());
        }

    }
}

From source file:com.sitewhere.server.device.DefaultDeviceModelInitializer.java

/**
 * Create device locations in a path near the main zone.
 * /*from w  ww  .  j a  v  a2s  . c om*/
 * @param assignment
 * @param start
 * @return
 * @throws SiteWhereException
 */
protected List<IDeviceLocation> createDeviceLocations(IDeviceAssignment assignment, Date date)
        throws SiteWhereException {
    long current = date.getTime();
    Polygon zone = GeoUtils.createPolygonForLocations(zoneLocations);
    Point centroid = zone.getCentroid();

    // Calculate length of steps between locations based on bounding circle.
    MinimumBoundingCircle circle = new MinimumBoundingCircle(zone);
    double step = circle.getRadius() / 10;

    double cx = centroid.getX();
    double cy = centroid.getY();
    double deltaX = (Math.sqrt(Math.random()) * step * 2) - step;
    double deltaY = (Math.sqrt(Math.random()) * step * 2) - step;

    // Used to rotate deltas to turn path and stay inside polygon.
    AffineTransformation xform = new AffineTransformation();
    xform.rotate(Math.toRadians(22.5));

    List<IDeviceLocation> results = new ArrayList<IDeviceLocation>();
    GeometryFactory factory = new GeometryFactory();
    DeviceLocationCreateRequest lastLoc = null;
    for (int x = 0; x < LOCATIONS_PER_ASSIGNMENT; x++) {
        boolean foundNext = false;

        // Add a little randomness to path.
        double waver = ((Math.random() * 20) - 10.0);
        AffineTransformation waverXform = new AffineTransformation();
        waverXform.rotate(Math.toRadians(waver));
        Coordinate waverDelta = new Coordinate(deltaX, deltaY);
        waverXform.transform(waverDelta, waverDelta);
        deltaX = waverDelta.x;
        deltaY = waverDelta.y;

        while (!foundNext) {
            Coordinate start = new Coordinate(cx, cy);
            Coordinate end = new Coordinate(cx + deltaX, cy + deltaY);
            Coordinate[] lineCoords = { start, end };
            LineString line = factory.createLineString(lineCoords);
            if (zone.contains(line)) {
                DeviceLocationCreateRequest request = new DeviceLocationCreateRequest();
                request.setLatitude(end.y);
                request.setLongitude(end.x);
                request.setElevation(0.0);
                request.setEventDate(new Date(current));
                IDeviceLocation created = getDeviceManagement().addDeviceLocation(assignment, request);
                lastLoc = request;
                results.add(created);

                cx = cx + deltaX;
                cy = cy + deltaY;
                foundNext = true;
            } else {
                // Rotate deltas and try again.
                Coordinate delta = new Coordinate(deltaX, deltaY);
                xform.transform(delta, delta);
                deltaX = delta.x;
                deltaY = delta.y;
            }
        }
        current += 30000;
    }
    LOGGER.info(PREFIX_CREATE_EVENTS + " " + results.size() + " locations. ");

    // Update assignment state.
    if (lastLoc != null) {
        DeviceEventBatch batch = new DeviceEventBatch();
        batch.getLocations().add(lastLoc);
        getDeviceManagement().updateDeviceAssignmentState(assignment.getToken(), batch);
    }
    return results;
}

From source file:com.skumar.flexibleciruclarseekbar.CircularSeekBar.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

    final int height = getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec);
    final int width = getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec);
    final int min = Math.min(width, height);
    float top = 0;
    float left = 0;

    mTranslateX = (int) (width * 0.5f);
    mTranslateY = (int) (height * 0.5f);

    mArcDiameter = min - getPaddingLeft() - mNeedleDistance - mIncreaseCenterNeedle - 5;
    mArcRadius = mArcDiameter / 2;/*from  w  ww.j av  a  2s  .  c  om*/
    top = height / 2 - (mArcDiameter / 2);
    left = width / 2 - (mArcDiameter / 2);
    mArcRect.set(left, top, left + mArcDiameter, top + mArcDiameter);

    int arcStart = (int) mProgressSweep + mStartAngle + mRotation + 90;
    mThumbXPos = (int) (mArcRadius * Math.cos(Math.toRadians(arcStart)));
    mThumbYPos = (int) (mArcRadius * Math.sin(Math.toRadians(arcStart)));

    setTouchInSide(mTouchInside);

    mPopup.measure(-2, -2);
    mPopup.layout(0, 0, mPopup.getMeasuredHeight(), mPopup.getMeasuredWidth());
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

From source file:pt.lsts.neptus.mra.importers.deltat.DeltaTParser.java

@Override
public BathymetrySwath nextSwath(double prob) {

    if (position == null)
        position = new CorrectedPosition(source);

    try {//from  w ww.jav a  2  s  .  c  om
        if (curPos >= channel.size()) {
            //                cleanupResultOutputFile();
            return null;
        }

        BathymetryPoint data[];
        realNumberOfBeams = 0;

        buf = channel.map(MapMode.READ_ONLY, curPos, 256);
        header = new DeltaTHeader();
        header.parse(buf);

        hasIntensity = header.hasIntensity;
        //            if (hasIntensity)
        //                NeptusLog.pub().info("LOG has intensity");
        //            else
        //                NeptusLog.pub().info("Log doesn't have intensity");

        // Parse and process data ( no need to create another structure for this )
        if (header.hasIntensity)
            buf = channel.map(MapMode.READ_ONLY, curPos + 256, header.numBeams * 4);
        else
            buf = channel.map(MapMode.READ_ONLY, curPos + 256, header.numBeams * 2);

        data = new BathymetryPoint[header.numBeams];

        long timestamp = header.timestamp + MRAProperties.timestampMultibeamIncrement;

        boolean poseFromCorrected = true;
        SystemPositionAndAttitude pose = position.getPosition(timestamp / 1000.0);
        if (pose == null) {

            poseFromCorrected = false;
            pose = new SystemPositionAndAttitude();
            LocationType loc = new LocationType();
            loc.setLatitudeDegs(CoordinateUtil.latFrom83PFormatWorker(header.gnssShipPosLat));
            loc.setLongitudeDegs(CoordinateUtil.lonFrom83PFormatWorker(header.gnssShipPosLon));
            loc.setAbsoluteDepth(-1);
            pose.setPosition(loc);

            pose.setTime(timestamp);
            pose.setAltitude(header.altitude);

            pose.setRoll(Math.toRadians(header.rollAngleDegreesOrientModule));
            pose.setPitch(Math.toRadians(header.pitchAngleDegreesOrientModule));
            pose.setYaw(Math.toRadians(header.headingAngleDegreesOrientModule));

            NeptusLog.pub().warn("No position found on navigation, using partial data from Sonar");
        }

        boolean doSpeedCorrection = MRAProperties.soundSpeedCorrection;

        if (generateProcessReport) {
            recordMsgln();
            recordMsgln("% Swath type & version : " + header.fileType + ", " + header.fileVersion);
            recordMsgln("% Swath time           : "
                    + DateTimeUtil.dateTimeFileNameFormatterMillis.format(new Date(timestamp)));
            recordMsgln("% Swath position       : " + pose.getPosition().toString().replaceAll("\n", " ")
                    + "m depth  :: " + MathMiscUtils.round(pose.getAltitude(), 2) + "m altitude"
                    + (poseFromCorrected ? " from corrected position" : " from data"));
            recordMsgln("% Swath attitude       : R" + MathMiscUtils.round(Math.toDegrees(pose.getRoll()), 1)
                    + "\u00B0 P" + MathMiscUtils.round(Math.toDegrees(pose.getPitch()), 1) + "\u00B0 Y"
                    + MathMiscUtils.round(Math.toDegrees(pose.getYaw()), 1) + "\u00B0");
            recordMsgln("% Orient. module       : R"
                    + MathMiscUtils.round(Math.toDegrees(header.rollAngleDegreesOrientModule), 1) + "\u00B0 P"
                    + MathMiscUtils.round(Math.toDegrees(header.pitchAngleDegreesOrientModule), 1) + "\u00B0 H"
                    + MathMiscUtils.round(Math.toDegrees(header.headingAngleDegreesOrientModule), 1)
                    + "\u00B0");

            recordMsgln("% Ship Course          : " + header.gnssShipCourse + "\u00B0");
            recordMsgln("% Ship Lat/Lon         : " + header.gnssShipPosLat + "  " + header.gnssShipPosLon);
            recordMsgln("% Sonar XYZ offsets    : " + header.sonarXOffset + "m, " + header.sonarYOffset + "m, "
                    + header.sonarZOffset + "m");

            recordMsgln("% Angle start/increment: " + header.startAngle + "\u00B0" + ", "
                    + header.angleIncrement + "\u00B0");
            recordMsgln("% Beams                : " + header.numBeams);
            recordMsgln("% Samples per beam     : " + header.samplesPerBeam);
            recordMsgln("% Number of pings avg  : " + header.numberOfPingsAveraged);
            recordMsgln("% Sample rate high/std : " + (header.sampleRateHigh ? "high" : "std")
                    + " [std(1 in 500)/high (1 in 5000)]");
            recordMsgln("% Range                : " + header.range + "m");
            recordMsgln("% Range resolution     : " + header.rangeResolution + "mm");
            recordMsgln("% Sonar Freq.          : " + header.sonarFreqKHz + "kHz");
            recordMsgln("% Pulse length         : " + header.pulseLength + "\u03BCs");
            recordMsg("% 1/PRF                : " + header.pulseRepetingRate + "ms");
            recordMsgln(
                    " (" + MathMiscUtils.parseToEngineeringNotation(1. / (header.pulseRepetingRate / 1E3), 1)
                            + "Hz)");
            recordMsgln("% Ping number          : " + header.pingNumber);
            recordMsgln("% Sector size          : " + header.sectorSize + "\u00B0 :: "
                    + (header.angleIncrement * header.numBeams) + "\u00B0 calculated");
            recordMsgln("% Speed                : " + MathMiscUtils.round(header.speed, 1) + "m/s");
            recordMsgln("% Sound speed          : " + header.soundVelocity + "m/s"
                    + (doSpeedCorrection ? "" : " (1500m/s used for calculation)"));
            recordMsgln("% Roll correction      : " + (header.dataIsCorrectedForRoll ? "yes" : "no"));
            recordMsgln("% RayBending correction: " + (header.dataIsCorrectedForRayBending ? "yes" : "no"));
            recordMsgln("% Op overlap mode      : " + (header.sonarIsOperatingInOverlappedMode ? "yes" : "no"));
            recordMsgln("% Altitude             : " + header.altitude + "m");
            recordMsgln("% ---------------------");
        }

        StringBuilder rangesStr = new StringBuilder();
        StringBuilder heightStr = new StringBuilder();
        StringBuilder intensityStr = new StringBuilder();
        StringBuilder oxStr = new StringBuilder();
        StringBuilder oyStr = new StringBuilder();
        StringBuilder deltasStr = new StringBuilder();
        float prevX = Float.NaN;
        float prevY = Float.NaN;

        for (int c = 0; c < header.numBeams; c++) {
            double range = buf.getShort(c * 2) * (header.rangeResolution / 1000.0); // rangeResolution in mm 

            if (range == 0.0 || Math.random() > prob) {
                if (generateProcessReport) {
                    if (range != 0) {
                        recordMsgln("% Skip swath beam " + c + " range=" + range);
                    } else {
                        rangesStr.append(" " + MathMiscUtils.round(range, 3));
                        heightStr.append(" " + Double.NaN);
                        intensityStr.append(" " + Double.NaN);
                        oxStr.append(" " + Double.NaN);
                        oyStr.append(" " + Double.NaN);
                        deltasStr.append(" " + Float.NaN);
                        prevX = Float.NaN;
                        prevY = Float.NaN;
                    }
                }
                continue;
            }

            if (doSpeedCorrection && header.soundVelocity != 1500f) {
                range = range * header.soundVelocity / 1500f;
            }

            if (generateProcessReport) {
                rangesStr.append(" " + MathMiscUtils.round(range, 3));
            }

            double angle = header.startAngle + header.angleIncrement * c;
            float height = (float) (range * Math.cos(Math.toRadians(angle)) + pose.getPosition().getDepth());

            double x = range * Math.sin(Math.toRadians(angle));
            double yawAngle = -pose.getYaw();

            float ox = (float) (x * Math.sin(yawAngle));
            float oy = (float) (x * Math.cos(yawAngle));

            if (header.hasIntensity) {
                short intensity = buf.getShort(480 + (c * 2) - 1); // sometimes there's a return = 0
                int intensityInt = 0xffff & intensity;
                data[realNumberOfBeams] = new BathymetryPoint(ox, oy, height, intensityInt);
                data[realNumberOfBeams].intensityMaxValue = 65535;
                if (generateProcessReport)
                    intensityStr.append(" " + intensityInt);
            } else {
                data[realNumberOfBeams] = new BathymetryPoint(ox, oy, height);
                data[realNumberOfBeams].intensityMaxValue = 65535;
                if (generateProcessReport)
                    intensityStr.append(" " + Double.NaN);
            }
            realNumberOfBeams++;

            if (generateProcessReport) {
                heightStr.append(" " + MathMiscUtils.round(height, 3));
                oxStr.append(" " + MathMiscUtils.round(ox, 3));
                oyStr.append(" " + MathMiscUtils.round(oy, 3));
                if (!Float.isNaN(prevX) && !Float.isNaN(prevY)) {
                    float delta = (float) Math.sqrt((ox - prevX) * (ox - prevX) + (oy - prevY) * (oy - prevY));
                    deltasStr.append(" " + MathMiscUtils.round(delta, 3));
                } else {
                    deltasStr.append(" " + Float.NaN);
                }
                prevX = ox;
                prevY = oy;
            }
        }

        if (generateProcessReport) {
            recordMsgln("% Ranges:");
            recordMsgln(rangesStr.toString());
            recordMsgln("% Heights:");
            recordMsgln(heightStr.toString());
            recordMsgln("% Intensities:");
            recordMsgln(intensityStr.toString());
            recordMsgln("% Offsets X:");
            recordMsgln(oxStr.toString());
            recordMsgln("% Offsets Y:");
            recordMsgln(oyStr.toString());
            recordMsgln("% Deltas:");
            recordMsgln(deltasStr.toString());
            recordMsgln("% Number of beams vs read: " + header.numBeams + " vs " + realNumberOfBeams);
        }

        curPos += header.numBytes; // Advance current position

        BathymetrySwath swath = new BathymetrySwath(header.timestamp, pose, data);
        swath.setNumBeams(realNumberOfBeams);

        return swath;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}