Example usage for java.lang Math hypot

List of usage examples for java.lang Math hypot

Introduction

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

Prototype

public static double hypot(double x, double y) 

Source Link

Document

Returns sqrt(x2 +y2) without intermediate overflow or underflow.

Usage

From source file:com.chrynan.guitartuner.PitchFragment.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void circularReveal(final float x, final float y) {
    if (x != -1 && y != -1) {
        float finalRadius = (float) Math.hypot(viewRoot.getWidth(), viewRoot.getHeight());
        Animator anim = ViewAnimationUtils.createCircularReveal(viewRoot, (int) x, (int) y, 0, finalRadius);
        //viewRoot.setBackgroundColor(getActivity().getResources().getColor(R.color.white));
        anim.setInterpolator(new DecelerateInterpolator(2f));
        anim.setDuration(1000);//from w  w w  .j  av  a 2 s. c om
        anim.start();
    }
}

From source file:uk.ac.hutton.ics.buntata.fragment.IntroNetworkFragment.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void circularShowView(final View view) {
    if (anim != null && anim.isRunning())
        anim.end();/*w  w  w  .ja  va2s  .  c  o  m*/

    /* set the center for the clipping circle */
    int cx = view.getWidth() / 2;
    int cy = view.getHeight();

    /* get the final radius for the clipping circle */
    float finalRadius = (float) Math.hypot(cx, cy);

    /* create the animator for this view (the start radius is zero) */
    anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius);

    /* make the view visible and start the animation */
    view.setVisibility(View.VISIBLE);

    anim.start();
}

From source file:syncleus.dann.math.ComplexNumber.java

public final double absScalar() {
    return Math.hypot(this.getReal(), this.getImaginary());
}

From source file:com.chrynan.guitartuner.PitchFragment.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public Animator unreveal(final float x, final float y) {
    Animator anim = ViewAnimationUtils.createCircularReveal(getView(), (int) x, (int) y,
            (float) Math.hypot(viewRoot.getWidth(), viewRoot.getHeight()), 0);
    anim.setInterpolator(new AccelerateInterpolator(0.5f));
    anim.setDuration(500);/*from  w w  w. java2s  .co m*/
    return anim;
}

From source file:edu.stanford.cfuller.imageanalysistools.filter.VoronoiFilter.java

/**
* Checks whether a given coordinate would be on a boundary of a 
* Voronoi diagram created from the given points.
*
**//*  w  w  w . j a va 2  s  . c o  m*/
public boolean isOnEightConnectedBoundary(java.util.List<Vector2D> points, ImageCoordinate ic) {

    int x = ic.get(ImageCoordinate.X);
    int y = ic.get(ImageCoordinate.Y);

    int closestIndex = 0;
    int nextIndex = 0;
    double closestDist = Double.MAX_VALUE;
    double nextDist = Double.MAX_VALUE;

    for (int i = 0; i < points.size(); i++) {

        Vector2D pt = points.get(i);

        double dist = Math.hypot(pt.getX() - x, pt.getY() - y);

        if (dist < closestDist) {

            nextDist = closestDist;
            nextIndex = closestIndex;
            closestDist = dist;
            closestIndex = i;

        } else if (dist < nextDist) {
            nextDist = dist;
            nextIndex = i;
        }

    }

    Vector2D projectedCoordinate = this.projectPointOntoVector(points.get(closestIndex), new Vector2D(x, y),
            points.get(nextIndex));

    double distToNext = points.get(nextIndex).subtract(projectedCoordinate).getNorm();

    double distToClosest = points.get(closestIndex).subtract(projectedCoordinate).getNorm();

    final double cutoff = 1.3 * Math.sqrt(2);

    if (distToNext - distToClosest < cutoff) {
        return true;
    }

    return false;

}

From source file:com.compomics.cell_coord.computation.impl.TrackOperatorImpl.java

@Override
public void computeStepDisplacements(Track track) {
    Double[][] steps = track.getSteps();
    Double[] stepDisplacements = new Double[steps.length];
    for (int row = 0; row < stepDisplacements.length; row++) {
        Double stepDispl = Math.hypot(steps[row][0], steps[row][1]);
        stepDisplacements[row] = stepDispl;
    }/* w w w .j  av a2  s.com*/
    track.setStepDisplacements(stepDisplacements);
}

From source file:uk.ac.hutton.ics.buntata.fragment.IntroNetworkFragment.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void circularHideView(final View view, final AnimatorListenerAdapter listener) {
    if (anim != null && anim.isRunning())
        anim.end();//from  w  ww. jav a2s . c  om

    /* get the center for the clipping circle */
    int cx = view.getWidth() / 2;
    int cy = view.getHeight();

    /* get the initial radius for the clipping circle */
    float initialRadius = (float) Math.hypot(cx, cy);

    /* create the animation (the final radius is zero) */
    anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, initialRadius, 0);

    /* make the view invisible when the animation is done */
    anim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            view.setVisibility(View.INVISIBLE);

            if (listener != null) {
                listener.onAnimationEnd(animation);
            }
        }
    });

    anim.start();
}

From source file:lk.ac.mrt.projectx.buildex.complex.FormalVerifier.java

/**
 * Populates the data array with random values.
 *///from  www.  j  av  a 2s.  co m
private void populateData() {
    double maxR = Math.hypot(width / 2, height / 2);

    //        Generator generator = new PolarGenerator();
    Generator generator = new TwirlGenerator();
    List<Pair<CartesianCoordinate, CartesianCoordinate>> list = generator.generate(width, height);
    int i = 0;
    for (Pair<CartesianCoordinate, CartesianCoordinate> cartesianCoordinateCartesianCoordinatePair : list) {
        CartesianCoordinate oldCoord = cartesianCoordinateCartesianCoordinatePair.first;
        CartesianCoordinate outputCoord = cartesianCoordinateCartesianCoordinatePair.second;
        PolarCoordinate polarOldCoord = CoordinateTransformer.cartesian2Polar(width, height, oldCoord);
        PolarCoordinate polaroOutputCoord = CoordinateTransformer.cartesian2Polar(width, height, outputCoord);

        if (clampPass(width, height, outputCoord)) {
            //  out.setRGB(i, j, in.getRGB((int) newCartCord.getX(), (int) newCartCord.getY()));
            //TODO : Add data 0 - X axis , 1 - Y Axis
            this.data[0][i] = (float) polarOldCoord.getR() * 0.05f + (float) polarOldCoord.getTheta();
            this.data[1][i] = (float) polaroOutputCoord.getTheta();
        }
        i++;
    }

}

From source file:com.google.samples.apps.ourstreets.view.ViewUtils.java

/**
 * Create a simple circular reveal from a given start view to it's target view.
 * This reveal will start from the start view's boundaries until it fills the target view.
 *
 * @param center The center x and y coordinates of the start circle.
 * @param width The initial width of the view's coordinates.
 * @param targetView The target view which will be displayed once the reveal is done.
 * @param interpolator The interpolator to use.
 * @return The created circular reveal./*from   ww w  .  j a  v a2  s  .  com*/
 */
@NonNull
public static Animator createCircularReveal(@NonNull Point center, int width, @NonNull View targetView,
        @NonNull Interpolator interpolator) {
    final Animator circularReveal = ViewAnimationUtils.createCircularReveal(targetView, center.x, center.y,
            width, (float) Math.hypot(center.x, center.y));
    circularReveal.setInterpolator(interpolator);
    return circularReveal;
}

From source file:com.bachhuberdesign.deckbuildergwent.util.FabTransform.java

@Override
public Animator createAnimator(final ViewGroup sceneRoot, final TransitionValues startValues,
        final TransitionValues endValues) {
    if (startValues == null || endValues == null)
        return null;

    final Rect startBounds = (Rect) startValues.values.get(PROP_BOUNDS);
    final Rect endBounds = (Rect) endValues.values.get(PROP_BOUNDS);

    final boolean fromFab = endBounds.width() > startBounds.width();
    final View view = endValues.view;
    final Rect dialogBounds = fromFab ? endBounds : startBounds;
    final Interpolator fastOutSlowInInterpolator = AnimUtils.getFastOutSlowInInterpolator();
    final long duration = getDuration();
    final long halfDuration = duration / 2;
    final long twoThirdsDuration = duration * 2 / 3;

    if (!fromFab) {
        // Force measure / layout the dialog back to it's original bounds
        view.measure(makeMeasureSpec(startBounds.width(), View.MeasureSpec.EXACTLY),
                makeMeasureSpec(startBounds.height(), View.MeasureSpec.EXACTLY));
        view.layout(startBounds.left, startBounds.top, startBounds.right, startBounds.bottom);
    }//from   w w w.ja va2 s . c  o  m

    final int translationX = startBounds.centerX() - endBounds.centerX();
    final int translationY = startBounds.centerY() - endBounds.centerY();
    if (fromFab) {
        view.setTranslationX(translationX);
        view.setTranslationY(translationY);
    }

    // Add a color overlay to fake appearance of the FAB
    final ColorDrawable fabColor = new ColorDrawable(color);
    fabColor.setBounds(0, 0, dialogBounds.width(), dialogBounds.height());
    if (!fromFab)
        fabColor.setAlpha(0);
    view.getOverlay().add(fabColor);

    // Add an icon overlay again to fake the appearance of the FAB
    final Drawable fabIcon = ContextCompat.getDrawable(sceneRoot.getContext(), icon).mutate();
    final int iconLeft = (dialogBounds.width() - fabIcon.getIntrinsicWidth()) / 2;
    final int iconTop = (dialogBounds.height() - fabIcon.getIntrinsicHeight()) / 2;
    fabIcon.setBounds(iconLeft, iconTop, iconLeft + fabIcon.getIntrinsicWidth(),
            iconTop + fabIcon.getIntrinsicHeight());
    if (!fromFab)
        fabIcon.setAlpha(0);
    view.getOverlay().add(fabIcon);

    // Since the view that's being transition to always seems to be on the top (z-order), we have
    // to make a copy of the "from" view and put it in the "to" view's overlay, then fade it out.
    // There has to be another way to do this, right?
    Drawable dialogView = null;
    if (!fromFab) {
        startValues.view.setDrawingCacheEnabled(true);
        startValues.view.buildDrawingCache();
        Bitmap viewBitmap = startValues.view.getDrawingCache();
        dialogView = new BitmapDrawable(view.getResources(), viewBitmap);
        dialogView.setBounds(0, 0, dialogBounds.width(), dialogBounds.height());
        view.getOverlay().add(dialogView);
    }

    // Circular clip from/to the FAB size
    final Animator circularReveal;
    if (fromFab) {
        circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2,
                view.getHeight() / 2, startBounds.width() / 2,
                (float) Math.hypot(endBounds.width() / 2, endBounds.height() / 2));
        circularReveal.setInterpolator(AnimUtils.getFastOutLinearInInterpolator());
    } else {
        circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2,
                view.getHeight() / 2, (float) Math.hypot(startBounds.width() / 2, startBounds.height() / 2),
                endBounds.width() / 2);
        circularReveal.setInterpolator(AnimUtils.getLinearOutSlowInInterpolator());

        // Persist the end clip i.e. stay at FAB size after the reveal has run
        circularReveal.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                final ViewOutlineProvider fabOutlineProvider = view.getOutlineProvider();

                view.setOutlineProvider(new ViewOutlineProvider() {
                    boolean hasRun = false;

                    @Override
                    public void getOutline(final View view, Outline outline) {
                        final int left = (view.getWidth() - endBounds.width()) / 2;
                        final int top = (view.getHeight() - endBounds.height()) / 2;

                        outline.setOval(left, top, left + endBounds.width(), top + endBounds.height());

                        if (!hasRun) {
                            hasRun = true;
                            view.setClipToOutline(true);

                            // We have to remove this as soon as it's laid out so we can get the shadow back
                            view.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
                                @Override
                                public boolean onPreDraw() {
                                    if (view.getWidth() == endBounds.width()
                                            && view.getHeight() == endBounds.height()) {
                                        view.setOutlineProvider(fabOutlineProvider);
                                        view.setClipToOutline(false);
                                        view.getViewTreeObserver().removeOnPreDrawListener(this);
                                        return true;
                                    }

                                    return true;
                                }
                            });
                        }
                    }
                });
            }
        });
    }
    circularReveal.setDuration(duration);

    // Translate to end position along an arc
    final Animator translate = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, View.TRANSLATION_Y,
            fromFab ? getPathMotion().getPath(translationX, translationY, 0, 0)
                    : getPathMotion().getPath(0, 0, -translationX, -translationY));
    translate.setDuration(duration);
    translate.setInterpolator(fastOutSlowInInterpolator);

    // Fade contents of non-FAB view in/out
    List<Animator> fadeContents = null;
    if (view instanceof ViewGroup) {
        final ViewGroup vg = ((ViewGroup) view);
        fadeContents = new ArrayList<>(vg.getChildCount());
        for (int i = vg.getChildCount() - 1; i >= 0; i--) {
            final View child = vg.getChildAt(i);
            final Animator fade = ObjectAnimator.ofFloat(child, View.ALPHA, fromFab ? 1f : 0f);
            if (fromFab) {
                child.setAlpha(0f);
            }
            fade.setDuration(twoThirdsDuration);
            fade.setInterpolator(fastOutSlowInInterpolator);
            fadeContents.add(fade);
        }
    }

    // Fade in/out the fab color & icon overlays
    final Animator colorFade = ObjectAnimator.ofInt(fabColor, "alpha", fromFab ? 0 : 255);
    final Animator iconFade = ObjectAnimator.ofInt(fabIcon, "alpha", fromFab ? 0 : 255);
    if (!fromFab) {
        colorFade.setStartDelay(halfDuration);
        iconFade.setStartDelay(halfDuration);
    }
    colorFade.setDuration(halfDuration);
    iconFade.setDuration(halfDuration);
    colorFade.setInterpolator(fastOutSlowInInterpolator);
    iconFade.setInterpolator(fastOutSlowInInterpolator);

    // Run all animations together
    final AnimatorSet transition = new AnimatorSet();
    transition.playTogether(circularReveal, translate, colorFade, iconFade);
    transition.playTogether(fadeContents);
    if (dialogView != null) {
        final Animator dialogViewFade = ObjectAnimator.ofInt(dialogView, "alpha", 0)
                .setDuration(twoThirdsDuration);
        dialogViewFade.setInterpolator(fastOutSlowInInterpolator);
        transition.playTogether(dialogViewFade);
    }
    transition.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            // Clean up
            view.getOverlay().clear();

            if (!fromFab) {
                view.setTranslationX(0);
                view.setTranslationY(0);
                view.setTranslationZ(0);

                view.measure(makeMeasureSpec(endBounds.width(), View.MeasureSpec.EXACTLY),
                        makeMeasureSpec(endBounds.height(), View.MeasureSpec.EXACTLY));
                view.layout(endBounds.left, endBounds.top, endBounds.right, endBounds.bottom);
            }

        }
    });
    return new AnimUtils.NoPauseAnimator(transition);
}