public string CalculateCircleArea()
        {
            CircleModel model = new CircleModel();

            mview.ResultText = model.getArea(double.Parse(mview.RadiusText)).ToString();
            return(mview.ResultText.ToString());
        }
Example #2
0
        public static AreaResult GetArea(params float[] values)
        {
            var result = new AreaResult();
            var length = values.Length;

            switch (length)
            {
            case 1:
            {
                var currentGetter = GetAreaGetter(AllFigures.Circle);
                var model         = new CircleModel {
                    Radius = values.FirstOrDefault()
                };
                return(currentGetter.GetArea(model));
            }

            case 3:
            {
                var currentGetter = GetAreaGetter(AllFigures.Triangle);
                var model         = new TriangleModel {
                    FirstLength = values[0], SecondLength = values[1], ThirdLength = values[2]
                };
                return(currentGetter.GetArea(model));
            }

            default:
            {
                result.Error = new AreaGetterException($"Нет реализации для value с длинной = {length}");
            }
            break;
            }

            return(result);
        }
Example #3
0
        public string Get(double radiusD,
                          double widthF,
                          double heightF,
                          double lengthF)
        {
            string result = $"calculate me {radiusD} {widthF} {heightF} {lengthF}";

            if (DoubleValueVerifier.IsDoubleArrayValid(
                    new double[] { radiusD, widthF, heightF, lengthF }))
            {
                CircleModel door   = new CircleModel(radiusD);
                CubeModel   fridge = new CubeModel(widthF, heightF, lengthF);

                result =
                    CalculatorMain.CubeToCircle(door, fridge)
                        ?
                    $"true, door: {door.ToString()}; fridge: {fridge.ToString()}"
                        :
                    $"false, door: {door.ToString()};fridge: {fridge.ToString()}";
            }
            else
            {
                result += "; Some bad value(s)!";
            }

            return(result);
        }
Example #4
0
        public CircleModel FittingCircleWithLeastSquares(double[][] points)
        {
            var ols = new OrdinaryLeastSquares
            {
                UseIntercept = true,
                IsRobust     = true
            };
            var outputs    = points.Select(t => Math.Pow(t[0], 2) + Math.Pow(t[1], 2)).ToArray();
            var regression = ols.Learn(points, outputs);

            // As result, we will be given the following:
            var a = regression.Weights[0] / 2; // a = 0
            var b = regression.Weights[1] / 2; // b = 0
            var c = regression.Intercept;      // c = 1

            c = Math.Sqrt(c + a * a + b * b);

            var midPoint = points[points.Length / 2];
            var result   = new CircleModel
            {
                X       = a,
                Y       = b,
                XSource = midPoint[0],
                YSource = midPoint[1],
                R       = c,
                R_geo   = GeoTools.CalculateDistance(midPoint[1], midPoint[0], b, a)
            };

            return(result);
        }
        private float GetArea(CircleModel circle)
        {
            var areaGetter = new CircleAreaGetter();
            var areaResult = areaGetter.GetArea(circle);

            return(areaResult.ResultArea);
        }
Example #6
0
        private RenderContext2D(ICamera camera)
        {
            this.camera = camera;

            rectangle = new RectangleModel(1, 1);
            circle    = new CircleModel(1);
        }
Example #7
0
        internal static CircleModel Polyline2DModel(Polyline2d line, AttributeModel atModel)
        {
            CircleModel dbModel = new CircleModel();


            double length = line.Length;

            dbModel.pointList = MethodCommand.GetArcPoints(line, length);

            dbModel.Color = line.ColorIndex == 256 ? MethodCommand.GetLayerColorByID(line.LayerId) : System.Drawing.ColorTranslator.ToHtml(line.Color.ColorValue);
            foreach (AttributeItemModel item in atModel.attributeItems)
            {
                string attValue = "";

                switch (item.AtItemType)
                {
                case AttributeItemType.Area:
                    attValue = line.Area.ToString();
                    break;

                case AttributeItemType.TxtHeight:

                    break;

                case AttributeItemType.Color:
                    attValue = dbModel.Color;
                    break;

                case AttributeItemType.Content:

                    break;

                case AttributeItemType.LayerName:
                    attValue = line.Layer;
                    break;

                case AttributeItemType.LineScale:
                    attValue = line.LinetypeScale.ToString();
                    break;

                case AttributeItemType.LineType:
                    attValue = GetLayerLineTypeByID(line);
                    break;

                case AttributeItemType.Overallwidth:
                    attValue = line.ConstantWidth.ToString();
                    break;

                case AttributeItemType.TotalArea:

                    break;
                }
                if (!string.IsNullOrEmpty(attValue))
                {
                    item.AtValue = attValue;
                    dbModel.attItemList.Add(item);
                }
            }
            return(dbModel);
        }
        public static bool CylinderToCircle(CircleModel door, CylinderModel fridge)
        {
            bool result = false;

            if (fridge.Diameter < door.Diameter)
            {
                result = true;
            }

            return(result);
        }
        public static bool CubeToCircle(CircleModel door, CubeModel fridge)
        {
            bool result = false;

            if (fridge.Diagonal < door.Diameter)
            {
                result = true;
            }

            return(result);
        }
        /// <summary>
        /// Return Circle area
        /// </summary>
        /// <returns>Circle area</returns>
        public AreaResult GetArea(CircleModel circle)
        {
            if (circle == null)
            {
                return(new AreaResult
                {
                    Error = new AreaGetterException("Не инстанциированная модель.")
                });
            }

            return(GetArea(circle.Radius));
        }
        private RigidBodyModel readRigidBody(OrderedDictionary bodyElem)
        {
            RigidBodyModel rbModel = new RigidBodyModel();

            rbModel.name      = (String)bodyElem["name"];
            rbModel.imagePath = (String)bodyElem["imagePath"];

            var bodyElemObject           = bodyElem["origin"] as JObject;
            OrderedDictionary originElem = bodyElemObject.ToObject <OrderedDictionary>();

            rbModel.origin.X = Convert.ToSingle(originElem["x"]);
            rbModel.origin.Y = Convert.ToSingle(originElem["y"]);


            // polygons
            var bEA = bodyElem["polygons"] as JArray;

            for (int i = 0; i < bEA.Count; i++)
            {
                PolygonModel polygon = new PolygonModel();
                rbModel.polygons.Add(polygon);

                var verticesElem = bEA[i] as JArray;
                for (int ii = 0; ii < verticesElem.Count; ii++)
                {
                    OrderedDictionary vertexElem = verticesElem[ii].ToObject <OrderedDictionary>();
                    float             x          = Convert.ToSingle(vertexElem["x"]);
                    float             y          = Convert.ToSingle(vertexElem["y"]);

                    polygon.vertices.Add(new Vector2(x, y));
                }

                polygon.buffer = new Vertices(polygon.vertices.Count);
            }

            // circles

            var circlesElem = bodyElem["circles"] as JArray;

            for (int i = 0; i < circlesElem.Count; i++)
            {
                CircleModel circle = new CircleModel();
                rbModel.circles.Add(circle);

                OrderedDictionary circleElem = circlesElem[i].ToObject <OrderedDictionary>();
                circle.center.X = (float)circleElem["cx"];
                circle.center.Y = (float)circleElem["cy"];
                circle.radius   = (float)circleElem["r"];
            }

            return(rbModel);
        }
Example #12
0
        internal static CircleModel Polyline2DModel(Polyline2d line)
        {
            CircleModel dbModel = new CircleModel();


            double length = line.Length;

            dbModel.pointList = MethodCommand.GetArcPoints(line, length);
            dbModel.isDashed  = GetLayerLineTypeByIDEx(line);

            dbModel.Color = line.ColorIndex == 256 ? MethodCommand.GetLayerColorByID(line.LayerId) : System.Drawing.ColorTranslator.ToHtml(line.Color.ColorValue);
            return(dbModel);
        }
Example #13
0
            public void CircleOfFifths(WebView webView, NameValueCollection parameters)
            {
                var model = new CircleModel(parameters)
                {
                    conv = _currentSettings.conv
                };
                var template = new CircleView()
                {
                    Model = model
                };
                var page = template.GenerateString();

                webView.LoadDataWithBaseURL("file:///android_asset/?page=CircleOfFifths", page, "text/html", "UTF-8", null);
            }
        //public BodyEditorLoader(string str) {
        //    if (str == null) throw new NullReferenceException("str is null");
        //    model = readJson(str);
        //}

        // -------------------------------------------------------------------------
        // Public API
        // -------------------------------------------------------------------------

        /**
         * Creates and applies the fixtures defined in the editor. The name
         * parameter is used to retrieve the right fixture from the loaded file.
         * <br/><br/>
         *
         * The body reference point (the red cross in the tool) is by default
         * located at the bottom left corner of the image. This reference point
         * will be put right over the BodyDef position point. Therefore, you should
         * place this reference point carefully to let you place your body in your
         * world easily with its BodyDef.position point. Note that to draw an image
         * at the position of your body, you will need to know this reference point
         * (see {@link #getOrigin(java.lang.String, float)}.
         * <br/><br/>
         *
         * Also, saved shapes are normalized. As shown in the tool, the width of
         * the image is considered to be always 1 meter. Thus, you need to provide
         * a scale factor so the polygons get resized according to your needs (not
         * every body is 1 meter large in your game, I guess).
         *
         * @param body The Box2d body you want to attach the fixture to.
         * @param name The name of the fixture you want to load.
         * @param fd The fixture parameters to apply to the created body fixture.
         * @param scale The desired scale of the body. The default width is 1.
         */

        public void attachFixture(Body body, String name, float scale)
        {
            // deleted FixtureDef
            RigidBodyModel rbModel = model.rigidBodies[name];

            if (rbModel == null)
            {
                throw new SystemException("Name '" + name + "' was not found.");
            }

            vec = rbModel.origin * scale;
            Vector2 origin = vec;

            for (int i = 0, n = rbModel.polygons.Count; i < n; i++)
            {
                PolygonModel polygon  = rbModel.polygons[i];
                Vertices     vertices = new Vertices(polygon.vertices);

                for (int ii = 0, nn = vertices.Count; ii < nn; ii++)
                {
                    var v = NewVec();
                    v             = vertices[ii] * scale;
                    vertices[ii]  = v;
                    vertices[ii] -= origin;
                }

                polygonShape.Set(vertices);
                body.CreateFixture(polygonShape);

                for (int ii = 0, nn = vertices.Count; ii < nn; ii++)
                {
                    Free(vertices[ii]);
                }
            }

            for (int i = 0, n = rbModel.circles.Count; i < n; i++)
            {
                CircleModel circle = rbModel.circles[i];
                var         v2     = NewVec();
                v2 = circle.center * scale;
                Vector2 center = v2;
                float   radius = circle.radius * scale;

                circleShape.Position = center;
                circleShape.Radius   = radius;
                body.CreateFixture(circleShape);

                Free(center);
            }
        }
Example #15
0
        public static CircleModel Circle2Model(Circle line)
        {
            CircleModel dbModel = new CircleModel();

            dbModel.Center  = Point3d2Pointf(line.Center);
            dbModel.Radius  = line.Radius;
            dbModel.GeoType = "Circle";
            MyPoint spt    = new MyPoint(line.StartPoint.X, line.StartPoint.Y);
            MyPoint ept    = new MyPoint(line.EndPoint.X, line.EndPoint.Y);
            MyPoint center = new MyPoint(dbModel.Center.X, dbModel.Center.Y);

            dbModel.pointList = MethodCommand.GetArcPoints(line, line.Circumference);
            dbModel.Color     = line.ColorIndex == 256 ? MethodCommand.GetLayerColorByID(line.LayerId) : System.Drawing.ColorTranslator.ToHtml(line.Color.ColorValue);
            dbModel.isDashed  = GetLayerLineTypeByIDEx(line);
            return(dbModel);
        }
Example #16
0
        public CircleModel FittingCircleWithRansac(double[][] points)
        {
            var ransca = new RansacCircle(100, 0.9);

            var circle   = ransca.Estimate(points.Select(t => new Point((float)t[0], (float)t[1])).ToArray());
            var midPoint = points[points.Length / 2];
            var result   = new CircleModel
            {
                X       = circle.Origin.X,
                Y       = circle.Origin.Y,
                XSource = midPoint[0],
                YSource = midPoint[1],
                R       = circle.Radius,
                R_geo   = GeoTools.CalculateDistance(midPoint[1], midPoint[0], circle.Origin.Y, circle.Origin.X)
            };

            return(result);
        }
        public override void SaveDrawing(HashSet <Point> mousePositions)
        {
            var startPoint = mousePositions.ElementAt(0);
            var endPoint   = mousePositions.ElementAt(mousePositions.Count - 1);

            var center = new Point((startPoint.X + endPoint.X) / 2, (startPoint.Y + endPoint.Y) / 2);
            var radius = (int)CustomPoint.GetDistance(startPoint.X, startPoint.Y, center.X, center.Y);

            var points = _circleAlgorithm.GetCirclePoints(BPoint.ConvertPointToIBPoint(center), radius);

            var finalPoints = new List <IBPoint>();

            foreach (var point in points)
            {
                finalPoints.Add(new BPoint(point.X, point.Y));
            }

            var circle = new CircleModel(finalPoints, BPoint.ConvertPointToIBPoint(center), radius);

            Add(circle);
        }
 public void Remove(CircleModel circle)
 {
     _circles.Remove(circle);
 }
 public void Add(CircleModel circle)
 {
     _circles.Add(circle);
 }
Example #20
0
 public CircleView(CircleModel circleModel)
 {
     InitializeComponent();
     this.DataContext = circleModel;
 }
Example #21
0
        public static CircleModel Ellipse2Model(Ellipse line, AttributeModel atModel)
        {
            CircleModel dbModel = new CircleModel();

            dbModel.Center = Point3d2Pointf(line.Center);
            //dbModel.MajorAxis= line.MajorRadius;
            //dbModel.MinorAxis = line.MinorRadius;
            MyPoint spt    = new MyPoint(line.StartPoint.X, line.StartPoint.Y);
            MyPoint ept    = new MyPoint(line.EndPoint.X, line.EndPoint.Y);
            MyPoint center = new MyPoint(dbModel.Center.X, dbModel.Center.Y);

            double length = line.RadiusRatio * (line.MinorRadius + line.MajorRadius);

            dbModel.pointList = MethodCommand.GetArcPoints(line, length);

            dbModel.Color = line.ColorIndex == 256 ? MethodCommand.GetLayerColorByID(line.LayerId) : System.Drawing.ColorTranslator.ToHtml(line.Color.ColorValue);
            foreach (AttributeItemModel item in atModel.attributeItems)
            {
                string attValue = "";

                switch (item.AtItemType)
                {
                case AttributeItemType.Area:
                    attValue = line.Area.ToString();
                    break;

                case AttributeItemType.TxtHeight:

                    break;

                case AttributeItemType.Color:
                    attValue = dbModel.Color;
                    break;

                case AttributeItemType.Content:

                    break;

                case AttributeItemType.LayerName:
                    attValue = line.Layer;
                    break;

                case AttributeItemType.LineScale:
                    attValue = line.LinetypeScale.ToString();
                    break;

                case AttributeItemType.LineType:
                    attValue = GetLayerLineTypeByID(line);
                    break;

                case AttributeItemType.Overallwidth:
                    break;

                case AttributeItemType.TotalArea:

                    break;
                }
                if (!string.IsNullOrEmpty(attValue))
                {
                    item.AtValue = attValue;
                    dbModel.attItemList.Add(item);
                }
            }
            return(dbModel);
        }
Example #22
0
 public String CalculateCircleArea()
 {
     ICircleModel model = new CircleModel();
     _view.ResultText=model.GetArea(double.Parse(_view.RadiusText)).ToString();
     return _view.ResultText.ToString();
 }