Example usage for android.graphics PointF PointF

List of usage examples for android.graphics PointF PointF

Introduction

In this page you can find the example usage for android.graphics PointF PointF.

Prototype

public PointF(float x, float y) 

Source Link

Usage

From source file:Main.java

public static boolean withPointRadius(float x, float y, PointF target, float radius) {
    PointF cur = new PointF(x, y);
    return withPointRadius(cur, target, radius);
}

From source file:Main.java

/**
 * Calculates the position around a center point, depending on the distance
 * from the center, and the angle of the position around the center.
 *
 * @param center//w ww . j a va 2 s  . c o  m
 * @param dist
 * @param angle  in degrees, converted to radians internally
 * @return
 */
public static PointF getPosition(PointF center, float dist, float angle) {

    PointF p = new PointF((float) (center.x + dist * Math.cos(Math.toRadians(angle))),
            (float) (center.y + dist * Math.sin(Math.toRadians(angle))));
    return p;
}

From source file:Main.java

public static PointF mapDisplayPointTo(Point p, Point center) {
    return new PointF(p.x - center.x, center.y - p.y);
}

From source file:Main.java

public static PointF rotatePoint(PointF point, PointF centerPoint, float rotate) {
    float x = point.x;
    float y = point.y;
    float sinA = (float) Math.sin(Math.toRadians(rotate));
    float cosA = (float) Math.cos(Math.toRadians(rotate));
    float newX = centerPoint.x + (x - centerPoint.x) * cosA - (y - centerPoint.y) * sinA;
    float newY = centerPoint.y + (y - centerPoint.y) * cosA + (x - centerPoint.x) * sinA;
    return new PointF(newX, newY);
}

From source file:Main.java

public static PointF mapDisplayPointTo(PointF p, PointF center) {
    return new PointF(p.x - center.x, center.y - p.y);
}

From source file:Main.java

/**
 * Method to see if the given XY value is within the reach of the lamps.
 * /*from w  w  w . j  a v a 2s. c o  m*/
 * @param p the point containing the X,Y value
 * @return true if within reach, false otherwise.
 */
private static boolean checkPointInLampsReach(PointF p, ArrayList<PointF> colorPoints) {
    PointF red = colorPoints.get(CPT_RED);
    PointF green = colorPoints.get(CPT_GREEN);
    PointF blue = colorPoints.get(CPT_BLUE);
    PointF v1 = new PointF(green.x - red.x, green.y - red.y);
    PointF v2 = new PointF(blue.x - red.x, blue.y - red.y);
    PointF q = new PointF(p.x - red.x, p.y - red.y);
    float s = crossProduct(q, v2) / crossProduct(v1, v2);
    float t = crossProduct(v1, q) / crossProduct(v1, v2);
    if ((s >= 0.0f) && (t >= 0.0f) && (s + t <= 1.0f)) {
        return true;
    } else {
        return false;

    }
}

From source file:Main.java

public static PointF getMiddlePoint(PointF p1, PointF p2) {
    return new PointF((p1.x + p2.x) / 2.0f, (p1.y + p2.y) / 2.0f);
}

From source file:Main.java

public static PointF getPointByPercent(PointF p1, PointF p2, float percent) {
    return new PointF(evaluate(percent, p1.x, p2.x), evaluate(percent, p1.y, p2.y));
}

From source file:Main.java

/**
 * Get center locations delta between two views.
 *
 * @param viewA View A.//from w w  w. j a v a  2  s . c om
 * @param viewB View B.
 * @return Locations delta as a point.
 */
private static PointF getCenterLocationsDelta(final View viewA, final View viewB) {
    final int[] fromLocation = new int[2];
    viewA.getLocationOnScreen(fromLocation);
    final int[] toLocation = new int[2];
    viewB.getLocationOnScreen(toLocation);
    final int deltaX = toLocation[0] - fromLocation[0] + viewB.getMeasuredWidth() / 2
            - viewA.getMeasuredWidth() / 2;
    final int deltaY = toLocation[1] - fromLocation[1] + viewB.getMeasuredHeight() / 2
            - viewA.getMeasuredHeight() / 2;
    return new PointF(deltaX, deltaY);
}

From source file:Main.java

private static ArrayList<PointF> colorPointsForModel(String model) {
    // LLC001, // LedStrip    // LWB001, // LivingWhite    
    if (model == null) { // if model is not known go for the default choice
        model = " ";
    }/*from  ww w.j  ava 2  s. c  o  m*/
    ArrayList<PointF> colorPoints = new ArrayList<PointF>();

    ArrayList<String> hueBulbs = new ArrayList<String>();
    hueBulbs.add("LCT001");

    ArrayList<String> livingColors = new ArrayList<String>();
    livingColors.add("LLC001");
    livingColors.add("LLC005");
    livingColors.add("LLC006");
    livingColors.add("LLC007");
    livingColors.add("LLC010");
    livingColors.add("LLC011");
    livingColors.add("LLC012");

    if (hueBulbs.contains(model)) {
        // Hue bulbs color gamut triangle
        colorPoints.add(new PointF(.674F, 0.322F)); // Red        
        colorPoints.add(new PointF(0.408F, 0.517F)); // Green        
        colorPoints.add(new PointF(0.168F, 0.041F)); // Blue            
    } else if (livingColors.contains(model)) {
        // LivingColors color gamut triangle
        colorPoints.add(new PointF(0.703F, 0.296F)); // Red        
        colorPoints.add(new PointF(0.214F, 0.709F)); // Green        
        colorPoints.add(new PointF(0.139F, 0.081F)); // Blue    
    } else {
        // Default construct triangle wich contains all values        
        colorPoints.add(new PointF(1.0F, 0.0F));// Red        
        colorPoints.add(new PointF(0.0F, 1.0F)); // Green       
        colorPoints.add(new PointF(0.0F, 0.0F));// Blue    
    }
    return colorPoints;
}