예제 #1
0
        public override Vector3d GetOrientation(Curve curve, double t)
        {
            double angle;

            if (t <= m_guides.First().Parameter)
            {
                angle = m_guides.First().AngularOffset;
            }
            else if (t >= m_guides.Last().Parameter)
            {
                angle = m_guides.Last().AngularOffset;
            }

            int res = Array.BinarySearch(m_guides.ToArray(), t);

            int    max = m_guides.Length - 1;
            double mu;

            if (res < 0)
            {
                res = ~res;
                res--;
            }

            if (res >= 0 && res < max)
            {
                mu    = (t - m_guides[res].Parameter) / (m_guides[res + 1].Parameter - m_guides[res].Parameter);
                angle = Interpolation.Lerp(m_guides[res].AngularOffset, m_guides[res + 1].AngularOffset, mu);
            }
            else if (res < 0)
            {
                angle = m_guides.First().AngularOffset;
            }
            else if (res >= max)
            {
                angle = m_guides.Last().AngularOffset;
            }
            else
            {
                throw new Exception("It shouldn't come to this...");
                //angle = 0.0;
            }

            Plane RMF;

            if (Math.Abs(t - curve.Domain.Min) < Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance)
            {
                RMF = curve.GetPerpendicularFrames(new double[] { curve.Domain.Min, curve.Domain.Max }).First();
            }
            else if (Math.Abs(t - curve.Domain.Max) < Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance)
            {
                RMF = curve.GetPerpendicularFrames(new double[] { curve.Domain.Min, curve.Domain.Max }).Last();
            }
            else if (t > curve.Domain.Min)
            {
                RMF = curve.GetPerpendicularFrames(new double[] { curve.Domain.Min, t }).Last();
            }
            else
            {
                RMF = curve.GetPerpendicularFrames(new double[] { t, curve.Domain.Max }).First();
            }

            //crv.PerpendicularFrameAt(t, out RMF);
            Vector3d vec = RMF.YAxis;

            vec.Transform(Rhino.Geometry.Transform.Rotation(angle, RMF.ZAxis, RMF.Origin));

            return(NormalizeVector(curve, t, vec));
        }
예제 #2
0
        public Point3d[] ToBeamSpace(IList <Point3d> pts, bool approximate = false, int num_samples = 100)
        {
            Point3d[] m_output_pts = new Point3d[pts.Count];

            Plane   m_plane;
            Point3d m_temp;
            double  t;

            if (approximate)
            {
                double mu;

                var tt      = Centreline.DivideByCount(num_samples, true);
                var lengths = tt.Select(x => Centreline.GetLength(new Interval(Centreline.Domain.Min, x))).ToArray();

                //for (int i = 0; i < pts.Count; ++i)
                Parallel.For(0, pts.Count, i =>

                {
                    Centreline.ClosestPoint(pts[i], out t);
                    m_plane = GetPlane(t);
                    m_plane.RemapToPlaneSpace(pts[i], out m_temp);

                    var res = Array.BinarySearch(tt, t);
                    if (res < 0)
                    {
                        res = ~res;
                        res--;
                    }

                    if (res >= 0 && res < tt.Length - 1)
                    {
                        mu       = (t - tt[res]) / (tt[res + 1] - tt[res]);
                        m_temp.Z = Interpolation.Lerp(lengths[res], lengths[res + 1], mu);
                    }
                    else if (res < 0)
                    {
                        m_temp.Z = lengths.First();
                    }
                    else if (res >= (tt.Length - 1))
                    {
                        m_temp.Z = lengths.Last();
                    }

                    m_output_pts[i] = m_temp;
                }
                             );
            }
            else
            {
                //for (int i = 0; i < pts.Count; ++i)
                Parallel.For(0, pts.Count, i =>
                {
                    Centreline.ClosestPoint(pts[i], out t);
                    m_plane = GetPlane(t);
                    m_plane.RemapToPlaneSpace(pts[i], out m_temp);
                    m_temp.Z = Centreline.GetLength(new Interval(Centreline.Domain.Min, t));

                    m_output_pts[i] = m_temp;
                }
                             );
            }

            return(m_output_pts);
        }