Example usage for java.lang Math cos

List of usage examples for java.lang Math cos

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static double cos(double a) 

Source Link

Document

Returns the trigonometric cosine of an angle.

Usage

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:gdsc.smlm.ij.plugins.BenchmarkFilterAnalysis.java

private List<MemoryPeakResults> readResults() {
    if (resultsList == null || lastId != BenchmarkSpotFit.fitResultsId || lastRank != rerankBySignal
            || lastPartialMatchDistance != partialMatchDistance
            || lastUpperMatchDistance != upperMatchDistance) {
        lastId = BenchmarkSpotFit.fitResultsId;
        lastRank = rerankBySignal;/*from  w  ww. ja v  a 2s . co  m*/
        lastUpperMatchDistance = upperMatchDistance;
        lastPartialMatchDistance = partialMatchDistance;
        resultsList = new LinkedList<MemoryPeakResults>();
        depthStats = new StoredDataStatistics();
        depthFitStats = new StoredDataStatistics();

        final double fuzzyMax = BenchmarkSpotFit.distanceInPixels * upperMatchDistance / 100.0;
        final double fuzzyMin = BenchmarkSpotFit.distanceInPixels * partialMatchDistance / 100.0;
        final double fuzzyRange = fuzzyMax - fuzzyMin;
        resultsPrefix3 = "\t" + Utils.rounded(fuzzyMin * simulationParameters.a) + "\t"
                + Utils.rounded(fuzzyMax * simulationParameters.a);

        // Normalise the matches so the fuzzy weighting sums to the original true positive count 
        //int tp = 0;
        //double sum = 0;

        MemoryPeakResults r = new MemoryPeakResults();
        Calibration cal = new Calibration(simulationParameters.a, simulationParameters.gain, 100);
        cal.bias = simulationParameters.bias;
        cal.emCCD = simulationParameters.emCCD;
        cal.readNoise = simulationParameters.readNoise;
        r.setCalibration(cal);
        // Set the configuration used for fitting
        r.setConfiguration(XmlUtils.toXML(BenchmarkSpotFit.fitConfig));

        for (Entry<Integer, FilterCandidates> entry : BenchmarkSpotFit.fitResults.entrySet()) {
            final int peak = entry.getKey().intValue();
            final FilterCandidates result = entry.getValue();
            depthStats.add(result.zPosition);

            // Results are in order of candidate ranking.
            int[] indices = Utils.newArray(result.fitResult.length, 0, 1);
            if (rerankBySignal) {
                // Change to signal intensity.
                double[] score = new double[result.fitResult.length];
                for (int i = 0; i < result.fitResult.length; i++) {
                    final FitResult fitResult = result.fitResult[i];
                    if (fitResult.getStatus() == FitStatus.OK) {
                        score[i] = fitResult.getParameters()[Gaussian2DFunction.SIGNAL];
                    }
                }
                Sort.sort(indices, score);
            }

            // Data about the match is stored in small arrays of size equal to the number of matches.
            // Create an array holding the full index position corresponding to each match.
            int[] positionIndex = new int[result.dMatch.length];
            int count = 0;
            for (int i = 0; i < result.fitMatch.length; i++) {
                if (result.fitMatch[i])
                    positionIndex[count++] = i;
            }

            for (int i = 0; i < result.fitResult.length; i++) {
                final int index = indices[i];
                final FitResult fitResult = result.fitResult[index];
                if (fitResult.getStatus() == FitStatus.OK) {
                    // Assume we are not fitting doublets and the fit result will have 1 peak
                    final float[] params = Utils.toFloat(fitResult.getParameters());
                    // To allow the shift filter to function the X/Y position coordinates must be relative
                    final double[] initial = fitResult.getInitialParameters();
                    params[Gaussian2DFunction.X_POSITION] -= initial[Gaussian2DFunction.X_POSITION];
                    params[Gaussian2DFunction.Y_POSITION] -= initial[Gaussian2DFunction.Y_POSITION];
                    // These will be incorrect due to the relative adjustment above...
                    final int origX = (int) params[Gaussian2DFunction.X_POSITION];
                    final int origY = (int) params[Gaussian2DFunction.Y_POSITION];

                    // Binary classification uses a score of 1 (match) or 0 (no match)
                    // Fuzzy classification uses a score of 1 (match) or 0 (no match), or >0 <1 (partial match)
                    float score = 0;
                    double depth = 0;
                    if (result.fitMatch[index]) {
                        int position = getPosition(positionIndex, index);
                        double distance = result.dMatch[position];

                        // Store depth of matches for later analysis
                        depth = result.zMatch[position];

                        if (distance <= fuzzyMax) {
                            depthFitStats.add(depth);
                            if (distance <= fuzzyMin) {
                                score = 1;
                            } else {
                                // Interpolate from the minimum to the maximum match distance:
                                // Linear 
                                //score = (float) ((fuzzyMax - result.d[index]) / fuzzyRange);
                                // Cosine
                                score = (float) (0.5
                                        * (1 + Math.cos(((distance - fuzzyMin) / fuzzyRange) * Math.PI)));
                            }
                            //tp++;
                            //sum += score;
                        }
                    }

                    // Use a custom peak result so that the depth can be stored.
                    r.add(new DepthPeakResult(peak, origX, origY, score, fitResult.getError(), result.noise,
                            params, depth));
                }
            }
        }

        if (r.size() > 0) {
            // Normalise the fuzzy weighting
            //final double w = tp / sum;
            //for (PeakResult result : r.getResults())
            //{
            //   if (result.origValue != 0)
            //      result.origValue *= w;
            //}         
            resultsList.add(r);
        }
    }
    return resultsList;
}

From source file:interfaceTisseoWS.ST3.java

public double getDistance(double x1, double y1, double x2, double y2) {
    double d2r = Math.PI / 180;

    try {//from  w  w w. j a v  a 2 s.  c  o m
        double dlong = (x2 - x1) * d2r;
        double dlat = (y2 - y1) * d2r;
        double a = Math.pow(Math.sin(dlat / 2.0), 2)
                + Math.cos(y1 * d2r) * Math.cos(y2 * d2r) * Math.pow(Math.sin(dlong / 2.0), 2);
        double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
        double d = 6367 * c;

        return d;

    } catch (Exception e) {
    }
    return -1.0;
}

From source file:com.alvermont.terraj.planet.PlanetGen.java

/**
 * Carries out the remaining levels of terrain generation, recursivel
 * until the last level is reached. Returns the height of the planet
 * at this point// w ww  .  ja v a 2 s. c  o  m
 *
 * @param a Altitude of vertex 1
 * @param b Altitude of vertex 2
 * @param c Altitude of vertex 3
 * @param d Altitude of vertex 4
 * @param as Seed of vertex 1
 * @param bs Seed of vertex 2
 * @param cs Seed of vertex 3
 * @param ds Seed of vertex 4
 * @param ax Vertex 1 X coordinate
 * @param ay Vertex 1 Y coordinate
 * @param az Vertex 1 Z coordinate
 * @param bx Vertex 2 X coordinate
 * @param by Vertex 2 Y coordinate
 * @param bz Vertex 2 Z coordinate
 * @param cx Vertex 3 X coordinate
 * @param cy Vertex 3 Y coordinate
 * @param cz Vertex 3 Z coordinate
 * @param dx Vertex 4 X coordinate
 * @param dy Vertex 4 Y coordinate
 * @param dz Vertex 4 Z coordinate
 * @param x Goal point X coordinate
 * @param y Goal point Y coordinate
 * @param z Goal point Z coordinate
 * @param level Number of remaining levels
 * @return The altitude of the planet after recursive subdivision
 */
double planet(double a, double b, double c, double d, double as, double bs, double cs, double ds, double ax,
        double ay, double az, double bx, double by, double bz, double cx, double cy, double cz, double dx,
        double dy, double dz, double x, double y, double z, int level) {
    double abx;
    double aby;
    double abz;
    double acx;
    double acy;
    double acz;
    double adx;
    double ady;
    double adz;
    double bcx;
    double bcy;
    double bcz;
    double bdx;
    double bdy;
    double bdz;
    double cdx;
    double cdy;
    double cdz;
    double lab;
    double lac;
    double lad;
    double lbc;
    double lbd;
    double lcd;
    double ex;
    double ey;
    double ez;
    double e;
    double es;
    double es1;
    double es2;
    double es3;
    double eax;
    double eay;
    double eaz;
    double epx;
    double epy;
    double epz;
    double ecx;
    double ecy;
    double ecz;
    double edx;
    double edy;
    double edz;
    double x1;
    double y1;
    double z1;
    double x2;
    double y2;
    double z2;
    double l1;
    double tmp;

    if (level > 0) {
        if (level == 11) {
            this.ssa = a;
            this.ssb = b;
            this.ssc = c;
            this.ssd = d;
            this.ssas = as;
            this.ssbs = bs;
            this.sscs = cs;
            this.ssds = ds;
            this.ssax = ax;
            this.ssay = ay;
            this.ssaz = az;
            this.ssbx = bx;
            this.ssby = by;
            this.ssbz = bz;
            this.sscx = cx;
            this.sscy = cy;
            this.sscz = cz;
            this.ssdx = dx;
            this.ssdy = dy;
            this.ssdz = dz;
        }

        abx = ax - bx;
        aby = ay - by;
        abz = az - bz;
        acx = ax - cx;
        acy = ay - cy;
        acz = az - cz;
        lab = (abx * abx) + (aby * aby) + (abz * abz);
        lac = (acx * acx) + (acy * acy) + (acz * acz);

        if (lab < lac) {
            return (planet(a, c, b, d, as, cs, bs, ds, ax, ay, az, cx, cy, cz, bx, by, bz, dx, dy, dz, x, y, z,
                    level));
        } else {
            adx = ax - dx;
            ady = ay - dy;
            adz = az - dz;
            lad = (adx * adx) + (ady * ady) + (adz * adz);

            if (lab < lad) {
                return (planet(a, d, b, c, as, ds, bs, cs, ax, ay, az, dx, dy, dz, bx, by, bz, cx, cy, cz, x, y,
                        z, level));
            } else {
                bcx = bx - cx;
                bcy = by - cy;
                bcz = bz - cz;
                lbc = (bcx * bcx) + (bcy * bcy) + (bcz * bcz);

                if (lab < lbc) {
                    return (planet(b, c, a, d, bs, cs, as, ds, bx, by, bz, cx, cy, cz, ax, ay, az, dx, dy, dz,
                            x, y, z, level));
                } else {
                    bdx = bx - dx;
                    bdy = by - dy;
                    bdz = bz - dz;
                    lbd = (bdx * bdx) + (bdy * bdy) + (bdz * bdz);

                    if (lab < lbd) {
                        return (planet(b, d, a, c, bs, ds, as, cs, bx, by, bz, dx, dy, dz, ax, ay, az, cx, cy,
                                cz, x, y, z, level));
                    } else {
                        cdx = cx - dx;
                        cdy = cy - dy;
                        cdz = cz - dz;
                        lcd = (cdx * cdx) + (cdy * cdy) + (cdz * cdz);

                        if (lab < lcd) {
                            return (planet(c, d, a, b, cs, ds, as, bs, cx, cy, cz, dx, dy, dz, ax, ay, az, bx,
                                    by, bz, x, y, z, level));
                        } else {
                            es = rand2(as, bs);
                            es1 = rand2(es, es);
                            es2 = 0.5 + (0.1 * rand2(es1, es1));
                            es3 = 1.0 - es2;

                            if (ax == bx) { /* very unlikely to ever happen */
                                ex = (0.5 * ax) + (0.5 * bx);
                                ey = (0.5 * ay) + (0.5 * by);
                                ez = (0.5 * az) + (0.5 * bz);
                            } else if (ax < bx) {
                                ex = (es2 * ax) + (es3 * bx);
                                ey = (es2 * ay) + (es3 * by);
                                ez = (es2 * az) + (es3 * bz);
                            } else {
                                ex = (es3 * ax) + (es2 * bx);
                                ey = (es3 * ay) + (es2 * by);
                                ez = (es3 * az) + (es2 * bz);
                            }

                            if (lab > 1.0) {
                                lab = Math.pow(lab, 0.75);
                            }

                            e = (0.5 * (a + b)) + (es * dd1 * Math.abs(a - b))
                                    + (es1 * dd2 * Math.pow(lab, pow));
                            eax = ax - ex;
                            eay = ay - ey;
                            eaz = az - ez;
                            epx = x - ex;
                            epy = y - ey;
                            epz = z - ez;
                            ecx = cx - ex;
                            ecy = cy - ey;
                            ecz = cz - ez;
                            edx = dx - ex;
                            edy = dy - ey;
                            edz = dz - ez;

                            if (((((eax * ecy * edz) + (eay * ecz * edx) + (eaz * ecx * edy))
                                    - (eaz * ecy * edx) - (eay * ecx * edz) - (eax * ecz * edy))
                                    * (((epx * ecy * edz) + (epy * ecz * edx) + (epz * ecx * edy))
                                            - (epz * ecy * edx) - (epy * ecx * edz)
                                            - (epx * ecz * edy))) > 0.0) {
                                return (planet(c, d, a, e, cs, ds, as, es, cx, cy, cz, dx, dy, dz, ax, ay, az,
                                        ex, ey, ez, x, y, z, level - 1));
                            } else {
                                return (planet(c, d, b, e, cs, ds, bs, es, cx, cy, cz, dx, dy, dz, bx, by, bz,
                                        ex, ey, ez, x, y, z, level - 1));
                            }
                        }
                    }
                }
            }
        }
    } else {
        if (this.doShade) {
            x1 = 0.25 * (ax + bx + cx + dx);
            x1 = (a * (x1 - ax)) + (b * (x1 - bx)) + (c * (x1 - cx)) + (d * (x1 - dx));
            y1 = 0.25 * (ay + by + cy + dy);
            y1 = (a * (y1 - ay)) + (b * (y1 - by)) + (c * (y1 - cy)) + (d * (y1 - dy));
            z1 = 0.25 * (az + bz + cz + dz);
            z1 = (a * (z1 - az)) + (b * (z1 - bz)) + (c * (z1 - cz)) + (d * (z1 - dz));
            l1 = Math.sqrt((x1 * x1) + (y1 * y1) + (z1 * z1));

            if (l1 == 0.0) {
                l1 = 1.0;
            }

            tmp = Math.sqrt(1.0 - (y * y));

            if (tmp < 0.0001) {
                tmp = 0.0001;
            }

            x2 = (x * x1) + (y * y1) + (z * z1);
            y2 = (((-x * y) / tmp * x1) + (tmp * y1)) - ((z * y) / tmp * z1);
            z2 = (-z / tmp * x1) + (x / tmp * z1);
            shade = (short) ((((-Math.sin((Math.PI * this.shadeAngle) / 180.0) * y2)
                    - (Math.cos((Math.PI * shadeAngle) / 180.0) * z2)) / l1 * 48.0) + 128.0);

            if (this.shade < 10) {
                this.shade = 10;
            }

            if (this.shade > 255) {
                this.shade = 255;
            }
        }

        return ((a + b + c + d) / 4);
    }
}

From source file:net.exclaimindustries.geohashdroid.util.KnownLocation.java

@NonNull
private Bitmap buildMarkerBitmap(@NonNull Context c) {
    // Oh, this is going to be FUN.
    int dim = c.getResources().getDimensionPixelSize(R.dimen.known_location_marker_canvas_size);
    float radius = c.getResources().getDimension(R.dimen.known_location_pin_head_radius);

    Bitmap bitmap = Bitmap.createBitmap(dim, dim, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);

    Paint paint = new Paint();
    paint.setAntiAlias(true);/*from ww  w  . j  av  a  2 s  . c  om*/

    KnownLocationPinData pinData = new KnownLocationPinData(c, mLocation);

    // Draw the pin line first.  That goes from the bottom-center up to
    // wherever the radius and length take us.
    float topX = Double.valueOf((dim / 2) + (pinData.getLength() * Math.cos(pinData.getAngle()))).floatValue();
    float topY = Double.valueOf(dim - (pinData.getLength() * Math.sin(pinData.getAngle()))).floatValue();
    paint.setStrokeWidth(c.getResources().getDimension(R.dimen.known_location_stroke));
    paint.setStyle(Paint.Style.STROKE);
    paint.setColor(Color.BLACK);

    canvas.drawLine(dim / 2, dim, topX, topY, paint);

    // On the top of that line, fill in a circle.
    paint.setColor(pinData.getColor());
    paint.setStyle(Paint.Style.FILL);
    canvas.drawCircle(topX, topY, radius, paint);

    // And outline it.
    paint.setColor(Color.BLACK);
    paint.setStyle(Paint.Style.STROKE);
    canvas.drawCircle(topX, topY, radius, paint);

    return bitmap;
}

From source file:edu.csun.ecs.cs.multitouchj.application.touchpong.TouchPong.java

private void onGameStateStart() {
    wonControl.setVisible(false);//from  ww  w  .  j  ava  2 s.  c om
    lostControl.setVisible(false);

    Random random = new Random(new Date().getTime());
    float ballAngle = (float) random.nextInt(360);
    float ballX = (float) Math.cos(Math.toRadians(ballAngle));
    float ballY = (float) Math.sin(Math.toRadians(ballAngle));
    if (ballX == 0.0f) {
        ballX = 0.5f;
    }
    if (ballY == 0.0f) {
        ballY = 0.5f;
    }

    log.debug("angle: " + ballAngle + ", x: " + ballX + ", y: " + ballY);
    ballUnitVector.set(ballX, ballY);
    ballUnitVector = ballUnitVector.normalise(null);

    gameState = GameState.Playing;
}

From source file:de.tuberlin.uebb.jdae.diff.total.TDOperations.java

public final void sin(final PDNumber[] a, final PDNumber[] target) {
    final double[] f = new double[order + 2];
    f[0] = Math.sin(a[0].values[0]);
    f[1] = Math.cos(a[0].values[0]);
    for (int n = 2; n < order + 2; n++)
        f[n] = -f[n - 2];/*  w ww .  j  a  v  a  2s . c  om*/

    compose(f, a, target);
}

From source file:Matrix4x4.java

/**
 * Apply rotation around an arbitrary axis.
 *
 * Ref: http://www.swin.edu.au/astronomy/pbourke/geometry/rotate/
 * (but be aware of errors, corrected here)
 *
 * @param angle  Angle to rotate [radians]
 * @param p0     First point defining the axis (x,y,z)
 * @param p1     Second point defining the axis (x,y,z)
 *///from  w  w w.  j  ava 2  s  . co  m
public void rotate(double angle, double[] p0, double[] p1) {
    // Represent axis of rotation by a unit vector [a,b,c]
    double a = p1[0] - p0[0];
    double b = p1[1] - p0[1];
    double c = p1[2] - p0[2];

    double length = Math.sqrt(a * a + b * b + c * c);

    a /= length;
    b /= length;
    c /= length;

    double d = Math.sqrt(b * b + c * c);

    // Coefficients used for step 2 matrix
    double e = d == 0.0 ? 1.0 : c / d;
    double f = d == 0.0 ? 0.0 : b / d;

    // Coefficients used for the step 3 matrix
    double k = d;
    double l = a;

    // Coefficients for the step 5 matrix (inverse of step 3)
    double m = d / (a * a + d * d);
    double n = a / (a * a + d * d);

    // Coefficients for the step 4 matrix
    double cosAngle = Math.cos(angle);
    double sinAngle = Math.sin(angle);

    //
    // Step 1
    //
    Matrix4x4 step1 = new Matrix4x4();
    step1.setElement(3, 0, -p0[0]);
    step1.setElement(3, 1, -p0[1]);
    step1.setElement(3, 2, -p0[2]);

    //
    // Step 2
    //
    Matrix4x4 step2 = new Matrix4x4();
    step2.setElement(1, 1, e);
    step2.setElement(1, 2, f);
    step2.setElement(2, 1, -f);
    step2.setElement(2, 2, e);

    //
    // Step 3
    //
    Matrix4x4 step3 = new Matrix4x4();
    step3.setElement(0, 0, k);
    step3.setElement(0, 2, l);
    step3.setElement(2, 0, -l);
    step3.setElement(2, 2, k);

    //
    // Step 4
    //
    Matrix4x4 step4 = new Matrix4x4();
    step4.setElement(0, 0, cosAngle);
    step4.setElement(0, 1, sinAngle);
    step4.setElement(1, 0, -sinAngle);
    step4.setElement(1, 1, cosAngle);

    //
    // Step 5 (inverse of step 3)
    //
    Matrix4x4 step5 = new Matrix4x4();
    step5.setElement(0, 0, m);
    step5.setElement(0, 2, -n);
    step5.setElement(2, 0, n);
    step5.setElement(2, 2, m);

    //
    // Step 6 (inverse of step 2)
    //
    Matrix4x4 step6 = new Matrix4x4();
    step6.setElement(1, 1, e);
    step6.setElement(1, 2, -f);
    step6.setElement(2, 1, f);
    step6.setElement(2, 2, e);

    //
    // Step 7 (inverse of step 1)
    //
    Matrix4x4 step7 = new Matrix4x4();
    step7.setElement(3, 0, p0[0]);
    step7.setElement(3, 1, p0[1]);
    step7.setElement(3, 2, p0[2]);

    multiply(step1);
    multiply(step2);
    multiply(step3);
    multiply(step4);
    multiply(step5);
    multiply(step6);
    multiply(step7);
}

From source file:de.tuberlin.uebb.jdae.diff.total.TDOperations.java

public final void cos(final PDNumber[] a, final PDNumber[] target) {
    final double[] f = new double[order + 2];
    f[0] = Math.cos(a[0].values[0]);
    f[1] = -Math.sin(a[0].values[0]);
    for (int n = 2; n < order + 2; n++)
        f[n] = -f[n - 2];/*from   www .j a  v  a2  s  .c  om*/

    compose(f, a, target);
}

From source file:de.biomedical_imaging.ij.steger.Lines_.java

private void displayContours() {
    imp.setOverlay(null);/*  w w  w  .  j  ava 2  s.  com*/
    Overlay ovpoly = new Overlay();

    double px, py, nx, ny, px_r = 0, py_r = 0, px_l = 0, py_l = 0;
    double last_w_r, last_w_l;

    // Print contour and boundary
    for (int k = 0; k < result.size(); k++) {
        for (int i = 0; i < result.get(k).size(); i++) {
            FloatPolygon polyMitte = new FloatPolygon();

            FloatPolygon polyR = new FloatPolygon();
            FloatPolygon polyL = new FloatPolygon();
            Line cont = result.get(k).get(i);
            int num_points = cont.num;
            last_w_r = 0;
            last_w_l = 0;

            for (int j = 0; j < num_points; j++) {

                px = cont.col[j];
                py = cont.row[j];
                nx = Math.sin(cont.angle[j]);
                ny = Math.cos(cont.angle[j]);
                if (doEstimateWidth) {
                    px_r = px + cont.width_r[j] * nx;
                    py_r = py + cont.width_r[j] * ny;
                    px_l = px - cont.width_l[j] * nx;
                    py_l = py - cont.width_l[j] * ny;
                }

                polyMitte.addPoint((px + 0.5), (py + 0.5));
                if (doEstimateWidth) {
                    if (last_w_r > 0 && cont.width_r[j] > 0) {
                        polyR.addPoint((px_r + 0.5), (py_r + 0.5));
                    }
                    if (last_w_l > 0 && cont.width_l[j] > 0) {
                        polyL.addPoint((px_l + 0.5), (py_l + 0.5));
                    }
                }
                if (doEstimateWidth) {
                    last_w_r = cont.width_r[j];
                    last_w_l = cont.width_l[j];
                }
            }

            PolygonRoi polyRoiMitte = new PolygonRoi(polyMitte, Roi.POLYLINE);

            polyRoiMitte.setStrokeColor(Color.red);
            int position = result.get(k).getFrame();
            if (!doStack || isPreview) {
                position = imp.getCurrentSlice();
            }

            polyRoiMitte.setPosition(position);
            ovpoly.add(polyRoiMitte);

            if (doEstimateWidth) {
                if (polyL.npoints > 1) {
                    PolygonRoi polyRoiRand1 = new PolygonRoi(polyL, Roi.POLYLINE);
                    polyRoiRand1.setStrokeColor(Color.green);
                    position = result.get(k).getFrame();
                    if (!doStack || isPreview) {
                        position = imp.getCurrentSlice();
                    }
                    polyRoiRand1.setPosition(position);
                    ovpoly.add(polyRoiRand1);

                    PolygonRoi polyRoiRand2 = new PolygonRoi(polyR, Roi.POLYLINE);
                    polyRoiRand2.setStrokeColor(Color.green);
                    polyRoiRand2.setPosition(position);
                    ovpoly.add(polyRoiRand2);
                }
            }

            //Show IDs
            if (showIDs) {/*
                          int posx =  polyMitte.xpoints[0];
                          int posy =  polyMitte.ypoints[0];
                          if(cont.cont_class == contour_class.cont_start_junc){
                          posx =  polyMitte.xpoints[polyMitte.npoints-1];
                          posy =  polyMitte.ypoints[polyMitte.npoints-1];
                          }
                          */

                int posx = (int) polyMitte.xpoints[polyMitte.npoints / 2];
                int posy = (int) polyMitte.ypoints[polyMitte.npoints / 2];
                TextRoi tr = new TextRoi(posx, posy, "" + cont.getID());
                tr.setCurrentFont(new Font(Font.SANS_SERIF, Font.PLAIN, 9));
                tr.setIgnoreClipRect(true);
                tr.setStrokeColor(Color.orange);
                tr.setPosition(resultJunction.get(k).getFrame());
                ovpoly.add(tr);
            }
        }
    }
    if (showJunctionPoints) {
        // Print junctions

        for (int k = 0; k < resultJunction.size(); k++) {
            FloatPolygon pointpoly = new FloatPolygon();
            for (int i = 0; i < resultJunction.get(k).size(); i++) {

                pointpoly.addPoint(resultJunction.get(k).get(i).x + 0.5, resultJunction.get(k).get(i).y + 0.5);
            }

            PointRoi pointroi = new PointRoi(pointpoly);
            pointroi.setShowLabels(false);
            int position = resultJunction.get(k).getFrame();
            if (!doStack || isPreview) {
                position = imp.getCurrentSlice();
            }
            pointroi.setPosition(position);
            ovpoly.add(pointroi);
        }
    }
    if (ovpoly.size() > 0) {
        imp.setOverlay(ovpoly);
    }
}