绘制箭头时偏移路径

Offset Path when drawing arrow

我正在通过执行以下操作绘制箭头:

deltaX = this.mPoints[1].x - this.mPoints[3].x;
deltaY = this.mPoints[1].y - this.mPoints[3].y;

frac = (float) 0.1;

point_x_1 = this.mPoints[3].x + (1 - frac) * deltaX + frac * deltaY;
point_y_1 = this.mPoints[3].y + (1 - frac) * deltaY - frac * deltaX;

point_x_2 = this.mPoints[1].x;
point_y_2 = this.mPoints[1].y;

point_x_3 = this.mPoints[3].x + (1 - frac) * deltaX - frac * deltaY;
point_y_3 = this.mPoints[3].y + (1 - frac) * deltaY + frac * deltaX;

Path path = new Path();
path.setFillType(Path.FillType.EVEN_ODD);
path.moveTo(point_x_1,  point_y_1);
path.lineTo(point_x_2, point_y_2);
path.lineTo(point_x_3, point_y_3);
path.lineTo(point_x_1, point_y_1);
path.lineTo(point_x_1, point_y_1);

path.close();

canvas.drawLine(this.mPoints[3].x, this.mPoints[3].y, this.mPoints[1].x, this.mPoints[1].y, this.mPaint);
canvas.drawPath(path, mPaint);

这是我得到的结果:

如您所见,我画的线在箭头后面突出。

我的问题:

我如何修改我目前所拥有的内容以避免在箭头后面看到该线。

我试过 path.offset(-30,30); 各种值,但它没有用,因为线的角度每次都会改变。

使线条在当前绘制线条的 90% 处结束(这是 1 - frac,因此线条应该在箭头三角形的底部结束):

deltaX = this.mPoints[1].x - this.mPoints[3].x;
deltaY = this.mPoints[1].y - this.mPoints[3].y;

frac = (float) 0.1;

point_x_1 = this.mPoints[3].x + (1 - frac) * deltaX + frac * deltaY;
point_y_1 = this.mPoints[3].y + (1 - frac) * deltaY - frac * deltaX;

point_x_2 = this.mPoints[1].x;
point_y_2 = this.mPoints[1].y;

point_x_3 = this.mPoints[3].x + (1 - frac) * deltaX - frac * deltaY;
point_y_3 = this.mPoints[3].y + (1 - frac) * deltaY + frac * deltaX;

line_end_x = this.mPoints[1].x - frac * deltaX; // This
line_end_y = this.mPoints[1].y - frac * deltaY;

Path path = new Path();
path.setFillType(Path.FillType.EVEN_ODD);
path.moveTo(point_x_1,  point_y_1);
path.lineTo(point_x_2, point_y_2);
path.lineTo(point_x_3, point_y_3);
path.lineTo(point_x_1, point_y_1);
path.lineTo(point_x_1, point_y_1);

path.close();

// line_end_* instead of this.mPoints[1].*
canvas.drawLine(this.mPoints[3].x, this.mPoints[3].y, line_end_x, line_end_y, this.mPaint);
canvas.drawPath(path, mPaint);

我一直无法考数学,但我认为它是正确的。试一试。