コード例 #1
0
ファイル: Line.cs プロジェクト: RBLjoseMota/Nucleus
        /// <summary>
        /// Extend this line to meet (as closely as possible) another.
        /// The start or end vertex of this line (whichever will result in the smallest
        /// overall movement) will be moved to meet the other at the closest point.
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public bool ExtendToLine(Line other)
        {
            Vector pt = Axis.ClosestPoint(StartPoint, Direction, other.StartPoint, other.Direction);

            if (pt.IsValid())
            {
                double t = ClosestParameter(pt);
                if (t < 0.5)
                {
                    Start.Position = pt;
                }
                else
                {
                    End.Position = pt;
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #2
0
        /// <summary>
        /// Calculate the data needed for initialising a circle from 3 points
        /// </summary>
        /// <param name="pt0"></param>
        /// <param name="pt1"></param>
        /// <param name="pt2"></param>
        /// <returns></returns>
        private static Vector[] Calculate3PtCSystem(ref Vector pt0, ref Vector pt1, ref Vector pt2, ref double radius)
        {
            Vector v01 = (pt1 - pt0);
            Vector v12 = (pt2 - pt1);
            //Find mid-points
            Vector mid01  = pt0.Interpolate(pt1, 0.5);
            Vector mid12  = pt1.Interpolate(pt2, 0.5);
            Vector normal = v01.Cross(v12).Unitize();
            //Find perpendicular axes
            Vector axis1 = v01.Cross(normal);
            Vector axis2 = v12.Cross(normal);
            //FInd intersection:
            Vector origin = Axis.ClosestPoint(mid01, axis1, mid12, axis2);
            Vector vO0    = pt0 - origin;

            radius = vO0.Magnitude();
            if (radius == 0)
            {
                return new Vector[] { pt0, Vector.UnitZ, Vector.UnitX }
            }
            ;                                                                         //Zero-radius circle!
            return(new Vector[] { origin, normal, vO0 / radius });
        }