示例#1
0
        /// offset-ellipse Brent solver

        /// offfset-ellipse solver using Brent's method
        /// find the EllipsePosition that makes the offset-ellipse point be at p
        /// this is a zero of Ellipse::error()
        /// returns number of iterations
        ///
        /// called (only?) by BullCutter::singleEdgeDropCanonical()
        public int solver_brent()
        {
            int             iters = 1;
            EllipsePosition apos  = new EllipsePosition();            // Brent's method requires bracketing the root in [apos.diangle, bpos.diangle]
            EllipsePosition bpos  = new EllipsePosition();

            apos.setDiangle(0.0);
            Debug.Assert(apos.isValid());
            bpos.setDiangle(3.0);
            Debug.Assert(bpos.isValid());
            if (Math.Abs(error(apos)) < DefineConstants.OE_ERROR_TOLERANCE)
            {                                    // if we are lucky apos is the solution
                EllipsePosition1.CopyFrom(apos); // and we do not need to search further.
                find_EllipsePosition2();
                return(iters);
            }
            else if (Math.Abs(error(bpos)) < DefineConstants.OE_ERROR_TOLERANCE)
            {             // or bpos might be the solution?
                EllipsePosition1.CopyFrom(bpos);
                find_EllipsePosition2();
                return(iters);
            }
            // neither apos nor bpos is the solution
            // but root is now bracketed, so we can use brent_zero
            Debug.Assert(error(apos) * error(bpos) < 0.0);
            // this looks for the diangle that makes the offset-ellipse point y-coordinate zero
            double dia_sln = ocl.GlobalMembers.brent_zero(apos.diangle, bpos.diangle, 3E-16, DefineConstants.OE_ERROR_TOLERANCE, this);             // brent_zero.hpp

            EllipsePosition1.setDiangle(dia_sln);
            Debug.Assert(EllipsePosition1.isValid());
            // because we only work with the y-coordinate of the offset-ellipse-point, there are two symmetric solutions
            find_EllipsePosition2();
            return(iters);
        }
示例#2
0
        /// return a normalized normal vector of the ellipse at the given EllipsePosition
//C++ TO C# CONVERTER WARNING: 'const' methods are not available in C#:
//ORIGINAL LINE: virtual Point normal(const EllipsePosition& pos) const
        public virtual Point normal(EllipsePosition pos)
        {
            Debug.Assert(pos.isValid());
            Point n = new Point(b * pos.s, a * pos.t, 0);

            n.normalize();
            return(new ocl.Point(n));
        }