コード例 #1
0
        public static Point GetLineCross(this LineObj l0, LineObj l1)
        {
            double u;

            // do both lines exhist?
            if (l0 == null && l1 == null)
            {
                return(null);
            }
            // are both lines vertical?
            if (double.IsNaN(l0.c) && double.IsNaN(l1.c))
            {
                // no intersection; is parallel, not vertical
                if (l0.a.Equals(l1.a))
                {
                    return(null);
                }
                // common X value
                u = (l1.b - l0.b) / (l0.a - l1.a);
                return(new Point(u, l0.a * u + l0.b));
            }

            // l0.c != undefined
            // wasn't fun figuring this out
            // should write some notes on this Object usage.
            if (!double.IsNaN(l0.c))
            {
                if (!double.IsNaN(l1.c))
                {
                    // both lines vertical, intersection does not exhist
                    return(null);
                }
                else
                {
                    // return the point on l1 with x = l0.c
                    return(new Point(l0.c, (l1.a * l0.c + l1.b)));
                }
            }
            else if (!double.IsNaN(l1.c))
            {
                // l0.c as it was tested above
                // return the point on l0 with x = l1.c
                return(new Point(l1.c, (l0.a * l1.c + l0.b)));
            }
            return(null);
        }
コード例 #2
0
        public static Point GetLineCross(this LineObj l0, LineObj l1)
        {
            double u;
              // do both lines exhist?
              if (l0==null && l1==null) return null;
              // are both lines vertical?
              if (double.IsNaN(l0.c) && double.IsNaN(l1.c))
              {
            // no intersection; is parallel, not vertical
            if (l0.a.Equals(l1.a)) return null;
            // common X value
            u = (l1.b - l0.b) / (l0.a - l1.a);
            return new Point(u, l0.a * u + l0.b);
              }

              // l0.c != undefined
              // wasn't fun figuring this out
              // should write some notes on this Object usage.
              if (!double.IsNaN(l0.c)) {
            if (!double.IsNaN(l1.c)) {
              // both lines vertical, intersection does not exhist
              return null;
            }
            else
            {
              // return the point on l1 with x = l0.c
              return new Point(l0.c, (l1.a * l0.c + l1.b));
            }
              }
              else if (!double.IsNaN(l1.c)) {
            // l0.c as it was tested above
            // return the point on l0 with x = l1.c
            return new Point(l1.c, (l0.a * l1.c + l0.b));
              }
              return null;
        }
コード例 #3
0
ファイル: Draw.cs プロジェクト: VRDate/modest-smf-vstnet
        int DrawCubicBézier(IApiDraw api, Vertex pt)
        {
            Tuple <Point, LineObj> curt = null; // Tangent Object (LineObj)?
            Tuple <Point, LineObj> next;        // Tangent Object (LineObj)?
            int    total    = 0;                // int or long
            int    nSegment = numSegments < 2 ? 4 : this.numSegments;
            double tstep    = 1 / nSegment;

            curt = new Tuple <Point, LineObj>(pt.p0, LineObj.GetLine(pt.p0, pt.p1));
            if (api != null)
            {
                api.moveTo(pt.p0);
            }
            for (int i = 1; i < nSegment; i++)
            {
                next   = pt.CubicTangent(Convert.ToInt32(i * tstep));                                  // next tangent
                total += SliceCubicBézierSegments(api, pt, (i - 1) * tstep, i * tstep, curt, next, 0); // current segment
                if (total > numSegments)
                {
                }
                curt = next;
            }
            return(total);
        }