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.google.location.lbs.gnss.gps.pseudorange.EcefToTopocentricConverter.java

/**
 * Transformation of {@code inputVectorMeters} with origin at {@code originECEFMeters} into
 * topocentric coordinate system. The result is {@code TopocentricAEDValues} containing azimuth
 * from north +ve clockwise, radians; elevation angle, radians; distance, vector length meters
 *
 * <p>Source: http://www.navipedia.net/index.php/Transformations_between_ECEF_and_ENU_coordinates
 * http://kom.aau.dk/~borre/life-l99/topocent.m
 *
 *//* w  ww . ja  va 2  s . c om*/
public static TopocentricAEDValues convertCartesianToTopocentericRadMeters(final double[] originECEFMeters,
        final double[] inputVectorMeters) {

    GeodeticLlaValues latLngAlt = Ecef2LlaConverter.convertECEFToLLACloseForm(originECEFMeters[0],
            originECEFMeters[1], originECEFMeters[2]);

    RealMatrix rotationMatrix = Ecef2EnuConverter
            .getRotationMatrix(latLngAlt.latitudeRadians, latLngAlt.longitudeRadians).transpose();
    double[] eastNorthUpVectorMeters = GpsMathOperations
            .matrixByColVectMultiplication(rotationMatrix.transpose().getData(), inputVectorMeters);
    double eastMeters = eastNorthUpVectorMeters[EAST_IDX];
    double northMeters = eastNorthUpVectorMeters[NORTH_IDX];
    double upMeters = eastNorthUpVectorMeters[UP_IDX];

    // calculate azimuth, elevation and height from the ENU values
    double horizontalDistanceMeters = Math.hypot(eastMeters, northMeters);
    double azimuthRadians;
    double elevationRadians;

    if (horizontalDistanceMeters < MIN_DISTANCE_MAGNITUDE_METERS) {
        elevationRadians = Math.PI / 2.0;
        azimuthRadians = 0;
    } else {
        elevationRadians = Math.atan2(upMeters, horizontalDistanceMeters);
        azimuthRadians = Math.atan2(eastMeters, northMeters);
    }
    if (azimuthRadians < 0) {
        azimuthRadians += 2 * Math.PI;
    }

    double distanceMeters = Math.sqrt(Math.pow(inputVectorMeters[0], 2) + Math.pow(inputVectorMeters[1], 2)
            + Math.pow(inputVectorMeters[2], 2));
    return new TopocentricAEDValues(elevationRadians, azimuthRadians, distanceMeters);
}

From source file:com.andryr.guitartuner.Utils.java

public static void reveal(View view) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // get the center for the clipping circle
        int cx = view.getWidth() / 2;
        int cy = view.getHeight() / 2;

        // 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)
        Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius);

        // make the view visible and start the animation
        view.setVisibility(View.VISIBLE);
        anim.start();//ww w.  j  a  v a  2  s . c  o  m
    } else {
        view.setVisibility(View.VISIBLE);
        view.animate().alpha(1f).start();
    }
}

From source file:com.example.android.revealeffectbasic.RevealEffectBasicFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.reveal_effect_basic, container, false);

    View button = rootView.findViewById(R.id.button);

    // Set a listener to reveal the view when clicked.
    button.setOnClickListener(new View.OnClickListener() {
        @Override/* w w  w.  ja v a 2  s.c  om*/
        public void onClick(View view) {
            View shape = rootView.findViewById(R.id.circle);

            // Create a reveal {@link Animator} that starts clipping the view from
            // the top left corner until the whole view is covered.
            Animator animator = ViewAnimationUtils.createCircularReveal(shape, 0, 0, 0,
                    (float) Math.hypot(shape.getWidth(), shape.getHeight()));

            // Set a natural ease-in/ease-out interpolator.
            animator.setInterpolator(new AccelerateDecelerateInterpolator());

            // Finally start the animation
            animator.start();

            Log.d(TAG, "Starting Reveal animation");
        }
    });

    return rootView;
}

From source file:com.example.toolbardemo.Fragment.CircularRevealFragment.java

/**
 * {@inheritDoc}//from   w  ww . j  a v a 2s. co m
 * @see android.support.v4.app.Fragment#onActivityCreated(android.os.Bundle)
 */
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onActivityCreated(savedInstanceState);
    tv1 = (TextView) getActivity().findViewById(R.id.textView1);
    tv2 = (TextView) getActivity().findViewById(R.id.textView2);
    tv3 = (TextView) getActivity().findViewById(R.id.textView3);
    tv4 = (TextView) getActivity().findViewById(R.id.textView4);
    tv1.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Animator animator = ViewAnimationUtils.createCircularReveal(tv1, tv1.getWidth() / 2,
                    tv1.getHeight() / 2, tv1.getWidth(), 0);
            animator.setInterpolator(new AccelerateDecelerateInterpolator());
            animator.setDuration(1000);
            animator.start();
        }
    });
    tv2.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Animator animator = ViewAnimationUtils.createCircularReveal(tv2, 0, 0, 0,
                    (float) Math.hypot(tv2.getWidth(), tv2.getHeight()));
            animator.setInterpolator(new AccelerateInterpolator());
            animator.setDuration(1000);
            animator.start();
        }
    });
    tv3.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Animator animator = ViewAnimationUtils.createCircularReveal(tv3, tv3.getWidth() / 2,
                    tv3.getHeight() / 2, 0, tv3.getWidth());
            animator.setInterpolator(new AccelerateInterpolator());
            animator.setDuration(1000);
            animator.start();
        }
    });
    tv4.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Animator animator = ViewAnimationUtils.createCircularReveal(tv4, 0, 0,
                    (float) Math.hypot(tv4.getWidth(), tv4.getHeight()), 0);
            animator.setInterpolator(new AccelerateInterpolator());
            animator.setDuration(1000);
            animator.start();
        }
    });
}

From source file:tech.salroid.filmy.fragment.FullReadFragment.java

@Nullable
@Override//  ww w . j a va2s .c o m
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.read_full_layout, container, false);
    ButterKnife.bind(this, view);

    crossButton.setOnClickListener(this);

    // To run the animation as soon as the view is layout in the view hierarchy we add this
    // listener and remove it
    // as soon as it runs to prevent multiple animations if the view changes bounds
    view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop,
                int oldRight, int oldBottom) {
            v.removeOnLayoutChangeListener(this);

            int cx = getArguments().getInt("cx");
            int cy = getArguments().getInt("cy");

            // get the hypothenuse so the radius is from one corner to the other
            int radius = (int) Math.hypot(right, bottom);

            Animator reveal;

            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
                reveal = ViewAnimationUtils.createCircularReveal(v, cx, cy, 0, radius);
                reveal.setInterpolator(new DecelerateInterpolator(2f));
                reveal.setDuration(1000);
                reveal.start();
            }

        }
    });

    return view;
}

From source file:com.andryr.guitartuner.Utils.java

public static void hide(final View view) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // get the center for the clipping circle
        int cx = view.getWidth() / 2;
        int cy = view.getHeight() / 2;

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

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

        // make the view invisible when the animation is done
        anim.addListener(new AnimatorListenerAdapter() {
            @Override/*from  www.j av a  2 s. c om*/
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                view.setVisibility(View.INVISIBLE);
            }
        });

        // start the animation
        anim.start();
    } else {
        view.animate().alpha(0f).setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                view.setVisibility(View.INVISIBLE);
            }
        }).start();
    }
}

From source file:com.opengamma.analytics.math.ComplexMathUtils.java

/**
 * Returns the principal value of log, with z the principal argument of z defined to lie in the interval (-pi, pi]
 * @param z ComplexNumber//from   w  w  w .jav a2s. c om
 * @return The log
 */
public static ComplexNumber log(final ComplexNumber z) {
    ArgumentChecker.notNull(z, "z");
    return new ComplexNumber(Math.log(Math.hypot(z.getReal(), z.getImaginary())),
            Math.atan2(z.getImaginary(), z.getReal()));
}

From source file:tech.salroid.filmy.fragment.AllTrailerFragment.java

@Nullable
@Override//ww w. j  a v  a2s.  c  o  m
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {

    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
    nightMode = sp.getBoolean("dark", false);

    View view = inflater.inflate(R.layout.all_trailer_layout, container, false);
    ButterKnife.bind(this, view);

    if (!nightMode)
        allThemeLogic();
    else {
        nightModeLogic();
    }

    crossButton.setOnClickListener(this);

    // To run the animation as soon as the view is layout in the view hierarchy we add this
    // listener and remove it
    // as soon as it runs to prevent multiple animations if the view changes bounds
    view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop,
                int oldRight, int oldBottom) {
            v.removeOnLayoutChangeListener(this);

            int cx = getArguments().getInt("cx");
            int cy = getArguments().getInt("cy");

            // get the hypothenuse so the radius is from one corner to the other
            int radius = (int) Math.hypot(right, bottom);

            Animator reveal;

            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
                reveal = ViewAnimationUtils.createCircularReveal(v, cx, cy, 0, radius);
                reveal.setInterpolator(new DecelerateInterpolator(2f));
                reveal.setDuration(1000);
                reveal.start();
            }

        }
    });

    init(view);

    return view;
}

From source file:com.opengamma.analytics.math.ComplexMathUtils.java

public static double mod(final ComplexNumber z) {
    ArgumentChecker.notNull(z, "z");
    return Math.hypot(z.getReal(), z.getImaginary());
}

From source file:com.adkdevelopment.rssreader.utils.Utilities.java

/**
 * Animates RecyclerView card on click with revealing effect
 * @param viewHolder to make animation on
 *///from   w w w .j  av  a  2 s  .c om
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void animationCard(RecyclerView.ViewHolder viewHolder) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        if (sBlueColor == 0) {
            sBlueColor = ContextCompat.getColor(viewHolder.itemView.getContext(), R.color.colorPrimary);
        }
        if (sWhiteColor == 0) {
            sWhiteColor = ContextCompat.getColor(viewHolder.itemView.getContext(), R.color.white);
        }

        int finalRadius = (int) Math.hypot(viewHolder.itemView.getWidth() / 2,
                viewHolder.itemView.getHeight() / 2);

        Animator anim = ViewAnimationUtils.createCircularReveal(viewHolder.itemView,
                viewHolder.itemView.getWidth() / 2, viewHolder.itemView.getHeight() / 2, 0, finalRadius);

        viewHolder.itemView.setBackgroundColor(sBlueColor);
        anim.start();
        anim.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                viewHolder.itemView.setBackgroundColor(sWhiteColor);
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
    }
}