Get the point of intersection between circle and line. - Android Graphics

Android examples for Graphics:Path Point

Description

Get the point of intersection between circle and line.

Demo Code


//package com.java2s;
import android.graphics.PointF;

public class Main {

    public static PointF[] getIntersectionPoints(PointF pMiddle,
            float radius, Double lineK) {
        PointF[] points = new PointF[2];

        float radian, xOffset = 0, yOffset = 0;
        if (lineK != null) {
            radian = (float) Math.atan(lineK);// ???????
            xOffset = (float) (Math.sin(radian) * radius);// ??????
            yOffset = (float) (Math.cos(radian) * radius);// ??????
        } else {/*from  ww w  .  ja va2 s . c  om*/
            xOffset = radius;
            yOffset = 0;
        }
        points[0] = new PointF(pMiddle.x + xOffset, pMiddle.y - yOffset);
        points[1] = new PointF(pMiddle.x - xOffset, pMiddle.y + yOffset);

        return points;
    }
}

Related Tutorials