给出了一系列的观点,我如何计算5行像素以外的那条线的向量?例如: 考虑:绘制N宽度线?
\
\
\
我怎么能找到
\ \
\ \
\ \
右边的那些载体。
我想弄清楚像Flash这样的程序可以制作粗略的轮廓。
由于
给出了一系列的观点,我如何计算5行像素以外的那条线的向量?例如: 考虑:绘制N宽度线?
\
\
\
我怎么能找到
\ \
\ \
\ \
右边的那些载体。
我想弄清楚像Flash这样的程序可以制作粗略的轮廓。
由于
粗线是多边形。 (让我们忘掉抗锯齿现在)
picture http://img39.imageshack.us/img39/863/linezi.png
开始=行开始=矢量(X1,Y1)
端=行结束=矢量(X2,Y2)
DIR =线方向=端 - 开始=矢量(X2-X1,Y2-Y1)
NDIR =归一化的方向= DIR * 1.0 /长度(DIR)
PERP =垂直于方向矢量=(dir.x,-dir.y)
nperp =归一化垂直= perp * 1.0 /长度(perp)
perpoffset = nperp * W * 0.5
diroffset = NDIR * W * 0.5
(可以容易地删除一个归一化并且通过从其他采取垂直计算的偏移量中的一个)
P0,P1, P2,P3 =多边形点:
P0 = START + perpoffset - diroffset
P1 =开始 - perpoffset - diroffset
P2 =端+ perpoffset + diroffset
P3 =端 - perpoffset + diroffset
P.S.你是我将要解释这些东西的最后一个人。 这些事情应该直观地理解。
做的一个直线的方式是找到垂直(N)行到原来的线,以在该方向上的5个像素步骤,然后找到垂直于垂直中的该点
| |
--+-----+---N
| |
| |
与非直线做到这一点的方法是很多的直线来近似,或者如果你有行的分析表示,找到某种解析解的类似的方式在一个的直线。
试试这个未经测试的伪代码:
# Calculate the "Rise" and "run" (slope) of your input line, then
# call this function, which returns offsets of x- and y-intercept
# for the parallel line. Obviously the slope of the parallel line
# is already known: rise/run.
# returns (delta_x, delta_y) to be added to intercepts.
adjacent_parallel(rise, run, distance, other_side):
negate = other_side ? -1 : 1
if rise == 0:
# horizontal line; parallel is vertically away
return (0, negate * distance)
elif run == 0:
# vertical line; parallel is horizontally away
return (negate * distance, 0)
else:
# a perpendicular radius is - run/rise slope with length
# run^2 + rize^2 = length^2
nrml = sqrt(run*run + rise*rise)
return (negate * -1 * run/nrml, negate * rise/nrml)
如SIGTERM显示了他不错的图,你将要得到的目标线两侧的线条:所以在thickness/2
传递距离和调用两次,用other_side=true
一次,并绘制以“抽象线”为中心的厚度。
一个向量总是按照定义,是一条很好的直线......它甚至是一条无限长,很好的直线。另外,五个像素在什么方向?在右边?沿着正常到第一线? – 2010-06-05 20:15:47
这是功课还是个人项目? – 2010-06-05 20:15:51
如果原始系列的线段不是简单的垂直线,您会希望发生什么? – SamB 2010-06-05 20:17:05