10

ここに画像の説明を入力

だから私はn点で構成された任意の線(図1に示されている例を参照)を持っています

この線の周りにアウトラインを描きたいので (図 2 を参照)、周囲のポリゴンのポイントを計算する必要があります。

私はライン上で拡張を実行することから始めましたが、これはうまくいきません - 図3を参照してください

これを行う方法に関する提案はありますか?

下の新しい線と現在の位置の上の新しい線を変換し、新しい線をそれぞれ無限に延長して交点として定義するために使用する各線分の法線を計算していると思われますか?

4

5 に答える 5

7

最初に各線を 2 回複製します。各元の線から必要な幅の半分の距離で両側に 1 回ずつです。これにより、画像に緑色の線が表示されます。次に、順番に(番号を付けて)それらを訪問し、未解決の問題に対処する必要があります。

線の輪郭

線が交わらない場合 (2-3、6-7、12-13)、線の結合(青色) を追加します。線の結合は、点を接続するだけのベベル結合(2-3) 、線が交わるまで線を延長する留め継ぎ結合(6-7)、または曲線を作成するラウンド結合です。

線が交わったら、交点 (青い点) を取るだけです。

ラインの端には、エンド キャップ(青色)を追加する必要があります。エンドキャップは、点を結んでバットキャップ(8-9) 、線を少し延長して結んだ突き出しキャップ(1-16)、丸キャップ(図示せず)などがあります。

最終結果はポリゴン (ラウンド結合を含む場合はパス) であり、これをストロークまたは塗りつぶすことができます。

于 2011-04-13T00:05:48.973 に答える
5

線の輪郭点を計算する方法を見つけました。元の線の各ポイントに対して、アウトラインの 2 つのポイントを計算する必要があります。

  1. 元の線 (2 点間) の線分ごとに、法線ベクトル (赤) を計算する必要があります。
  2. ポイントごとに、前後の線分の法線を追加します。これにより、新しいベクトル (緑) が生成されます。
  3. 新しいベクトルを値 k l+1 で除算します。ここで、k l は法線ベクトルの内積です。青いベクトルが得られます。次に、このベクトルを現在のポイントとその反対のベクトルに追加すると、現在のポイントの 2 つのアウトライン ポイントが得られます。

上記の色はこのイメージに対応しています。 ここに画像の説明を入力

この関数は C でプログラムしましたが、Accelerate Framework を使用したため、読みにくいです。ソース コードはこちらで、デモを実行するビデオはこちらでご覧いただけます

于 2011-09-12T21:13:34.457 に答える
0

レンダリングする前にすべての線を作成します。

その場合、次のようにオーバーラップする必要があります。ここに画像の説明を入力

私が描いたものは、明らかに、アウトラインを明らかにするトリミングされたものです.

于 2011-04-12T21:30:14.690 に答える
0

これは、Objective-C でそれを実行している私のコードの一部です (バグがある場合でも、理由がわかりません。どうなるか教えてください...):

  • ポリラインの各エッジを取得し、現在のエッジの垂直方向の右側に最初の配列を作成し (ポリラインと同じように、CCW または CW)、左側に 2 つ目の配列を作成します。
  • エッジごとに、2 つの無限直線 (エッジがセグメントであるため) が交差するポイントをテストします。
  • 最後に、各ポイントを目的の順序で追加してポリゴンを作成します

    - (hOzPolygon2D *) convertToPolygonWithWidth:(double) polyWidth
    {
    
    double shift = polyWidth / 2.;
    
    NSMutableArray *tempEdgesRight = [[[NSMutableArray alloc] init] autorelease];
    NSMutableArray *tempEdgesLeft = [[[NSMutableArray alloc] init] autorelease];
    
    NSMutableArray *tempPolyPoints = [[[NSMutableArray alloc] init] autorelease];
    
    // Move your points on the right by half the desired width
    
    // My edges are already computed in a NSArray* called edges, 
    // but you can use pairs of vectors and adapt all this
    
    for (hOzEdge2D *edge in edges) {
    
    hOzVector2 v = hOzVector2([[edge pointB] x] - [[edge pointA] x], [[edge pointB] y] - [[edge pointA] y]);
    double mag = sqrt (v.x * v.x + v.y * v.y);
    v.x = v.x / mag;
    v.y = v.y / mag;
    
    double temp = v.x;
    v.x = v.y;
    v.y = -temp;
    
    hOzPoint2D *newPointA = [[hOzPoint2D alloc] init];
    [newPointA setX:([[edge pointA] x] + v.x * shift)];
    [newPointA setY:([[edge pointA] y] + v.y * shift)];
    
    hOzPoint2D *newPointB = [[hOzPoint2D alloc] init];
    [newPointB setX:([[edge pointB] x] + v.x * shift)];
    [newPointB setY:([[edge pointB] y] + v.y * shift)];
    
    [tempEdgesRight addObject:[hOzEdge2D edge2DWithPointA:newPointA pointB:newPointB]];
    
    }
    
    // With the same polyline, move on the left
    
    for (int j = [edges count] - 1; j >= 0; j--) {
    
    hOzVector2 v = hOzVector2([[[edges objectAtIndex:j] pointB] x] - [[[edges objectAtIndex:j] pointA] x], [[[edges objectAtIndex:j] pointB] y] - [[[edges objectAtIndex:j] pointA] y]);
    double mag = sqrt (v.x * v.x + v.y * v.y);
    v.x = v.x / mag;
    v.y = v.y / mag;
    
    double temp = v.x;
    v.x = v.y;
    v.y = -temp;
    
    hOzPoint2D *newPointA = [[hOzPoint2D alloc] init];
    [newPointA setX:([[[edges objectAtIndex:j] pointB] x] - v.x * shift)];
    [newPointA setY:([[[edges objectAtIndex:j] pointB] y] - v.y * shift)];
    
    hOzPoint2D *newPointB = [[hOzPoint2D alloc] init];
    [newPointB setX:([[[edges objectAtIndex:j] pointA] x] - v.x * shift)];
    [newPointB setY:([[[edges objectAtIndex:j] pointA] y] - v.y * shift)];
    
    [tempEdgesLeft addObject:[hOzEdge2D edge2DWithPointA:newPointA pointB:newPointB]];
    
    }
    
    
    
    // Add the static points and the intersection points to a points array that will define your polygon
    
    [tempPolyPoints addObject:[[tempEdgesRight objectAtIndex:0] pointA]];  // The first point of the right array
    
    for (int k = 0; k < [tempEdgesRight count] - 1; k++) {
    
    // For this function, see the link below in the answer
    
    hOzPoint2D *inter = [[tempEdgesRight objectAtIndex:k] getIntersectionWithStraight:[tempEdgesRight objectAtIndex:k+1]];   
    
    if (inter == nil) {    // if the edges are parallel, we insert a known point
        [tempPolyPoints addObject:[[tempEdgesRight objectAtIndex:k] pointB]];
    } else {
        [tempPolyPoints addObject:inter];
    }
    }
    
    [tempPolyPoints addObject:[[tempEdgesRight lastObject] pointB]];    // The last point of the right array
    
    [tempPolyPoints addObject:[[tempEdgesLeft objectAtIndex:0] pointA]];
    
    // Then the left array, same thing
    
    for (int k = 0; k < [tempEdgesLeft count] - 1; k++) {
    hOzPoint2D *inter = [[tempEdgesLeft objectAtIndex:k] getIntersectionWithStraight:[tempEdgesLeft objectAtIndex:k+1]];
    
    if (inter == nil) {
        [tempPolyPoints addObject:[[tempEdgesLeft objectAtIndex:k] pointB]];
    } else {
        [tempPolyPoints addObject:inter];
    }
    }
    
    [tempPolyPoints addObject:[[tempEdgesLeft lastObject] pointB]];
    
    // Create your polygon with this new ordered points array.
    hOzPolygon2D *poly = [hOzPolygon2D polygon2DWithArrayOfPoints:tempPolyPoints];
    
    return poly;
    
    }
    

Cコードを使用した交点の説明は次のとおりです。http://alienryderflex.com/intersect/

于 2013-04-09T18:13:09.073 に答える
0

線分の点があれば、各線分に 2 本の平行線を簡単に作成し、それらが線分 (線分ではなく) である場合、次の線分と交差する接続点を計算できます。このサイトは、超高速交差点を計算するために必要なすべてを提供するはずです。

http://www.math.niu.edu/~rusin/known-math/95/line_segs

于 2011-04-12T22:50:25.063 に答える