Пример #1
1
    /**
     * divideCrvsByDeltaTan : Curve[] * double -> LinkedList<Plane>
     * REQUIRES: theta > 0
     * ENSURES: divideCrvsByDeltaTan(crvs, theta) returns a linked list of planes
     *          along the curves s.t. there is a plane at every point along
     *          the curve where the change in the tangent vector between
     *          two points is greater than theta.
    **/
    private IEnumerable<Point3d> DivByAngle(Curve crv, double angle)
    {

      //initialize parameters
      double theta = angle;
      Interval dom = crv.Domain;
      double stepSize = Math.Abs(dom.Length) * Constants.AbsoluteTolerance * Constants.AbsoluteTolerance;

      //initialize list
      List<Point3d> pts = new List<Point3d>();

      Continuity c = Continuity.C1_continuous;
      //initialize data
      
      double rover = dom.Min; //steps along the curve by stepSize

      //Add plane at start point of curve to list
      Point3d pt = crv.PointAt(rover);
      pts.Add(pt);

      //Increment
      Vector3d prevTan = crv.TangentAt(rover);
      double oldRover = rover; //stores the previous rover for comparison
      rover += stepSize;

      while (rover < dom.Max)
      {
        Vector3d currTan = crv.TangentAt(rover);
        //If there is a discontinuity between the oldRover and rover
        //then place a point at the discontinuity and update prevTan.
        double discontinuity;
        bool isDisc = crv.GetNextDiscontinuity(c, oldRover, rover,
          out discontinuity);
        if (isDisc)
        {
          pt = crv.PointAt(discontinuity);
          pts.Add(pt);
          prevTan = crv.TangentAt(discontinuity);
        }

        //If the change in tangent vector is greater than theta,
        //then drop a target at the rover and update prevTan.
        double delta = RhinoMath.ToDegrees(Math.Abs(Vector3d.VectorAngle(prevTan, currTan)));
        if (delta > theta)
        {
          pt = crv.PointAt(rover);
          pts.Add(pt);
          prevTan = currTan;
        }
        //Increment
        oldRover = rover;
        rover += stepSize;
      }

      //Add target at end point of curve
      pt = crv.PointAt(dom.Max);
      pts.Add(pt);
      return pts;
    }