我正在尝试在任意数量的片段弧上绘制刻度线。该弧是一个GeneralPath
对象。
我想沿着弧线绘制n个刻度线(其中n是算法的输入)。我还需要在弧的起点和终点绘制刻度线。
有没有人知道在哪里可以找到这样的算法?
我正在尝试在任意数量的片段弧上绘制刻度线。该弧是一个GeneralPath
对象。
我想沿着弧线绘制n个刻度线(其中n是算法的输入)。我还需要在弧的起点和终点绘制刻度线。
有没有人知道在哪里可以找到这样的算法?
嗯,一条线是一个二维向量。获取它的方向,计算长度,将其除以n,然后使用起点、方向向量和起点与刻度之间的距离计算刻度的位置。
编辑:
还有一些伪代码:
double unnormalizedDir.x = end.x - start.x;
double unnormalizedDir.y = end.y - start.y;
double length = sqrt(unnormalizedDir.x * unnormalizedDir.x + unnormalizedDir.y * unnormalizedDir.y );
double dir.x = unnormalizedDir.x / length;
double dir.y = unnormalizedDir.y / length;
double tickLength = length / n;
for( int i = 1; i <= n; i++ ) {
double tick.x = start.x + dir.x * i * ticklength;
double tick.y = start.y + dir.y * i * ticklength;
}
double distToNextTick = pathLength / n;
double distLastTickToNextVertex = ... ; //calculate
while( distToNextTick > distLastTickToNextVertex ) {
Point2D nextVertex = ... // get the vertex
distToNextTick -= distLastTickToNextVertex;
distLastTickToNextVertex = ...;// calculate again
}
if( distToNextTick == 0.0 ) {
//the tick is exactly on a vertex
}
else {
//the tick is on the segment starting at the last vertex
//for straight lines calculate as above
//for curves use an appropriate algorithm (depending on the type of curve)
}