예제 #1
0
 /// <summary>
 /// Splits (divides) the curve at a series of specified parameters. 
 /// The parameter must be in the interior of the curve's domain.
 /// </summary>
 /// <param name="t">
 /// Parameters to split the curve at in the interval returned by Domain().
 /// </param>
 /// <returns>
 /// Multiple curves on success, null on failure.
 /// </returns>
 public Curve[] Split(IEnumerable<double> t)
 {
   Interval domain = Domain;
   RhinoList<double> parameters = new RhinoList<double>(t);
   parameters.Add(domain.Min);
   parameters.Add(domain.Max);
   parameters.Sort();
   RhinoList<Curve> rc = new RhinoList<Curve>();
   for (int i = 0; i < parameters.Count - 1; i++)
   {
     double start = parameters[i];
     double end = parameters[i + 1];
     if ((end - start) > RhinoMath.ZeroTolerance)
     {
       Curve trimcurve = Trim(start, end);
       if (trimcurve != null)
         rc.Add(trimcurve);
     }
   }
   return rc.Count == 0 ? null : rc.ToArray();
 }
예제 #2
0
    /// <summary>
    /// Gets a collection of perpendicular frames along the curve. Perpendicular frames 
    /// are also known as 'Zero-twisting frames' and they minimize rotation from one frame to the next.
    /// </summary>
    /// <param name="parameters">A collection of <i>strictly increasing</i> curve parameters to place perpendicular frames on.</param>
    /// <returns>An array of perpendicular frames on success or null on failure.</returns>
    /// <exception cref="InvalidOperationException">Thrown when the curve parameters are not increasing.</exception>
    public Plane[] GetPerpendicularFrames(IEnumerable<double> parameters)
    {
      RhinoList<double> ts = new RhinoList<double>();
      double t0 = double.MinValue;

      foreach (double t in parameters)
      {
        if (t <= t0)
          throw new InvalidOperationException("Curve parameters must be strictly increasing");

        ts.Add(t);
        t0 = t;
      }
      // looks like we need at least two parameters to have this function make sense
      if (ts.Count < 2)
        return null;

      double[] _parameters = ts.ToArray();
      int count = _parameters.Length;
      Plane[] frames = new Plane[count];

      IntPtr pConstCurve = ConstPointer();
      int rc_count = UnsafeNativeMethods.RHC_RhinoGet1RailFrames(pConstCurve, count, _parameters, frames);
      if (rc_count == count)
        return frames;

      if (rc_count > 0)
      {
        Plane[] rc = new Plane[rc_count];
        Array.Copy(frames, rc, rc_count);
        return rc;
      }
      return null;
    }