Gets a float array of two lengths representing a rectangles width and height The order of the corners in the input float array is: 0------->1 ^ | | | | v 3<-------2 - Android Graphics

Android examples for Graphics:Rectangle

Description

Gets a float array of two lengths representing a rectangles width and height The order of the corners in the input float array is: 0------->1 ^ | | | | v 3<-------2

Demo Code


//package com.java2s;

public class Main {
    /**/*from w ww. ja  v a 2s  .  c  o  m*/
     * Gets a float array of two lengths representing a rectangles width and height
     * The order of the corners in the input float array is:
     * 0------->1
     * ^        |
     * |        |
     * |        v
     * 3<-------2
     *
     * @param corners the float array of corners (8 floats)
     * @return the float array of width and height (2 floats)
     */
    public static float[] getRectSidesFromCorners(float[] corners) {
        return new float[] {
                (float) Math.sqrt(Math.pow(corners[0] - corners[2], 2)
                        + Math.pow(corners[1] - corners[3], 2)),
                (float) Math.sqrt(Math.pow(corners[2] - corners[4], 2)
                        + Math.pow(corners[3] - corners[5], 2)) };
    }
}

Related Tutorials