Ejemplo n.º 1
0
 private void drawLine(Point start, Point end, Canvas canvas, Paint paint) {
   double d = MathUtils.distance(start.x, start.y, end.x, end.y);
   float cosA = (float) ((end.x - start.x) / d);
   float sinA = (float) ((end.y - start.y) / d);
   float rx = cosA * innerRadius;
   float ry = sinA * innerRadius;
   canvas.drawLine(rx + start.x, ry + start.y, end.x - rx, end.y - ry, paint);
 }
Ejemplo n.º 2
0
 private Point isInRound(float x, float y) {
   for (int i = 0; i < mPoints.length; i++) {
     for (int j = 0; j < mPoints[i].length; j++)
       if (MathUtils.isInRound(mPoints[i][j].x, mPoints[i][j].y, outerRadius, x, y))
         return mPoints[i][j];
   }
   return null;
 }
Ejemplo n.º 3
0
 private void drawArrow(Canvas canvas, Paint paint, Point start, Point end, float arrowHeight) {
   double d = MathUtils.distance(start.x, start.y, end.x, end.y);
   float cosB = (float) ((end.x - start.x) / d);
   float sinB = (float) ((end.y - start.y) / d);
   float tanC = (float) Math.tan(Math.PI / 4); // 箭头尖锐程度,默认为直角
   float h = (float) (d - arrowHeight - outerRadius);
   float l = arrowHeight * tanC;
   float a = l * cosB;
   float b = l * sinB;
   float x0 = h * cosB;
   float y0 = h * sinB;
   float x1 = start.x + (h + arrowHeight) * cosB;
   float y1 = start.y + (h + arrowHeight) * sinB;
   float x2 = start.x + x0 - b;
   float y2 = start.y + y0 + a;
   float x3 = start.x + x0 + b;
   float y3 = start.y + y0 - a;
   Path path = new Path();
   path.moveTo(x1, y1);
   path.lineTo(x2, y2);
   path.lineTo(x3, y3);
   path.close();
   canvas.drawPath(path, paint);
 }