Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 绘制箭头时的偏移路径_Java_Android_Android Canvas - Fatal编程技术网

Java 绘制箭头时的偏移路径

Java 绘制箭头时的偏移路径,java,android,android-canvas,Java,Android,Android Canvas,我正在通过执行以下操作绘制箭头: 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) * d

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

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);