2017-10-02 8 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; 
    } 

내가 컴파일러가 _border (A Point3dCollection) 내 포인트를 고려하는 것이 의심이 동일 평면하지 따라서는 오류가 발생, 다음은 오류를 생성 코드의 싹둑 세트입니다. 그러나, 당신이 볼 수 있듯이, 내 관점은 완벽하게 동일 평면이지만 컴파일러에 "알리는"방법을 모른다. 용의자가 맞습니까? 이 문제를 어떻게 해결할 수 있습니까? 모두 미리 감사하십시오.

답변

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

내가 Point3dCollection을 사용하려는 이유는 1입니다. 다른 코드는이 점과 2의 이점을 얻을 수 있습니다.이 점을 동적 법선 벡터를 사용하는 지그 프로세스에 적용하고 싶습니다. Point3dCollection을 사용하는 방법이 있습니까? 아니면 Point2dCollection을 사용해야하고 그에 따라 영역을 변형해야합니다 (이렇게하면 다른 코드에 대해 많은 작업을해야합니다). –

+0

나는 내 대답을 편집하여 Point3dCollection을 구축하는 방법에있어 잘못된 점을 설명하려고했습니다. 이전 코드에서 수정 된 CreateBorder() 메서드를 사용하여 Polyline3d에서 영역을 만들 수 있습니다. 각 Point3d를 Point2d로 변환하여 폴리 라인을 만들 수도 있습니다. – gileCAD

+0

정상적인 벡터 문제를 설명해 주셔서 감사합니다. 그게 내 코드를 언젠가는 충돌로 만드는 원인이되고, 때로는 눈치 채지 못하게 예기치 않은 결과를 낳습니다. –