float d = (float) twoPointDistace(lastPoint.x, lastPoint.y, curPoint.x, curPoint.y);
float cos_a = (curPoint.x - lastPoint.x) * 1.0f / d;
float sin_a = (curPoint.y - lastPoint.y) * 1.0f / d;
canvas.drawLine(lastPoint.x + inCircleR * cos_a, lastPoint.y + inCircleR * sin_a,
curPoint.x - inCircleR * cos_a, curPoint.y - inCircleR * sin_a, linePressPaint);
//绘制箭头
drawArrow(lastPoint.x, lastPoint.y, d, cos_a, sin_a, canvas);
lastPoint = curPoint;
}
if (isPressFlag){
//绘制射线
float d = (float) twoPointDistace(lastPoint.x, lastPoint.y, downPointX, downPointY);
float cos_a = (downPointX - lastPoint.x) * 1.0f / d;
float sin_a = (downPointY - lastPoint.y) * 1.0f / d;
canvas.drawLine(lastPoint.x + inCircleR * cos_a, lastPoint.y + inCircleR * sin_a,
downPointX, downPointY, linePressPaint);
}
}
}
private void drawArrow(float startX, float startY, float d, float cos_a, float sin_a, Canvas canvas) {
float l = (float) (arrowHeight * (Math.tan(Math.toRadians(angle))));
float x0 = startX + (d - outCircleR - arrowHeight) * cos_a;
float y0 = startY + (d - outCircleR - arrowHeight) * sin_a;
float x1 = startX + (d - outCircleR) * cos_a;
float y1 = startY + (d - outCircleR) * sin_a;
float x2 = x0 + l * sin_a;
float y2 = y0 - l * cos_a;
float x3 = x0 - l * sin_a;
float y3 = y0 + l * cos_a;
Path path = new Path();
path.moveTo(x1, y1);
path.lineTo(x2, y2);
path.lineTo(x3, y3);
path.close();
linePressPaint.setStyle(Paint.Style.FILL);
canvas.drawPath(path, linePressPaint);
}
private double twoPointDistace(float startX, float startY, float endX, float endY) {
return Math.sqrt(Math.pow(startX - endX, 2) + Math.pow(startY - endY, 2));
}
@Override
public boolean onTouchEvent(MotionEvent event) {
downPointX = event.getX();
downPointY = event.getY();
System.out.println(event.getAction());
switch (event.getAction()) {
case Moti