Esempio n. 1
0
        public Series CalculateShape()
        {
            double dl = this[_dl] ;
            double dx = this[_dx] ;
            double dy = this[_dy] ;
            double ell = this[_ell] ;
            x1 = this[_x1] ;
            x2 = this[_x2] ;
            y2 = this[_y2] ;

            if (dl <= dx)
                return null;

            double C = Math.Sqrt(24 * (dl - dx) / (dx* dx * dx));

            var A = new SingleVariableEq(i => 2 * Math.Sinh(dx * i * .5) - i *dl);

            var B = new SingleVariableEq(i => dx * Math.Cosh(dx * i * .5) - dl);
            var D = A.NewtonRaphson(B, C, 0, C * 1.1, 1.0e-12, 100);

            double x, y = 0;
            double x0 = ((x1 + x2) - Math.Log((ell + dy) / (ell - dy)) / C) * 0.5;
            double y0 = y2 - Math.Cosh((x2 - x0) * C) / C;
            x = x1;
            Series ser = new Series("rope");
            dx = .01;
            while (x < x2) {
                y = Math.Cosh((x - x0) * C) / C + y0;
                ser.Points.Add(new DataPoint(x, y));
                x += dx;
            }
            x = x2;
            ser.Points.Add(new DataPoint(x, y));
            ser.ChartType = SeriesChartType.Point;
            return ser;
        }
Esempio n. 2
0
        public double GetTension()
        {
            double dl = this[_dl];
            double dx = this[_dx];
            double dy = this[_dy];
            double ell = this[_ell];
            x1 = this[_x1];
            x2 = this[_x2];
            y2 = this[_y2];
            double y1 = this[_y1];

            if (dl <= dx)
                return double.MinValue;
            //f(T) =
            var A = new SingleVariableEq(t => 2 * t * Math.Sinh((x2- x1) / (2*t)) - Math.Sqrt(ell.Sqrd() - (y2 - y1).Sqrd()));
            //f'(T) =
            var B = new SingleVariableEq(t => (2 * Math.Sinh((x2 - x1) / 2 * t) * t - (x2 - x1) * Math.Cosh((x2 - x1) / 2 * t)) / t);

            var lowerBoundOnT = Math.Sqrt((x2 - x1).Sqrd() / ((Math.Sqrt(ell.Sqrd() - (y2 - y1).Sqrd()) - (x2 - x1))* 24));
            var tension = A.NewtonRaphson(lowerBoundOnT + .1, lowerBoundOnT, 10, 1.0e-12, 100);
            //Todo: test the value of the tension and don't return a bad value
            return tension;
        }
 //A bug popped up in this method, not sure why.
 private double SolveWithNewtonRaphson(double x, double y)
 {
     var t2 = new SingleVariableEq(i => y / x - A * (Math.Log(1 - B * Math.Sqrt(1 + i.Sqrd())) + B * Math.Sqrt(1 + i.Sqrd())) - i);
     double C = Math.Exp(-(-y / x + 1 + Math.Sqrt(1 / B.Sqrd() - 1) / A));
     double initApprox1 = -Math.Sqrt((1 - C).Sqrd() / B.Sqrd() - 1);
     double initApprox2 = Math.Sqrt((1 - C).Sqrd() / B.Sqrd() - 1);
     var deriv = new SingleVariableEq(i => (A * B.Sqrd() * i) / (1 - B * Math.Sqrt(1 + i.Sqrd())) - 1);
     var theta = Math.Atan(t2.NewtonRaphson(deriv, 0, initApprox1, initApprox2, 1.0e-10, 500));
     return theta;
 }