コード例 #1
0
        private static void rngTriangleAreaTest()
        {
            var rng    = new FastRng();
            var a      = new PointXY(rng.Exclusive(-1.0, 1.0), rng.Exclusive(0.0, 1.0));
            var b      = new PointXY(rng.Exclusive(1.0, 2.0), rng.Exclusive(-2.0, -1.0));
            var c      = new PointXY(rng.Exclusive(-2.0, -1.0), rng.Exclusive(-2.0, -1.0));
            var bc     = new PointXY(new[] { b, c }.Average());
            var inside = new PointXY(new [] { a, bc }.Average());

            Assert.IsTrue(inside.InsideTriangle(new List <IPoint>(new [] { a, b, c })));

            var areaA = Triangle.Area(b, c, inside);

            Assert.Less(Math.Abs(areaA - Triangle.Area(c, b, inside)), 1e-12);
            Assert.Less(Math.Abs(areaA - Triangle.Area(inside, b, c)), 1e-12);
            Assert.Less(Math.Abs(areaA - Triangle.Area(c, inside, b)), 1e-12);
            var areaB = Triangle.Area(a, c, inside);

            Assert.Less(Math.Abs(areaB - Triangle.Area(c, a, inside)), 1e-12);
            Assert.Less(Math.Abs(areaB - Triangle.Area(inside, a, c)), 1e-12);
            Assert.Less(Math.Abs(areaB - Triangle.Area(c, inside, a)), 1e-12);
            var areaC = Triangle.Area(a, b, inside);

            Assert.Less(Math.Abs(areaC - Triangle.Area(b, a, inside)), 1e-12);
            Assert.Less(Math.Abs(areaC - Triangle.Area(inside, a, b)), 1e-12);
            Assert.Less(Math.Abs(areaC - Triangle.Area(b, inside, a)), 1e-12);
            var area = Triangle.Area(a, b, c);

            Assert.Less(Math.Abs(area - Triangle.Area(b, a, c)), 1e-12);
            Assert.Less(Math.Abs(area - Triangle.Area(c, a, b)), 1e-12);
            Assert.Less(Math.Abs(area - Triangle.Area(b, c, a)), 1e-12);

            Assert.Less(Math.Abs(area - (areaA + areaB + areaC)), 1e-12);
        }
コード例 #2
0
        public void InsideTriangleTest()
        {
            var rng = new FastRng();

            for (int i = 2; i < 100; i++)
            {
                var a           = new PointXY(rng.Exclusive(-100.0, 100.0), rng.Exclusive(-100.0, 100.0));
                var b           = new PointXY(rng.Exclusive(-100.0, 100.0), rng.Exclusive(-100.0, 100.0));
                var c           = new PointXY(rng.Exclusive(-100.0, 100.0), rng.Exclusive(-100.0, 100.0));
                var midpointBC  = new PointXY((b.X + c.X) / (2.0), (b.Y + c.Y) / (2.0));
                var insidePoint = new PointXY((midpointBC.X + a.X) / (2.0), (midpointBC.Y + a.Y) / (2.0));
                Assert.IsTrue(insidePoint.InsideTriangle(a, b, c));

                var dx = midpointBC.X - a.X;
                var dy = midpointBC.Y - a.Y;

                // outside point, past BC on a->midpointBC vector.
                // As i increases, point is closer to to midpoint of BC
                var outsidePoint = new PointXY((midpointBC.X + dx / i), (midpointBC.Y + dy / i));
                Assert.IsFalse(outsidePoint.InsideTriangle(a, b, c));

                var dxy     = new Vector(midpointBC.X - a.X, midpointBC.Y - a.Y);
                var outside = new PointXY(midpointBC + dxy / i);
                Assert.IsFalse(outside.InsideTriangle(a, b, c));

                // inside point, inside BC on a->midpointBC vector
                // As i increases, point is closer to midpoint of BC
                insidePoint = new PointXY((midpointBC.X - dx / i), (midpointBC.Y - dy / i));
                Assert.IsTrue(insidePoint.InsideTriangle(a, b, c));

                var inside = new PointXY(midpointBC - dxy / i);
                Assert.IsTrue(inside.InsideTriangle(c, b, a));
            }
        }
コード例 #3
0
ファイル: PathHelper.cs プロジェクト: pmcxs/world-hexagon-map
        public static IEnumerable <HexagonLocationUV> GetHexagonsIntersectedByLine(PointXY startPoint, PointXY endPoint, HexagonDefinition hexagonDefinition)
        {
            var startHexagon = HexagonUtils.GetHexagonLocationUVForPointXY(startPoint, hexagonDefinition);
            var endHexagon   = HexagonUtils.GetHexagonLocationUVForPointXY(endPoint, hexagonDefinition);

            var minU = new[] { startHexagon.U, endHexagon.U }.Min() - 1;
            var maxU = new[] { startHexagon.U, endHexagon.U }.Max() + 1;

            var minV = new[] { startHexagon.V, endHexagon.V }.Min() - 1;
            var maxV = new[] { startHexagon.V, endHexagon.V }.Max() + 1;

            var matchingHexagons = new List <HexagonLocationUV>();

            for (var u = minU; u <= maxU; u++)
            {
                for (var v = minV; v <= maxV; v++)
                {
                    var points = HexagonUtils.GetPointsXYOfHexagon(new HexagonLocationUV(u, v), hexagonDefinition);

                    for (var k = 0; k < points.Count() - 1; k++)
                    {
                        var p0 = points[k];
                        var p1 = points[k + 1];

                        if (GetLineIntersection(p0, p1, startPoint, endPoint) != null)
                        {
                            matchingHexagons.Add(new HexagonLocationUV(u, v));
                            break;
                        }
                    }
                }
            }

            return(matchingHexagons);
        }
コード例 #4
0
        /// <summary>
        ///     Obtains the Hexagon Location (u,v) for a given point (x,y)
        /// </summary>
        /// <remarks>
        ///     This algorithm follows a two step approach. The first one is very first and although doesn't have false positives
        ///     might have false negatives.
        ///     Thus, on a second iteration (if the first didn't return true) it checks the vicinity hexagons and uses a more
        ///     deterministic polygon intersection mechanism.
        /// </remarks>
        /// <param name="point">A given X,Y point</param>
        /// <param name="hexagonDefinition"></param>
        /// aaa
        /// <returns>An hexagon U,V Location</returns>
        public static HexagonLocationUV GetHexagonLocationUVForPointXY(PointXY point, HexagonDefinition hexagonDefinition)
        {
            var u = Convert.ToInt32(Math.Round(point.X / hexagonDefinition.NarrowWidth));
            var v = Convert.ToInt32(Math.Round(point.Y / hexagonDefinition.Height - u * 0.5));

            if (IsPointXYInsideHexagonLocationUV(point, new HexagonLocationUV(u, v), hexagonDefinition))
            {
                return(new HexagonLocationUV(u, v));
            }

            var surroundingHexagons = new List <HexagonLocationUV>
            {
                new HexagonLocationUV(u, v - 1),
                new HexagonLocationUV(u, v + 1),
                new HexagonLocationUV(u - 1, v),
                new HexagonLocationUV(u + 1, v),
                new HexagonLocationUV(u - 1, v + 1),
                new HexagonLocationUV(u + 1, v - 1)
            };

            foreach (var hex in surroundingHexagons)
            {
                if (IsPointXYInsideHexagonLocationUV(point, hex, hexagonDefinition))
                {
                    return(hex);
                }
            }

            return(null);
        }
コード例 #5
0
        public static ValueRange <PointXY> Limits <TPoint>(this IEnumerable <TPoint> points) where TPoint : IPoint
        {
            var xMin = double.MaxValue;
            var yMin = double.MaxValue;
            var yMax = double.MinValue;
            var xMax = double.MinValue;

            foreach (var point in points)
            {
                if (point.X > xMax)
                {
                    xMax = point.X;
                }
                if (point.Y > yMax)
                {
                    yMax = point.Y;
                }
                if (point.X < xMin)
                {
                    xMin = point.X;
                }
                if (point.Y < yMin)
                {
                    yMin = point.Y;
                }
            }
            ;
            var min   = new PointXY(xMin, yMin);
            var max   = new PointXY(xMax, yMax);
            var range = new ValueRange <PointXY>(min, max);

            return(range);
        }
コード例 #6
0
    void CheckNextTurn()
    {
        Unit un = playerUnits[0];
        bool tf = true;

        for (int i = 0; i < maxPlayerUnits; i++)
        {
            if ((playerUnits[i].unit.id != 0) && (playerUnits[i].unit.curAP > 0))
            {
                tf          = false;
                un          = playerUnits[i];
                chosenPoint = new PointXY(playerUnits[i].point);
            }
        }
        if (tf)
        {
            // Debug.Log(tf);
            enemyUnitNow = 0;
            enemyTurn    = true;
            for (int i = 0; i < maxPlayerUnits; i++)
            {
                playerUnits[i].unit.calculateNewTurn();
            }
            for (int i = 0; i < maxEnemyUnits; i++)
            {
                enemyUnits[i].unit.calculateNewTurn();
            }
            chosenPoint = new PointXY(playerUnits[0].point);
        }
    }
コード例 #7
0
 public Unit(int a, int b, bool tf, PointXY rot)
 {
     this.point    = new PointXY(a, b);
     this.rotation = new PointXY(rot);
     this.unit     = new MovebleObject(1, tf);
     //this.unit.Generate(1);
 }
コード例 #8
0
    ArrayList GetWay(PointXY p)
    {
        ArrayList newWay = new ArrayList();

        newWay.Add(p);
        int step = 0;

        //Debug.Log(p.x + " " + p.y + " " + dist[p.x][p.y]);
        while (dist[p.x][p.y] > 0)
        {
            // step++;
            //if (step > 50)
            //{
            //  break;
            //}
            p = parents[p.x][p.y];
            // Debug.Log(p.x + " " + p.y + " " + dist[p.x][p.y]);
            newWay.Add(p);
        }
        //if (step > 50)
        //{
        //  Debug.Log(dist[p.x][p.y]);
        //}
        return(newWay);
    }
コード例 #9
0
 public BoundingBox(PointXY nw, PointXY se)
 {
     North = nw.Y;
     South = se.Y;
     West  = nw.X;
     East  = se.X;
 }
コード例 #10
0
ファイル: Damage.cs プロジェクト: GospodinNoob/XCOM-like
    public Damage(Damage dmg, PointXY vectorTarget, PointXY vectorAttack, Armour arm)
    {
        this.damage = Mathf.Max(0, dmg.piercingDamage - arm.piercingArmour) + Mathf.Max(0, dmg.slashDamage - arm.slashArmour) +
                      Mathf.Max(0, dmg.axeDamage - arm.axeArmour) + Mathf.Max(0, dmg.crashDamage - arm.crashArmour);
        double a1 = Mathf.Atan2(vectorAttack.x, vectorAttack.y);

        if (a1 < 0)
        {
            a1 += Mathf.PI * 2;
        }
        double a2 = Mathf.Atan2(vectorTarget.x, vectorTarget.y);

        if (a2 < 0)
        {
            a2 += Mathf.PI * 2;
        }
        double resultAngle = (a2 - a1);

        if (resultAngle < 0)
        {
            resultAngle += Mathf.PI * 2;
        }
        if (resultAngle > Mathf.PI)
        {
            resultAngle = Mathf.PI * 2 - resultAngle;
        }
        resultAngle  = Mathf.PI - resultAngle;
        resultAngle /= Mathf.PI;
        this.damage  = this.damage + (int)(this.damage * resultAngle);
    }
コード例 #11
0
        public async Task <bool> ExportResults(IEnumerable <Hexagon> hexagons, HexagonDefinition hexagonDefinition, MergeStrategy mergeStrategy)
        {
            foreach (Hexagon hexagon in hexagons)
            {
                string insertCommand = @"INSERT INTO HexagonLocation (U,V,PIXELX,PIXELY) VALUES (@U,@V,@PixelX,@PixelY) ON CONFLICT(U,V) DO UPDATE SET PixelX=excluded.PixelX,PixelY=excluded.PixelY";

                PointXY hexagonCenter = HexagonUtils.GetCenterPointXYOfHexagonLocationUV(hexagon.LocationUV, hexagonDefinition);

                await _connection.ExecuteAsync(insertCommand,
                                               new
                {
                    hexagon.LocationUV.U,
                    hexagon.LocationUV.V,
                    PixelX = hexagonCenter.X,
                    PixelY = hexagonCenter.Y
                });

                foreach (var key in hexagon.HexagonData.Data.Keys)
                {
                    object dataValue = hexagon.HexagonData.Data[key];

                    string insertDataCommand = @"INSERT INTO HexagonData (U,V,FIELD,VALUE) VALUES (@U,@V,@Field,@Value) ON CONFLICT(U,V,FIELD) DO ";

                    switch (mergeStrategy)
                    {
                    case MergeStrategy.BitMask:
                        insertDataCommand += "UPDATE SET VALUE=VALUE|excluded.Value";
                        break;

                    case MergeStrategy.Ignore:
                        insertDataCommand += "NOTHING";
                        break;

                    case MergeStrategy.Replace:
                        insertDataCommand += "UPDATE Set Value=excluded.Value";
                        break;

                    case MergeStrategy.Max:
                        insertDataCommand += "UPDATE Set Value=max(excluded.Value,Value)";
                        break;

                    case MergeStrategy.Min:
                        insertDataCommand += "UPDATE Set Value=min(excluded.Value,Value)";
                        break;
                    }

                    await _connection.ExecuteAsync(insertDataCommand,
                                                   new
                    {
                        hexagon.LocationUV.U,
                        hexagon.LocationUV.V,
                        Field = key,
                        Value = dataValue
                    });
                }
            }

            return(true);
        }
コード例 #12
0
 public Unit(int a, int b, string s, bool tf, PointXY rot)
 {
     this.point    = new PointXY(a, b);
     this.rotation = new PointXY(rot);
     // Debug.Log(s);
     this.unit = new MovebleObject(s);
     //this.unit.Generate(1);
 }
コード例 #13
0
        public void LatLonToPixelXYTest(double lon, double lat, int pixelX, int pixelY, int zoom)
        {
            PointXY pixel = new PointXY();

            (pixel.X, pixel.Y) = TileSystem.LatLongToPixelXY(lat, lon, zoom);

            Assert.Equal(pixelX, pixel.X);
            Assert.Equal(pixelY, pixel.Y);
        }
コード例 #14
0
        private static void rightTriangleAreaTest(IPoint origin, double height, double width)
        {
            var a = new PointXY(origin.X + width, origin.Y);
            var b = new PointXY(origin.X, origin.Y);
            var c = new PointXY(origin.X, origin.Y + height);

            Assert.Less(Math.Abs(Triangle.Area(a, b, c) - Math.Abs(height * width) / 2.0), 1e-12);
            Assert.Less(Math.Abs(Triangle.Area((Point)a, (Point)b, (Point)c) - Math.Abs(height * width) / 2.0), 1e-12);
        }
コード例 #15
0
ファイル: RulePointDist.cs プロジェクト: zj8487/HyDM
        /// <summary>
        /// 检查两个数据点是否重合
        /// </summary>
        /// <param name="srcPt"></param>
        /// <param name="tarPt"></param>
        /// <returns></returns>
        private bool PointIsEqual(PointXY srcPt, PointXY tarPt)
        {
            if (Math.Abs(srcPt.dx - tarPt.dx) < m_pPara.dPointDist && Math.Abs(srcPt.dy - tarPt.dy) < m_pPara.dPointDist)
            {
                return(true);
            }

            return(false);
        }
コード例 #16
0
 public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
 {
     if (destinationType == typeof(string))
     {
         PointXY point = (PointXY)value;
         return(point.X + " " + point.Y);
     }
     return(base.ConvertTo(context, culture, value, destinationType));
 }
コード例 #17
0
        private static TileInfo GetTileOfPoint(PointXY pointXY, int zoomLevel, int tileSize, HexagonDefinition hexagonDefinition)
        {
            var pixelFactor = Math.Pow(2, zoomLevel - hexagonDefinition.ReferenceZoom);

            var tileX = Convert.ToInt32(Math.Floor(pointXY.X * pixelFactor / tileSize));
            var tileY = Convert.ToInt32(Math.Floor(pointXY.Y * pixelFactor / tileSize));

            return(new TileInfo(zoomLevel, tileX, tileY));
        }
コード例 #18
0
ファイル: FormDeviceData.cs プロジェクト: mrwangming/LWDicer
        public void ClearPicture()
        {
            LabelX.Hide();
            LabelY.Hide();
            PointXY.Hide();

            m_Grapic.Clear(Color.White);

            PicWafer.Refresh();
        }
コード例 #19
0
ファイル: HexagonUtils.cs プロジェクト: ststeiger/CoreTiles
 public static IEnumerable <PointXY> GetHexagonPixels(int edgeSize, PointXY center)
 {
     for (var i = 0; i < 6; i++)
     {
         float angle_deg = 60f * i;
         float angle_rad = (float)Math.PI / 180f * angle_deg;
         yield return(new PointXY(center.X + edgeSize * (float)Math.Cos(angle_rad),
                                  center.Y + edgeSize * (float)Math.Sin(angle_rad)));
     }
 }
コード例 #20
0
    public void DealDamage(Damage dmg, PointXY vectorTarget, PointXY vectorAttack)
    {
        Damage reducedDamage = new Damage(dmg, vectorTarget, vectorAttack, this.armour);

        this.curHits -= Mathf.Max(0, reducedDamage.Sum());
        if (this.curHits <= 0)
        {
            this.id = 0;
        }
    }
コード例 #21
0
    void Dijkstra(PointXY p1)
    {
        PointXY p   = new PointXY(p1);
        int     INF = 10000000;
        int     n   = 6;
        int     k   = 6;

        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < k; j++)
            {
                dist[i][j]  = INF;
                flags[i][j] = false;
            }
        }

        dist[p.x][p.y] = 0;
        int step = 0;

        while ((dist[p.x][p.y] < INF - 1) && (step < 500))
        {
            step++;
            // Dep.yug.Log(dist[p.x][p.y]);
            for (int i = -1; i <= 1; i++)
            {
                for (int j = -1; j <= 1; j++)
                {
                    // Dep.yug.Log(Vp.xlid(p.x + i, p.y + j));
                    if (Valid(p.x + i, p.y + j) && (dist[p.x + i][p.y + j] > dist[p.x][p.y] + Len(p.x, p.y, p.x + i, p.y + j)))
                    {
                        dist[p.x + i][p.y + j] = dist[p.x][p.y] + Len(p.x, p.y, p.x + i, p.y + j);
                        //Debug.Log(p.x + " " + p.y);
                        parents[p.x + i][p.y + j] = new PointXY(p);
                    }
                }
            }

            flags[p.x][p.y] = true;

            float min = INF;
            for (int i = 0; i < 6; i++)
            {
                for (int j = 0; j < 6; j++)
                {
                    if ((dist[i][j] < min) && (!flags[i][j]))
                    {
                        p.x = i;
                        p.y = j;
                        min = dist[i][j];
                    }
                }
            }
        }
    }
コード例 #22
0
        /// <summary>
        ///     Determines if a specified point (x,y) is inside a given hexagon Location (u,v)
        /// </summary>
        /// <param name="point"></param>
        /// <param name="location"></param>
        /// <param name="hexagonDefinition"></param>
        /// <returns>True if inside the hexagon, false otherwise</returns>
        public static bool IsPointXYInsideHexagonLocationUV(PointXY point, HexagonLocationUV location,
                                                            HexagonDefinition hexagonDefinition)
        {
            var center = GetCenterPointXYOfHexagonLocationUV(location, hexagonDefinition);

            var d  = hexagonDefinition.Diameter;
            var dx = Math.Abs(point.X - center.X) / d;
            var dy = Math.Abs(point.Y - center.Y) / d;
            var a  = 0.25 * Math.Sqrt(3.0);

            return(dy <= a && a * dx + 0.25 * dy <= 0.5 * a);
        }
コード例 #23
0
        public IActionResult Get(int z, int x, int y)
        {
            using (var destinationImage = new Image <Rgba32>(TileSize, TileSize))
            {
                if (z >= 7)
                {
                    var hexSize = 500;


                    var size = (int)(hexSize / Math.Pow(2, 10 - z));

                    var hexagonDefinition = new HexagonDefinition(size, 10);

                    //Tile offset
                    var pixelX = x * TileSize;
                    var pixelY = y * TileSize;

                    var topLeft     = new PointXY(pixelX - size, pixelY - size);
                    var bottomRight = new PointXY(pixelX + TileSize + size, pixelY + TileSize + size);

                    foreach (HexagonLocationUV hexagon in HexagonUtils.GetHexagonsInsideBoundingBox(topLeft, bottomRight, hexagonDefinition))
                    {
                        PointXY center = HexagonUtils.GetCenterPointXYOfHexagonLocationUV(hexagon, hexagonDefinition);

                        IList <PointXY> hexagonPoints = HexagonUtils
                                                        .GetHexagonPixels(size, new PointXY(center.X - pixelX, center.Y - pixelY)).ToList();

                        PointF[] points = hexagonPoints.Select(p => new PointF((float)p.X, (float)p.Y)).ToArray();

                        destinationImage.Mutate(ctx => ctx

                                                .DrawLines(
                                                    new Rgba32(200, 200, 200, 200),
                                                    5,
                                                    points)
                                                .DrawLines(
                                                    new Rgba32(100, 100, 100, 200),
                                                    2,
                                                    points));
                    }
                }

                Stream outputStream = new MemoryStream();

                destinationImage.Save(outputStream, new PngEncoder());
                outputStream.Seek(0, SeekOrigin.Begin);
                return(this.File(outputStream, "image/png"));
            }
        }
コード例 #24
0
ファイル: PathHelper.cs プロジェクト: pmcxs/world-hexagon-map
        public static PointXY GetLineIntersection(PointXY p0, PointXY p1, PointXY p2, PointXY p3)
        {
            var s1X = p1.X - p0.X;
            var s1Y = p1.Y - p0.Y;
            var s2X = p3.X - p2.X;
            var s2Y = p3.Y - p2.Y;
            var s   = (-s1Y * (p0.X - p2.X) + s1X * (p0.Y - p2.Y)) / (-s2X * s1Y + s1X * s2Y);
            var t   = (s2X * (p0.Y - p2.Y) - s2Y * (p0.X - p2.X)) / (-s2X * s1Y + s1X * s2Y);

            if (s >= 0 && s <= 1 && t >= 0 && t <= 1)
            {
                var intX = p0.X + t * s1X;
                var intY = p0.Y + t * s1Y;
                return(new PointXY(intX, intY));
            }

            return(null);
        }
コード例 #25
0
    void Swap(PointXY p1, PointXY p2, bool tf)
    {
        Unit playerUnit = GetUnit(p1);

        playerUnit.point = new PointXY(p2);
        map[p1.x][p1.y].movebleObject = map[p2.x][p2.y].movebleObject;
        map[p2.x][p2.y].movebleObject = playerUnit.unit;

        way = GetWay(p2);

        // Debug.Log(p2.x.ToString() + " " + p2.y.ToString());

        if (tf)
        {
            for (int i = 0; i < maxPlayerUnits; i++)
            {
                if (playerUnits[i] == playerUnit)
                {
                    Transform tr = this.gameObject.transform;
                    //  Debug.Log(1);
                    block = true;
                    this.GetComponent <UnitMove>().SetWay(playerUnits[i], playerUnitsGO[i], way);
                }
                //  Debug.Log(playerUnits[i].x);
                //playerUnitsGO[i].transform.position = new Vector3(tr.position.x - dx / 2 - 2 * dx + dx * playerUnits[i].point.x, tr.position.y - dx / 2 - dx + dx * playerUnits[i].point.y, tr.position.z);
            }
        }
        else
        {
            // enemyUnitNow = 0;
            for (int i = 0; i < maxEnemyUnits; i++)
            {
                if (enemyUnits[i] == playerUnit)
                {
                    Transform tr = this.gameObject.transform;
                    //  Debug.Log(playerUnits[i].x);
                    block = true;
                    //enemyUnitNow = 0;
                    this.GetComponent <UnitMove>().SetWay(enemyUnits[i], enemyUnitsGO[i], way);
                    //enemyUnitsGO[i].transform.position = new Vector3(tr.position.x - dx / 2 - 2 * dx + dx * enemyUnits[i].point.x, tr.position.y - dx / 2 - dx + dx * enemyUnits[i].point.y, tr.position.z);
                }
            }
        }
    }
コード例 #26
0
ファイル: FormDeviceData.cs プロジェクト: mrwangming/LWDicer
        public void ShowLayout(bool bShow)
        {
            if (bShow == true)
            {
                LabelX.Show();
                LabelY.Show();
                PointXY.Show();

                DrawLayout();
            }
            else
            {
                LabelX.Hide();
                LabelY.Hide();
                PointXY.Hide();

                ClearLayout();
            }
        }
コード例 #27
0
 // Update is called once per frame
 void Update()
 {
     if (flag)
     {
         //Debug.Log(newWay.Count);
         PointXY a = (PointXY)newWay[segment - 1];
         PointXY b = new PointXY(0, 0);
         if (segment < newWay.Count)
         {
             b = (PointXY)newWay[segment];
         }
         if (segment < newWay.Count)
         {
             if (Time.time - timer > len)
             {
                 Transform tr = this.gameObject.transform;
                 //Debug.Log((b.x - a.x).ToString() + " " + (b.y - a.y).ToString());
                 unitObject.SetRotation(new PointXY(b.x - a.x, b.y - a.y));
                 //Debug.Log(unitObject.rotation.x.ToString() + " " + unitObject.rotation.y.ToString());
                 Rotation(b.x - a.x, b.y - a.y);
                 len = Mathf.Sqrt((b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y));
                 unit.gameObject.transform.position = new Vector3(tr.position.x - dx / 2 - 2 * dx + dx * a.x, tr.position.y - dx / 2 - dx + dx * a.y, tr.position.z);
                 segment++;
                 timer = Time.time;
                 Vector2 speed = new Vector2((b.x - a.x) / len, (b.y - a.y) / len) * dx;
                 unit.gameObject.GetComponent <Rigidbody2D>().velocity = speed;
             }
         }
         else
         {
             if (Time.time - timer > len)
             {
                 flag = false;
                 Transform tr    = this.gameObject.transform;
                 Vector2   speed = new Vector2(0, 0);
                 unit.gameObject.GetComponent <Rigidbody2D>().velocity = speed;
                 unit.gameObject.transform.position = new Vector3(tr.position.x - dx / 2 - 2 * dx + dx * a.x, tr.position.y - dx / 2 - dx + dx * a.y, tr.position.z);
                 this.gameObject.GetComponent <BattleSceneControl>().SetBlock(false);
             }
         }
     }
 }
コード例 #28
0
        public IEnumerable <Hexagon> ProcessArea(GeoData geoData, LayersLoaderTarget[] targets = null)
        {
            foreach (PointXY[] geoCoordinates in geoData.Points)
            {
                var topLeftCoordinate     = new PointXY(geoCoordinates.Min(c => c.X), geoCoordinates.Min(c => c.Y));
                var bottomRightCoordinate = new PointXY(geoCoordinates.Max(c => c.X), geoCoordinates.Max(c => c.Y));

                var hexagonLocations = HexagonUtils.GetHexagonsInsideBoundingBox(topLeftCoordinate, bottomRightCoordinate, hexagonDefinition);

                foreach (var hexagonLocation in hexagonLocations)
                {
                    var center = HexagonUtils.GetCenterPointXYOfHexagonLocationUV(hexagonLocation, hexagonDefinition);

                    if (AreaHelper.IsPointInsidePolygon(center.X, center.Y, geoCoordinates))
                    {
                        yield return(CreateHexagon(geoData, targets, hexagonLocation, (geo, target) => geo.Values[target.SourceField]));
                    }
                }
            }
        }
コード例 #29
0
ファイル: FrmCaliPara.cs プロジェクト: Gz1d/Gz
 /// <summary>
 /// 插值算法 反距离加权法IDW
 /// </summary>
 /// <param name="input">离散点的XYZ</param>
 /// <param name="outpoint">平均点的XY</param>
 /// <returns></returns>
 public static bool InverseDistanceWeighted(List <PointXYZ> input, PointXY outpoint)
 {
     try{
         double r  = 0.0;   //距离的倒数和
         double ri = 0.0;   //i点的权重
         foreach (PointXYZ inputpoint in input)
         {
             r += 1.0 / (Math.Pow(inputpoint.X - outpoint.X, 2) + Math.Pow(inputpoint.Y - outpoint.Y, 2));
         }
         foreach (PointXYZ inputpoint in input)
         {
             ri           = 1.0 / (Math.Pow(inputpoint.X - outpoint.X, 2) + Math.Pow(inputpoint.Y - outpoint.Y, 2)) / r;
             inputpoint.Z = ri;
         }
         return(true);
     }
     catch {
         return(false);
     }
 }
コード例 #30
0
    GameObject GetUnitGO(PointXY p)
    {
        GameObject un = null;

        for (int i = 0; i < maxPlayerUnits; i++)
        {
            if ((playerUnits[i].point.x == p.x) && (playerUnits[i].point.y == p.y))
            {
                un = playerUnitsGO[i];
                break;
            }
        }
        for (int i = 0; i < maxEnemyUnits; i++)
        {
            if ((enemyUnits[i].point.x == p.x) && (enemyUnits[i].point.y == p.y))
            {
                un = enemyUnitsGO[i];
                break;
            }
        }
        return(un);
    }
コード例 #31
0
ファイル: RulePointDist.cs プロジェクト: hy1314200/HyDM
        /// <summary>
        /// ����������ݵ��Ƿ��غ�
        /// </summary>
        /// <param name="srcPt"></param>
        /// <param name="tarPt"></param>
        /// <returns></returns>
        private bool PointIsEqual(PointXY srcPt, PointXY tarPt)
        {
            if (Math.Abs(srcPt.dx - tarPt.dx) < m_pPara.dPointDist && Math.Abs(srcPt.dy - tarPt.dy) < m_pPara.dPointDist)
            {
                return true;
            }

            return false;
        }
コード例 #32
0
ファイル: RulePointDist.cs プロジェクト: hy1314200/HyDM
        /// <summary>
        /// ֱ��ʹ��Ƕ��ѭ���ķ�����������������˵�ǡ���������
        /// </summary>
        /// <param name="ipPtFeaCls">��ͼ��</param>
        /// <returns></returns>
        private bool SearchStupid(IFeatureClass ipPtFeaCls)
        {
            if (ipPtFeaCls == null) return false;

            // ����Դͼ��Ҫ��

            IQueryFilter ipQuery = new QueryFilterClass();
            ipQuery.SubFields = "OBJECTID,Shape";
            IFeatureCursor ipFeatCursor = ipPtFeaCls.Search(ipQuery, true);
            IFeature ipFeature = ipFeatCursor.NextFeature();

            IGeometry ipGeometry = null;
            int OID1 = -1;
            string str;

            while (ipFeature != null)
            {
                ipGeometry = ipFeature.Shape;
                OID1 = ipFeature.OID;
                if (ipGeometry == null)
                {
                    ipFeature = ipFeatCursor.NextFeature();
                    continue;
                }
                else
                {
                    if (ipGeometry.GeometryType == esriGeometryType.esriGeometryPoint ||
                        ipGeometry.GeometryType == esriGeometryType.esriGeometryMultipoint)
                    {
                        PointXY pt = new PointXY();
                        IPoint ipT = (IPoint)ipGeometry;
                        pt.dx = ipT.X;
                        pt.dy = ipT.Y;
                        str = OID1.ToString();
                        m_MapOIDFeature1.Add(str, pt);
                        m_MapOIDFeature2.Add(str, pt);
                    }
                }
                Marshal.ReleaseComObject(ipFeature);
                ipFeature = ipFeatCursor.NextFeature();
            }

            string rsOID, rsOID2;
            PointXY rsGeometry;
            PointXY rsGeometry2;
            m_aryResult = new List<PointDistInfo>();
            foreach (DictionaryEntry dn in m_MapOIDFeature1)
            {
                rsOID = (string)dn.Key;
                rsGeometry = (PointXY)dn.Value;
                foreach (DictionaryEntry dn2 in m_MapOIDFeature2)
                {
                    rsOID2 = (string)dn2.Key;
                    rsGeometry2 = (PointXY)dn2.Value;

                    // ��������
                    double dDist = (rsGeometry2.dx - rsGeometry.dx) * (rsGeometry2.dx - rsGeometry.dx) +
                                   (rsGeometry2.dy - rsGeometry.dy) * (rsGeometry2.dy - rsGeometry.dy);

                    if (rsOID != rsOID2 && Math.Sqrt(dDist) < m_pPara.dPointDist)
                    {
                        // ��ҽ����¼
                        PointDistInfo PtInfo = new PointDistInfo();

                        PtInfo.dDistance = Math.Round(Math.Sqrt(dDist), 2);

                        PtInfo.OID1 = Convert.ToInt32(rsOID);
                        PtInfo.OID2 = Convert.ToInt32(rsOID2);
                        m_aryResult.Add(PtInfo);
                        break;
                    }
                }
            }

            ClearMap();

            return true;
        }