我在画布上有一个Line(,),即使它可能会歪斜,我要做的就是相对于具有相同线长的旧Line(,)绘制一条新的平行线。 尝试过这>>>>
double d = getLength(x1, y1, x2, y2);
double m = getSlope(x1, y1, x2, y2);
double r = Math.sqrt(1 + Math.pow(m, 2));
double endX = x + d / r;
double endY = y + ((d * m) / r);
return new double[]{x, y, endX, endY};
答案 0 :(得分:0)
要制作平行线段,您需要构建所需长度的垂直向量。 请注意,对于分段的两面都有两种解决方案
dx = x2 - x1
dy = y2 - y1
len = sqrt(dx*dx+dy*dy)
perpx = -dy * distance / len
perpy = dx * distance / len
// "left" line start
x1' = x1 + perpx
y1' = y1 + perpy
// "left" line end
x2' = x2 + perpx
y2' = y2 + perpy
// "right" line
x1'' = x1 - perpx
y1'' = y1 - perpy
x2'' = x2 - perpx
y2'' = y2 - perpy