答案 0 :(得分:46)
您要做的是偏移正交方向的坐标。如果你知道向量数学,则将由行的端点之间的距离创建的向量乘以下面的矩阵:
[ 0 -1 ]
[ 1 0 ]
假设第一行的点数为(x1,y1)
,(x2,y2)
,x=x2-x1
,y=y2-y1
。
我们还有L = sqrt(x*x+y*y)
,行的长度(原谅符号)。然后下一行应该被
[ 0 -1 ] [x]
[ 1 0 ] [y]
=> dx = -y / L
,dy = x / L
这是新行的标准化偏移量。
在类似C#的伪代码中:
var x1 = ..., x2 = ..., y1 = ..., y2 = ... // The original line
var L = Math.Sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
var offsetPixels = 10.0
// This is the second line
var x1p = x1 + offsetPixels * (y2-y1) / L
var x2p = x2 + offsetPixels * (y2-y1) / L
var y1p = y1 + offsetPixels * (x1-x2) / L
var y2p = y2 + offsetPixels * (x1-x2) / L
g.MoveTo(x1p,y1p) // I don't remember if this is the way
g.LineTo(x2p,y2p) // to draw a line in GDI+ but you get the idea
答案 1 :(得分:0)
您是否尝试将n减去y1和y2以及将n添加到x1和x2?我猜这可能有用