2017-10-02 34 views
0

Polyline3dから領域を作成しようとしていますが、メソッドRegion.CreateFromCurves(curvesSegments)が無効な入力エラーを返します。私は3日間近く頭を撫でていましたが、この問題について合理的な説明は見つかりませんでした。ここでエラーを発生させるコードのスニップのセットです:autocad .net CreateFromCurves()無効な入力

Point3dCollection _border = new Point3dCollection(); 
    double _radius; 
    Vector3d _normal 

    // some codes to input value to _radius, _normal 

    // creating a hexagon border here that contains 6 coplanar points 
    public void CreateBorder() 
    { 
     _border.Clear(); 
     Vector3d vect = new Vector3d(_radius, 0, 0); 
     for (int index = 0; index < _count; index++) 
     { 
      _border.Add (_center + vect); 
      vect = vect.RotateBy(_angle, _normal); 
     } 
    } 

    public Region CreateTopBottom(bool isBottom) 
    { 
     Polyline3d poly = new Polyline3d(Poly3dType.SimplePoly, _border, true); 
     DBObjectCollection curves = new DBObjectCollection(); 
     curves.Add(poly); 
     DBObjectCollection regions = Region.CreateFromCurves(curves); 
     regions Region region = regions[0] as Region; 
     if (!isBottom) region.TransformBy(Matrix3d.Displacement(_normal * _height)); 
     return region; 
    } 

私は、このように、それはエラーとなり、(Point3dCollection)コンパイラが_borderで私の点を考慮している疑いが同一平面上にありません。しかし、私のポイントは、あなたが見ることができるように、完全に同一平面上にありますが、私はコンパイラに「知らせる」方法を知らないのです。容疑者は正しいのですか?これをどうすれば解決できますか?すべて前もってありがとうございます

答えて

0

代わりにポリライン(とPoint2dCollection)を使用する必要があります。

Point2dCollection _border = new Point2dCollection(); 
    Vector3d _normal; 
    int _count; 
    Point3d _center; 
    double _radius; 
    double _height; 
    Plane _plane; // new Plane(Point3d.Origin, _normal) 

    public void CreateBorder() 
    { 
     Point2d center = _center.Convert2d(_plane); 
     double angle = 2 * Math.PI/_count; 
     _border.Clear(); 
     for (int i = 0; i < _count; i++) 
     { 
      double a = i * angle; 
      _border.Add(new Point2d(center.X + _radius * Math.Cos(a), center.Y + _radius * Math.Sin(a))); 
     } 
    } 

    public Region CreateTopBottom(bool isBottom) 
    { 
     Region region = null; 
     double elevation = _center.TransformBy(Matrix3d.WorldToPlane(_plane)).Z; 
     using (Polyline pline = new Polyline(_border.Count)) 
     { 
      for (int i = 0; i < _border.Count; i++) 
      { 
       pline.AddVertexAt(i, _border[i], 0.0, 0.0, 0.0); 
      } 
      pline.Closed = true; 
      pline.TransformBy(Matrix3d.PlaneToWorld(_plane)); 
      pline.Elevation = isBottom ? elevation : elevation + _height; 
      var curves = new DBObjectCollection() { pline }; 
      var regions = Region.CreateFromCurves(curves); 
      region = (Region)regions[0]; 
     } 
     return region; 
    } 

しかし、どのようなあなたのコードで間違っていることは、あなたがPoint3dCollection(_border)を構築する方法です。 Vector3d(_radius、0、0)は_normalベクトルに垂直になるように変換する必要があります。 Vector3dは不変なので、Vector3d.TransformBy()メソッドは副作用がなく、新しいVector3dを返します。この値でvectを再定義する必要があります。

public void CreateBorder() 
{ 
    double angle = 2 * Math.PI/_count; 
    _border.Clear(); 
    Plane plane = new Plane(Point3d.Origin, _normal); 
    Vector3d vect = new Vector3d(_radius, 0.0, 0.0).TransformBy(Matrix3d.PlaneToWorld(plane)); 
    for (int i = 0; i < _count; i++) 
    { 
     _border.Add(_center + vect); 
     vect = vect.TransformBy(Matrix3d.Rotation(angle, _normal, Point3d.Origin)); 
    } 
} 
+0

IはPoint3dCollectionを使用する理由は、他のコードは、この私は動的法線ベクトルとジギングプロセスにこれを適用する2からの利益とすることができる1です。 Point3dCollectionを使用する方法がありますか、それともPoint2dCollectionを使用し、それに応じてリージョンを変換する必要がありますか(他のコードに対して多くの作業を行う必要があります) –

+0

私はPoint3dCollectionの構築方法に何が間違っていたのか説明しようと私の返信を編集しました。以前のコードで修正されたCreateBorder()メソッドを使用して、Polyline3dから領域を作成することができます。また、各Point3dをPoint2dに変換してポリラインを作成することもできます。 – gileCAD

+0

法線ベクトルの問題を説明していただきありがとうございます。それはまさに私のコードをいつかクラッシュさせる原因になります。私が気づかないと予期せぬ結果が生じることがあります。 –

関連する問題