static CenterRadiusObject getCenterAndRadiusCircle(PointZ a, PointZ b, PointZ c)
        {
            Matrix d = new Matrix(3, 3, new[] {
                a.X, a.Y, 1.0,
                b.X, b.Y, 1.0,
                c.X, c.Y, 1.0
            });

            Matrix x0Matrix = new Matrix(3, 3, new[] {
                a.X *a.X + a.Y *a.Y, a.Y, 1.0,
                b.X *b.X + b.Y *b.Y, b.Y, 1.0,
                c.X *c.X + c.Y *c.Y, c.Y, 1.0
            });

            Matrix y0Matrix = new Matrix(3, 3, new[] {
                a.X *a.X + a.Y *a.Y, a.X, 1.0,
                b.X *b.X + b.Y *b.Y, b.X, 1.0,
                c.X *c.X + c.Y *c.Y, c.X, 1.0
            });

            double D = 2 * d.Determinant();

            PointZ center = new PointZ(x0Matrix.Determinant() / D, -y0Matrix.Determinant() / D);

            return(new CenterRadiusObject()
            {
                center = center, radius = getpointsDistance(a, center)
            });
        }
Example #2
0
 public Visor(int amplitud, int altura)
 {
     Amplitud = amplitud;
     Altura   = altura;
     mundo    = new Llista <Mapa>();
     posicion = new PointZ();
 }
        static PointZ[] getTwoNearestConvexHullPoints(List <PointZ> convexHull, PointZ p)
        {
            PointZ[] result = new PointZ[2];

            var index          = convexHull.FindIndex(el => el == p);
            var convexHullLast = convexHull.Count - 1;


            if (index == 0)
            {
                result[0] = convexHull[1];
                result[1] = convexHull[convexHullLast];
            }

            else if (index == convexHullLast)
            {
                result[0] = convexHull[convexHullLast - 1];
                result[1] = convexHull[0];
            }

            else
            {
                result[0] = convexHull[index - 1];
                result[1] = convexHull[index + 1];
            }

            return(result);
        }
Example #4
0
		public Visor(int amplitud, int altura)
		{
			Amplitud = amplitud;
			Altura = altura;
			mundo = new Llista<Mapa>();
			posicion = new PointZ();
		}
Example #5
0
 public ImageFragment(Bitmap imagen, PointZ localizacion)
 {
     if (imagen == null)
     {
         throw new NullReferenceException("La imagen no puede ser null");
     }
     this.imagen = new ImageBase(imagen);
     Location    = localizacion;
     IsVisible   = true;
 }
Example #6
0
        public ImageFragment Remove(PointZ localizacion)
        {
            ImageFragment fragmentoQuitado = GetFragment(localizacion);

            if (fragmentoQuitado != null)
            {
                fragments.Remove(fragmentoQuitado);
            }

            return(fragmentoQuitado);
        }
		public Pixel SelectPixel(PointZ externPoint)
		{
			PointZ internalPoint = new PointZ(externPoint.X - Posicion.X, externPoint.Y - Posicion.Y, externPoint.Z - Posicion.Z);
			Pixel selectedPixel = null;
			var figuraPixelada = Figura.GetEnumerator();
			while (selectedPixel == null && figuraPixelada.MoveNext()) {
				if (figuraPixelada.Current.Localizacion.Equals(internalPoint))
					selectedPixel = figuraPixelada.Current;
			}
			return selectedPixel;
		}
        static bool IsUnderTheLine(PointZ A, PointZ B, PointZ P)
        {
            double x = P.X;
            double y = P.Y;

            double x1 = A.X;
            double y1 = A.Y;

            double x2 = B.X;
            double y2 = B.Y;

            double f = (y1 - y2) * x + (x2 - x1) * y + (x1 * y2 - x2 * y1);

            return(f < 0);
        }
 public Color GetColor(Point point)
 {
     Color color;
     PointZ location = new PointZ(point, 0);
     if (colorLocatedByPointerList.ContainsKey(location))
         color = colorLocatedByPointerList[location];
     else
     {
         color = imagen.GetPixel(point.X, point.Y);
         colorLocatedByPointerList.Add(location, color);
         if (!pointLocatedByColorList.ContainsKey(color.ToArgb()))
             pointLocatedByColorList.Add(color.ToArgb(), point);
     }
     return color;
 }
Example #10
0
        public ImageFragment Add(Bitmap imagen, int x = 0, int y = 0, int z = 0)
        {
            if (imagen == null)
            {
                throw new ArgumentNullException("imagen", "Se necesita una imagen");
            }

            ImageFragment fragment = null;
            PointZ        location = new PointZ(x, y, z);

            fragment = new ImageFragment(imagen, location);
            fragments.Add(fragment);


            return(fragment);
        }
Example #11
0
        public void Treu(PointZ localitzacio)
        {
            int  pos    = 0;
            bool trobat = false;

            while (pos < pixels.Count && !trobat)
            {
                if (pixels[pos].Localizacion.Equals(localitzacio))
                {
                    trobat = true;
                }
                else
                {
                    pos++;
                }
            }
            pixels.Elimina(pos);
        }
Example #12
0
 public ImageFragment[] GetFragments(PointZ location)
 {
     return(GetFragments(location.X, location.Y, location.Z));
 }
        internal static Triangle[] Process(List <PointZ> points, bool flag, int steps)
        {
            List <PointZ> sortedPoints = points.OrderBy(p => p.X).ThenBy(p => p.Y).ToList();
            PointZ        x_0          = sortedPoints[0];

            List <PointZ> otherPoints = sortedPoints.Skip(1).OrderBy(x_i => getpointsDistance(x_0, x_i)).ToList();
            PointZ        x_j         = otherPoints[0];

            //skip x_j element
            otherPoints = otherPoints.Skip(1).ToList();

            var centerRadiusCollection = otherPoints.Select((p, index) =>
            {
                CenterRadiusObject crObject;

                try
                {
                    crObject = getCenterAndRadiusCircle(x_0, x_j, p);
                }
                catch
                {
                    double epsilon = 0.1;
                    crObject       = getCenterAndRadiusCircle(x_0, x_j, new PointZ(p.X + epsilon, p.Y));
                }

                return(new { Point = p, Index = index, Radius = crObject.radius, Center = crObject.center });
            }).ToList();

            double minRadius        = centerRadiusCollection.Min(el => el.Radius);
            var    minRadiusElement = centerRadiusCollection.Find(el => el.Radius == minRadius);
            PointZ c = minRadiusElement.Center;

            PointZ x_k = minRadiusElement.Point;

            centerRadiusCollection.RemoveAt(minRadiusElement.Index);

            List <PointZ> pointsSi = centerRadiusCollection
                                     .Select(el => el.Point)
                                     .OrderBy(el => getpointsDistance(el, c))
                                     .ToList();

            List <Triangle> result = new List <Triangle>();


            List <PointZ> pointsInTringulation = new List <PointZ>();

            pointsInTringulation.Add(x_0);
            pointsInTringulation.Add(x_j);
            pointsInTringulation.Add(x_k);

            //List<PointZ> pointsInTringulationPrev = pointsInTringulation.Select(el => el).ToList();
            List <PointZ> PrevConvexHull = pointsInTringulation.Select(el => el).ToList().ToList();


            result.Add(new Triangle(x_0, x_j, x_k));

            //return result.ToArray();

            bool debugFlag = false;

            for (int i = 0; i < pointsSi.Count; i++)
            {
                var currentPoint = pointsSi[i];

                pointsInTringulation.Add(currentPoint);
                var convexHull = JarvisAlgorithm.JarvisHull(pointsInTringulation.ToArray());

                //разность множеств
                List <PointZ> difference = PrevConvexHull.Except(convexHull).ToList();

                if (difference.Count == 0)
                {
                    //рисуем один треугольник

                    var nearestPointsOfConvexHull       = getTwoNearestConvexHullPoints(convexHull, currentPoint);
                    var trianglewithNearestPointsOfHull = new Triangle(currentPoint, nearestPointsOfConvexHull[0], nearestPointsOfConvexHull[1]);

                    var adjacentTriangle = result.Find(triangle => triangle.Contains(nearestPointsOfConvexHull[0]) && triangle.Contains(nearestPointsOfConvexHull[1]));

                    result.Add(trianglewithNearestPointsOfHull);

                    if (adjacentTriangle != null)
                    {
                        fixTriangles(result, trianglewithNearestPointsOfHull, adjacentTriangle);
                    }
                }


                else  //когда разность множеств больше 1
                {
                    PointZ[] nearest = getTwoNearestConvexHullPoints(convexHull, currentPoint);

                    if (IsUnderTheLine(nearest[0], nearest[1], currentPoint))
                    {
                        //swapPoints
                        PointZ third = nearest[0];

                        nearest[0] = nearest[1];
                        nearest[1] = third;

                        difference = difference.OrderByDescending(p => p.X).ToList();
                    }

                    //difference = difference.OrderBy(p => p.X).ToList();

                    var t1         = new Triangle(currentPoint, nearest[0], difference[0]);
                    var neighbour1 = result.Find(t => t.Contains(nearest[0]) && t.Contains(difference[0]));

                    result.Add(t1);
                    if (neighbour1 != null)
                    {
                        fixTriangles(result, t1, neighbour1);
                    }

                    for (int j = 0; j < difference.Count - 1; j++)
                    {
                        var ti         = new Triangle(currentPoint, difference[j], difference[j + 1]);
                        var neighbouri = result.Find(t => t.Contains(difference[j]) && t.Contains(difference[j + 1]));

                        result.Add(ti);
                        if (neighbouri != null)
                        {
                            fixTriangles(result, ti, neighbouri);
                        }
                    }

                    var t2         = new Triangle(currentPoint, nearest[1], difference[difference.Count - 1]);
                    var neighbour2 = result.Find(t => t.Contains(nearest[1]) && t.Contains(difference[difference.Count - 1]));

                    result.Add(t2);
                    if (neighbour2 != null)
                    {
                        fixTriangles(result, t2, neighbour2);
                    }
                }

                //pointsInTringulationPrev.Add(currentPoint);
                PrevConvexHull = convexHull;

                if (debugFlag)
                {
                    return(result.ToArray());
                }

                if (steps == i)
                {
                    return(result.ToArray());
                }
            }

            System.Diagnostics.Debug.WriteLine("triangles.count = " + result.Count);
            return(result.ToArray());
        }
Example #14
0
 public ImageFragment Add(Bitmap imatge, PointZ localizacio)
 {
     return(Add(imatge, localizacio.X, localizacio.Y, localizacio.Z));
 }
Example #15
0
            private void _read()
            {
                _shapeType = ((ShapefileMain.ShapeType)m_io.ReadS4le());
                if (ShapeType != ShapefileMain.ShapeType.NullShape)
                {
                    switch (ShapeType)
                    {
                    case ShapefileMain.ShapeType.PointM: {
                        _shapeParameters = new PointM(m_io, this, m_root);
                        break;
                    }

                    case ShapefileMain.ShapeType.PolygonZ: {
                        _shapeParameters = new PolygonZ(m_io, this, m_root);
                        break;
                    }

                    case ShapefileMain.ShapeType.MultiPointM: {
                        _shapeParameters = new MultiPointM(m_io, this, m_root);
                        break;
                    }

                    case ShapefileMain.ShapeType.PolyLineZ: {
                        _shapeParameters = new PolyLineZ(m_io, this, m_root);
                        break;
                    }

                    case ShapefileMain.ShapeType.MultiPointZ: {
                        _shapeParameters = new MultiPointZ(m_io, this, m_root);
                        break;
                    }

                    case ShapefileMain.ShapeType.MultiPoint: {
                        _shapeParameters = new MultiPoint(m_io, this, m_root);
                        break;
                    }

                    case ShapefileMain.ShapeType.PolygonM: {
                        _shapeParameters = new PolygonM(m_io, this, m_root);
                        break;
                    }

                    case ShapefileMain.ShapeType.Polygon: {
                        _shapeParameters = new Polygon(m_io, this, m_root);
                        break;
                    }

                    case ShapefileMain.ShapeType.Point: {
                        _shapeParameters = new Point(m_io, this, m_root);
                        break;
                    }

                    case ShapefileMain.ShapeType.PolyLineM: {
                        _shapeParameters = new PolyLineM(m_io, this, m_root);
                        break;
                    }

                    case ShapefileMain.ShapeType.PolyLine: {
                        _shapeParameters = new PolyLine(m_io, this, m_root);
                        break;
                    }

                    case ShapefileMain.ShapeType.PointZ: {
                        _shapeParameters = new PointZ(m_io, this, m_root);
                        break;
                    }

                    case ShapefileMain.ShapeType.MultiPatch: {
                        _shapeParameters = new MultiPatch(m_io, this, m_root);
                        break;
                    }
                    }
                }
            }
Example #16
0
		public Pixel(Color color, PointZ posicion)
		{
			localizacion = posicion;
			colorPixel = color;
		}
		//posicion de la figura en la figura Animada
		public FiguraPosicionada(PointZ posicion, Figura figura)
		{
			Figura = figura;
			Posicion = posicion;
		}
Example #18
0
 public Pixel(Color color, PointZ posicion)
 {
     localizacion = posicion;
     colorPixel   = color;
 }
Example #19
0
 public Mapa(PointZ posicion, IEnumerable <FiguraPosicionada> figuras)
     : this()
 {
     Localizacion = posicion;
     this.Figuras.AfegirMolts(figuras);
 }
Example #20
0
 public Color[,] Area(PointZ esquinaSuperiorIzquierda, int amplitud, int altura)
 {
     Color[,] area = new Color[amplitud, altura];
     return(area);
 }