示例#1
1
 /// <summary>
 /// Given an array of edges, weeds out any edges
 /// not present on the desired plane
 /// </summary>
 /// <param name="xyzArray">the array of edges </param>
 /// <param name="normal">normal to the desired plane</param>
 /// <returns>edges on the desired plane</returns>
 public static EdgeArray GetEdgesOnPlane(EdgeArray edgeArray, XYZ normal)
 {
     EdgeArray edgesOnPlane = new EdgeArray();
     for (int i = 0; i < edgeArray.Size; i++) {
         IList<XYZ> xyzArray = edgeArray.get_Item(i).Tessellate();
         if (normal.Equals(GeomUtils.kXAxis)) {
             if (xyzArray[0].X == xyzArray[1].X) {
                 edgesOnPlane.Append(edgeArray.get_Item(i));
             }
         }
         if (normal.Equals(GeomUtils.kYAxis)) {
             if (xyzArray[0].Y == xyzArray[1].Y) {
                 edgesOnPlane.Append(edgeArray.get_Item(i));
             }
         }
         if (normal.Equals(GeomUtils.kZAxis)) {
             if (xyzArray[0].Z == xyzArray[1].Z) {
                 edgesOnPlane.Append(edgeArray.get_Item(i));
             }
         }
     }
     return edgesOnPlane;
 }
示例#2
0
        Mirror(Curve curve, XYZ axis, Application app)
        {
            XYZ startPt = curve.GetEndPoint(0);
            XYZ endPt   = curve.GetEndPoint(1);
            XYZ p       = new XYZ();

            XYZ newStart = null;
            XYZ newEnd   = null;

            if (axis.Equals(GeomUtils.kXAxis))
            {
                newStart = new XYZ(startPt.X, -startPt.Y, startPt.Z);
                newEnd   = new XYZ(endPt.X, -endPt.Y, endPt.Z);
            }
            if (axis.Equals(GeomUtils.kYAxis))
            {
                newStart = new XYZ(-startPt.X, startPt.Y, startPt.Z);
                newEnd   = new XYZ(-endPt.X, -endPt.Y, endPt.Z);
            }
            if (axis.Equals(GeomUtils.kZAxis))
            {
                newStart = new XYZ(startPt.X, startPt.Y, -startPt.Z);
                newEnd   = new XYZ(endPt.X, endPt.Y, -endPt.Z);
            }
            return(Line.CreateBound(startPt, endPt));
        }
示例#3
0
        GetEdgesOnPlane(EdgeArray edgeArray, XYZ normal)
        {
            EdgeArray edgesOnPlane = new EdgeArray();

            for (int i = 0; i < edgeArray.Size; i++)
            {
                IList <XYZ> xyzArray = edgeArray.get_Item(i).Tessellate();
                if (normal.Equals(GeomUtils.kXAxis))
                {
                    if (xyzArray[0].X == xyzArray[1].X)
                    {
                        edgesOnPlane.Append(edgeArray.get_Item(i));
                    }
                }
                if (normal.Equals(GeomUtils.kYAxis))
                {
                    if (xyzArray[0].Y == xyzArray[1].Y)
                    {
                        edgesOnPlane.Append(edgeArray.get_Item(i));
                    }
                }
                if (normal.Equals(GeomUtils.kZAxis))
                {
                    if (xyzArray[0].Z == xyzArray[1].Z)
                    {
                        edgesOnPlane.Append(edgeArray.get_Item(i));
                    }
                }
            }
            return(edgesOnPlane);
        }
示例#4
0
        GetEdgesOnPlaneAtOffset(EdgeArray edgeArray, XYZ normal, double offset)
        {
            EdgeArray edgesAtOffset = new EdgeArray();

            edgeArray = GetEdgesOnPlane(edgeArray, normal);
            for (int i = 0; i < edgeArray.Size; i++)
            {
                IList <XYZ> xyzArray = edgeArray.get_Item(i).Tessellate();
                if (normal.Equals(GeomUtils.kXAxis))
                {
                    if ((xyzArray[0].X == offset))
                    {
                        edgesAtOffset.Append(edgeArray.get_Item(i));
                    }
                }
                if (normal.Equals(GeomUtils.kYAxis))
                {
                    if (xyzArray[0].Y == offset)
                    {
                        edgesAtOffset.Append(edgeArray.get_Item(i));
                    }
                }
                if (normal.Equals(GeomUtils.kZAxis))
                {
                    if (xyzArray[0].Z == offset)
                    {
                        edgesAtOffset.Append(edgeArray.get_Item(i));
                    }
                }
            }
            return(edgesAtOffset);
        }
 public XYZ GetDestination(XYZ source)
 {
     if (source.Equals(Endpoint1))
     {
         return(Endpoint2);
     }
     if (source.Equals(Endpoint2))
     {
         return(Endpoint1);
     }
     throw new InvalidOperationException("Invalid portal entry location: " + source);
 }
示例#6
0
        public void Test_XYZTests_Equals_NotEquals()
        {
            XYZ a = new XYZ(1, 2, 3);
            XYZ b = new XYZ(1, 2, 3);
            XYZ c = new XYZ(1, 3, 2);

            Assert.True(a.Equals(b), "Equality failure");
            Assert.False(a.Equals(c), "Inequality failure");

            Assert.Equal(a, b);
            Assert.NotEqual(a, c);
        }
示例#7
0
        public static XYZ GetClosestPt(XYZ pt, List <XYZ> pts)
        {
            XYZ    xyz = new XYZ();
            double num = 0.0;

            foreach (XYZ xyz2 in pts)
            {
                bool flag = !pt.Equals(xyz2);
                if (flag)
                {
                    double num2  = Math.Sqrt(Math.Pow(pt.X - xyz2.X, 2.0) + Math.Pow(pt.Y - xyz2.Y, 2.0) + Math.Pow(pt.Z - xyz2.Z, 2.0));
                    bool   flag2 = xyz.IsZeroLength();
                    if (flag2)
                    {
                        num = num2;
                        xyz = xyz2;
                    }
                    else
                    {
                        bool flag3 = num2 < num;
                        if (flag3)
                        {
                            num = num2;
                            xyz = xyz2;
                        }
                    }
                }
            }
            return(xyz);
        }
示例#8
0
        GetClosestPt(XYZ pt, System.Collections.Generic.IList <XYZ> pts)
        {
            XYZ    closestPt   = new XYZ();
            Double closestDist = 0.0;

            foreach (XYZ ptTemp in pts)
            {
                /// don't consider the pt itself
                if (pt.Equals(ptTemp))
                {
                    continue;
                }

                Double dist = Math.Sqrt(Math.Pow((pt.X - ptTemp.X), 2.0) +
                                        Math.Pow((pt.Y - ptTemp.Y), 2.0) +
                                        Math.Pow((pt.Z - ptTemp.Z), 2.0));

                if (closestPt.IsZeroLength())
                {
                    closestDist = dist;
                    closestPt   = ptTemp;
                }
                else
                {
                    if (dist < closestDist)
                    {
                        closestDist = dist;
                        closestPt   = ptTemp;
                    }
                }
            }
            return(closestPt);
        }
示例#9
0
        public override void Correct(EpochSatellite epochSatellite)
        {
            Time gpsTime = epochSatellite.RecevingTime;

            IEphemeris      sat = epochSatellite.Ephemeris;
            SatelliteNumber prn = epochSatellite.Prn;

            //计算太阳位置方法
            //XYZ sunPosition = epochSatellite.EpochInfo.DataSouceProvider.UniverseObjectProvider.GetSunPosition(gpsTime);

            //新的计算太阳位置方法
            Time tutc = gpsTime.GpstToUtc();

            //查找地球自转信息
            Gnsser.Data.ErpItem erpv = null;
            if (DataSouceProvider.ErpDataService != null)
            {
                erpv = DataSouceProvider.ErpDataService.Get(tutc);
            }
            if (erpv == null)
            {
                erpv = ErpItem.Zero;
            }

            XYZ sunPosition = new XYZ();

            DataSouceProvider.UniverseObjectProvider.GetSunPosition(gpsTime, erpv, ref sunPosition);

            //use L1 value
            IAntenna antenna = DataSouceProvider.AntennaDataSource.Get(prn.ToString(), gpsTime);

            if (antenna == null)
            {
                return;
            }

            string AntennaType = antenna.AntennaType;

            XYZ svPos = sat.XYZ;

            XYZ receiverPosition = epochSatellite.SiteInfo.EstimatedXyz;

            if (receiverPosition.Equals(XYZ.Zero))
            {
                return;
            }

            bool cycleSlip = epochSatellite.IsUnstable;

            if (cycleSlip || !PhaseManager.Contains(prn)) //a cycle slip happend
            {
                PhaseManager[prn] = new SatVectorPhase();
            }

            double windUpCorrection = GetSatPhaseWindUpCorectValue(prn, gpsTime, svPos, receiverPosition, sunPosition, AntennaType);

            //double windUpCorrection2 = GetSatPhaseWindUpCorectValue(satelliteType, gpsTime, svPos, receiverPosition, epochSatellite, sunPosition);

            this.Correction = (windUpCorrection);
        }
示例#10
0
 public static XYZ Greater(XYZ pt1, XYZ pt2, XYZ axis)
 {
     XYZ result = new XYZ();
     if (axis.Equals(XYZ.BasisX))
     {
         result = ((!(pt1.X > pt2.X)) ? pt2 : pt1);
     }
     if (axis.Equals(XYZ.BasisY))
     {
         result = ((!(pt1.Y > pt2.Y)) ? pt2 : pt1);
     }
     if (axis.Equals(XYZ.BasisZ))
     {
         result = ((!(pt1.Z > pt2.Z)) ? pt2 : pt1);
     }
     return result;
 }
示例#11
0
        Mirror(XYZ point, XYZ axis)
        {
            XYZ Point = null;

            if (axis.Equals(GeomUtils.kXAxis))
            {
                Point = new XYZ(point.X, -point.Y, point.Z);
            }
            if (axis.Equals(GeomUtils.kYAxis))
            {
                Point = new XYZ(-point.X, point.Y, point.Z);
            }
            if (axis.Equals(GeomUtils.kZAxis))
            {
                Point = new XYZ(point.X, point.Y, -point.Z);
            }
            return(Point);
        }
示例#12
0
        Greater(XYZ pt1, XYZ pt2, XYZ axis)
        {
            XYZ pt = new XYZ();

            if (axis.Equals(kXAxis))
            {
                if (pt1.X > pt2.X)
                {
                    pt = pt1;
                }
                else
                {
                    pt = pt2;
                }
            }
            if (axis.Equals(kYAxis))
            {
                if (pt1.Y > pt2.Y)
                {
                    pt = pt1;
                }
                else
                {
                    pt = pt2;
                }
            }
            if (axis.Equals(kZAxis))
            {
                if (pt1.Z > pt2.Z)
                {
                    pt = pt1;
                }
                else
                {
                    pt = pt2;
                }
            }

            return(pt);
        }
示例#13
0
        public static XYZ Greater(XYZ pt1, XYZ pt2, XYZ axis)
        {
            XYZ  result = new XYZ();
            bool flag   = axis.Equals(XYZ.BasisX);

            if (flag)
            {
                result = ((pt1.X <= pt2.X) ? pt2 : pt1);
            }
            bool flag2 = axis.Equals(XYZ.BasisY);

            if (flag2)
            {
                result = ((pt1.Y <= pt2.Y) ? pt2 : pt1);
            }
            bool flag3 = axis.Equals(XYZ.BasisZ);

            if (flag3)
            {
                result = ((pt1.Z <= pt2.Z) ? pt2 : pt1);
            }
            return(result);
        }
示例#14
0
        public void AddPathToDestination(XYZ nextNode)
        {
            if (nextNode.Equals(_currentNode))
            {
                return;
            }
            var path = _pathFinder.GetPath(_currentNode, nextNode);

            if (!path.IsValid)
            {
                throw new InvalidPathException("No path found!");
            }
            _segments.Add(path);
            _currentNode = nextNode;
        }
示例#15
0
        /// <summary>
        /// 构建一个首次方差参数顺序:xyz
        /// </summary>
        /// <param name="rowCol">行列数量</param>
        /// <param name="baseParamCount">基础参数数量</param>
        /// <param name="xyzRms">初始坐标RMS</param>
        /// <returns></returns>
        public static WeightedVector GetInitDoubleAprioriParam(int rowCol, int baseParamCount, XYZ xyzRms)
        {
            //   int rowCol = EpochData.NumOfUnknowns;
            DiagonalMatrix initCova = new DiagonalMatrix(rowCol);

            double[] initCovaVector = initCova.Vector;
            //Fill the initialErrorCovariance matrix

            //Second, the coordinates
            for (int i = 0; i < 3; i++)
            {
                if (!xyzRms.Equals(XYZ.Zero))
                {
                    initCovaVector[i] = Math.Pow(xyzRms[i], 2); //(1 m)  ^*2
                }
                else
                {
                    initCovaVector[i] = 10000.0; //(100 m)  ^*2
                }
            }

            ////Third, the receiver clock
            //initCova[3][3] = 9.0e10;    //(300 km) ^*2
            if (baseParamCount == 4)
            {
                //First, the zenital wet tropospheric delay
                initCova[3, 3] = 0.25;    //(0.5 m) ^*2
            }
            if (baseParamCount == 5)
            {
                //First, the zenital wet tropospheric delay
                initCova[3, 3] = 0.25;    //(0.5 m) ^*2

                //First, the zenital wet tropospheric delay
                initCova[4, 4] = 0.25;    //(0.5 m) ^*2
            }
            ////First, the ionosphere delay
            //initCova[5][5] = 0.25;    //(0.5 m) ^*2


            //Finally, the phase biases
            for (int i = baseParamCount; i < rowCol; i++)
            {
                // initCova[time][time] = 1.0e100;   //(20000 km) ^*2
                initCovaVector[i] = 4.0e14;   //(20000 km) ^*2
            }
            return(new WeightedVector(new Vector(rowCol), initCova));
        }
示例#16
0
        /// 构建一个首次方差参数顺序:xyz dt ,没有对流层
        /// </summary>
        /// <param name="rowCol"></param>
        /// <param name="xyzRms"></param>
        /// <param name="isSiteFixed"></param>
        /// <returns></returns>
        public static WeightedVector GetInitTropAugCombinedAprioriParam(int Totalsystem, int rowCol, XYZ xyzRms, bool isSiteFixed = false)
        {
            //   int rowCol = EpochData.NumOfUnknowns;
            DiagonalMatrix initCova = new DiagonalMatrix(rowCol);

            double[] initCovaVector = initCova.Vector;
            //double[][] initCova = MatrixUtil.Create(rowCol, rowCol);
            //Fill the initialErrorCovariance matrix
            int i = 0;

            if (!isSiteFixed)
            {
                //Second, the coordinates
                for (i = 0; i < 3; i++)
                {
                    if (!xyzRms.Equals(XYZ.Zero))
                    {
                        initCovaVector[i] = Math.Pow(xyzRms[i], 2); //(1 m)  ^*2
                    }
                    else
                    {
                        initCovaVector[i] = 10000.0; //(100 m)  ^*2
                    }
                }
            }

            //Third, the receiver clock
            initCovaVector[3] = 9.0e10;    //(300 km) ^*2
            //First, the 系统时间偏差,没有对流层
            for (i = 4; i < 4 - 1 + Totalsystem; i++)
            {
                initCovaVector[i] = 0.25;
            }

            //Finally, the phase biases
            for (i = 4 - 1 + Totalsystem; i < rowCol; i++)
            {
                // initCova[time][time] = 1.0e100;   //(20000 km) ^*2
                //initCova[i][i] = 4.0e14;   //(20000 km) ^*2
                initCovaVector[i] = 4.0e14;   //已对齐相位,应该和伪距精度相同
            }
            return(new WeightedVector(new Vector(rowCol), initCova));
        }
        /// <summary>
        /// Transforms XYZ color to destination reference white.
        /// </summary>
        public XYZ Transform(XYZ sourceColor, XYZ sourceWhitePoint, XYZ targetWhitePoint)
        {
            if (sourceColor == null)
            {
                throw new ArgumentNullException(nameof(sourceColor));
            }

            if (sourceWhitePoint == null)
            {
                throw new ArgumentNullException(nameof(sourceWhitePoint));
            }

            if (targetWhitePoint == null)
            {
                throw new ArgumentNullException(nameof(targetWhitePoint));
            }

            if (sourceWhitePoint.Equals(targetWhitePoint))
            {
                return(sourceColor);
            }

            var sourceColorLMS = _conversionToLMS.Convert(sourceColor);

            if (sourceWhitePoint != _lastSourceWhitePoint || targetWhitePoint != _lastTargetWhitePoint)
            {
                var sourceWhitePointLMS = _conversionToLMS.Convert(sourceWhitePoint);
                var targetWhitePointLMS = _conversionToLMS.Convert(targetWhitePoint);

                _cachedDiagonalMatrix = Matrix.Diagonal(targetWhitePointLMS.L / sourceWhitePointLMS.L, targetWhitePointLMS.M / sourceWhitePointLMS.M, targetWhitePointLMS.S / sourceWhitePointLMS.S);
                _lastSourceWhitePoint = sourceWhitePoint;
                _lastTargetWhitePoint = targetWhitePoint;
            }

            var targetColorLMS = new LMS(_cachedDiagonalMatrix.Multiply(sourceColorLMS.Vector));
            var targetColor    = _conversionToXYZ.Convert(targetColorLMS);

            return(targetColor);
        }
示例#18
0
        private Path FindPath(XYZ start, XYZ end)
        {
            var startsOffMap        = start.Equals(SpecialLocation.OffOfMap);
            var endsOffMap          = end.Equals(SpecialLocation.OffOfMap);
            var onMapStartLocations = startsOffMap ? GetOnMapEndpoints() : new List <XYZ> {
                start
            };
            var onMapEndLocations = endsOffMap ? GetOnMapEndpoints() : new List <XYZ> {
                end
            };
            var path = FindPath(onMapStartLocations, onMapEndLocations);

            if (startsOffMap)
            {
                path.Insert(0, SpecialLocation.OffOfMap);
            }
            if (endsOffMap)
            {
                path.Add(end);
            }
            return(new Path(path));
        }
示例#19
0
 public static XYZ GetClosestPt(XYZ pt, List<XYZ> pts)
 {
     XYZ xYZ = new XYZ();
     double num = 0.0;
     foreach (XYZ pt2 in pts)
     {
         if (!pt.Equals(pt2))
         {
             double num2 = Math.Sqrt(Math.Pow(pt.X - pt2.X, 2.0) + Math.Pow(pt.Y - pt2.Y, 2.0) + Math.Pow(pt.Z - pt2.Z, 2.0));
             if (xYZ.IsZeroLength())
             {
                 num = num2;
                 xYZ = pt2;
             }
             else if (num2 < num)
             {
                 num = num2;
                 xYZ = pt2;
             }
         }
     }
     return xYZ;
 }
示例#20
0
        public static XYZ GetClosestPoint(this XYZ pt, List <XYZ> pts)
        {
            XYZ    xyz  = new XYZ();
            double num1 = 0.0;

            foreach (XYZ pt1 in pts)
            {
                if (!pt.Equals((object)pt1))
                {
                    double num2 = Math.Sqrt(Math.Pow(pt.X - pt1.X, 2.0) + Math.Pow(pt.Y - pt1.Y, 2.0) + Math.Pow(pt.Z - pt1.Z, 2.0));
                    if (xyz.IsZeroLength())
                    {
                        num1 = num2;
                        xyz  = pt1;
                    }
                    else if (num2 < num1)
                    {
                        num1 = num2;
                        xyz  = pt1;
                    }
                }
            }
            return(xyz);
        }
示例#21
0
        /// <summary>
        /// given an array of pts, find the closest
        /// pt to a given pt
        /// </summary>
        /// <param name="pt"></param>
        /// <param name="pts"></param>
        /// <returns></returns>
        public static XYZ GetClosestPt(XYZ pt, System.Collections.Generic.IList<XYZ> pts)
        {
            XYZ closestPt = new XYZ();
            Double closestDist = 0.0;

            foreach( XYZ ptTemp in pts )
            {
                /// don't consider the pt itself
                if (pt.Equals(ptTemp))
                    continue;

                Double dist = Math.Sqrt(Math.Pow((pt.X - ptTemp.X), 2.0) +
                    Math.Pow((pt.Y - ptTemp.Y), 2.0) +
                    Math.Pow((pt.Z - ptTemp.Z), 2.0));

                if (closestPt.IsZeroLength()) {
                    closestDist = dist;
                    closestPt = ptTemp;
                }
                else {
                    if (dist < closestDist) {
                        closestDist = dist;
                        closestPt = ptTemp;
                    }
                }
            }
            return closestPt;
        }
示例#22
0
 public static bool Equals(XYZ source, RGB target)
 {
     return(source.Equals(ColorConverter.RgbToXyz(target)));
 }
示例#23
0
    public void Update()
    {
        UpdateAttack();
        UpdateMovement();

        void UpdateWeapon()
        {
            if (weapon == null || !actor.Inventory.Contains(weapon) || weapon.Gun.AmmoLeft + weapon.Gun.ClipLeft == 0)
            {
                weapon = actor.Inventory.FirstOrDefault(i => i.Gun != null && i.Gun.AmmoLeft + i.Gun.ClipLeft > 0);
            }
        }

        void UpdateAttack()
        {
            if (attack == null || attack.Done())
            {
                UpdateWeapon();
                if (weapon == null)
                {
                    return;
                }
                var enemies = new HashSet <Entity>();
                foreach (var point in actor.World.entities.space.Keys)
                {
                    if (((XYZ)point - actor.Position).Magnitude < 100)
                    {
                        enemies.UnionWith(actor.World.entities[point].OfType <ICharacter>());
                    }
                }
                enemies.Remove(actor);
                enemies = enemies.Where(e => (e.Position - actor.Position).Magnitude < weapon.Gun.range).ToHashSet();
                if (enemies.Any())
                {
                    var target = enemies.First();
                    attack = new ShootAction(actor, weapon, new TargetEntity(target));
                    actor.Actions.Add(attack);
                }
            }
        }

        void UpdateMovement()
        {
            if (movement == null || movement.Done())
            {
                UpdateWeapon();
                if (weapon == null)
                {
                    var weapons = new HashSet <IItem>();
                    foreach (var point in actor.World.entities.space.Keys)
                    {
                        if (((XYZ)point - actor.Position).Magnitude < 100)
                        {
                            weapons.UnionWith(actor.World.entities[point].OfType <IItem>());
                        }
                    }
                    if (!weapons.Any())
                    {
                        UpdateWander();
                        return;
                    }
                    var target = weapons.OrderBy(w => (w.Position - actor.Position).Magnitude2).First();

                    Dictionary <(int, int, int), (int, int, int)> prev = new Dictionary <(int, int, int), (int, int, int)>();
                    var points = new SimplePriorityQueue <XYZ, double>();
                    //Truncate to integer coordinates so we don't get confused by floats
                    (int, int, int)start    = target.Position.i;
                    (int, int, int)actorPos = actor.Position.i;
                    prev[start]             = start;
                    points.Enqueue(start, 0);
                    int  seen    = 0;
                    bool success = false;
                    while (points.Any() && seen < 500 && !success)
                    {
                        var point = points.Dequeue();

                        foreach (var offset in new XYZ[] { new XYZ(0, 1), new XYZ(1, 0), new XYZ(0, -1), new XYZ(-1, 0) })
                        {
                            var next = point + offset;
                            if (prev.ContainsKey(next))
                            {
                                continue;
                            }
                            else if (CanOccupy(next))
                            {
                                prev[next] = point;
                                //Truncate to integer coordinates so we don't get confused by floats
                                if (next.Equals(actorPos))
                                {
                                    success = true;
                                    break;
                                }
                                else
                                {
                                    points.Enqueue(next, (next - actorPos).Magnitude);
                                }
                            }
                        }
                    }

                    if (success)
                    {
                        LinkedList <XYZ> path = new LinkedList <XYZ>();

                        XYZ p = prev[actor.Position];
                        path.AddLast(p);
                        while (!p.Equals(start))
                        {
                            p = prev[p];
                            path.AddLast(p);
                        }

                        movement = new CompoundAction(new FollowPath(actor, path), new TakeItem(actor, target));
                        actor.Actions.Add(movement);
                    }
                    else
                    {
                        UpdateWander();
                    }
                }
                else
                {
                    UpdateWander();
                }
            }
        }

        void UpdateWander()
        {
            HashSet <(int, int, int)> known               = new HashSet <(int, int, int)>();
            HashSet <XYZ>             accessible          = new HashSet <XYZ>();
            Dictionary <(int, int, int), (XYZ, int)> prev = new Dictionary <(int, int, int), (XYZ, int)>();
            Queue <XYZ> points = new Queue <XYZ>();

            var start = actor.Position.i;

            points.Enqueue(start);
            prev[start] = (null, 0);
            int seen = 0;

            while (points.Count > 0 && seen < 500)
            {
                var point = points.Dequeue().i;
                known.Add(point);
                seen++;
                if (CanOccupy(point))
                {
                    accessible.Add(point);
                    foreach (var offset in new XYZ[] { new XYZ(0, 1), new XYZ(1, 0), new XYZ(0, -1), new XYZ(-1, 0) })
                    {
                        var next = point + offset;
                        var dist = prev[point].Item2 + 1;
                        if (known.Add(next))
                        {
                            prev[next] = (point, dist);
                            points.Enqueue(next);
                        }
                        else if (prev.TryGetValue(next, out (XYZ, int)v) && v.Item2 > dist)
                        {
                            prev[next] = (point, dist);
                        }
                    }
                }
            }

            var dest = accessible.OrderByDescending(xyz => (actor.Position - xyz).Magnitude2).ElementAt(new Random().Next(0, 4));
            var path = new LinkedList <XYZ>();

            while (dest != null)
            {
                path.AddFirst(dest);
                XYZ next;
                (next, _) = prev[dest];
                dest      = next;
            }
            movement = new FollowPath(actor, path);
            actor.Actions.Add(movement);
        }

        bool CanOccupy(XYZ position)
        {
            var v     = actor.World.voxels.Try(position);
            var below = actor.World.voxels.Try(position.PlusZ(-1));

            return(v is Air || v is Floor || below?.Collision == VoxelType.Solid);
        }
    }
示例#24
0
 public static bool Equals(XYZ source, HSL target)
 {
     return(source.Equals(ColorConverter.HslToXyz(target)));
 }
示例#25
0
 public static bool Equals(XYZ source, CMYK target)
 {
     return(source.Equals(ColorConverter.CmykToXyz(target)));
 }
示例#26
0
 /// <summary>
 /// Given an array of edges, weeds out any edges
 /// not present at the given offset
 /// </summary>
 /// <param name="edgeArray">the array of edges </param>
 /// <param name="normal">normal to the desired plane</param>
 /// <param name="offset">offset from the plane</param>
 /// <returns>edges on a plane at given offset</returns>
 public static EdgeArray GetEdgesOnPlaneAtOffset(EdgeArray edgeArray, XYZ normal, double offset)
 {
     EdgeArray edgesAtOffset = new EdgeArray();
     edgeArray = GetEdgesOnPlane(edgeArray, normal);
     for (int i = 0; i < edgeArray.Size; i++) {
         IList<XYZ> xyzArray = edgeArray.get_Item(i).Tessellate();
         if (normal.Equals(GeomUtils.kXAxis)) {
             if ((xyzArray[0].X == offset)) {
                 edgesAtOffset.Append(edgeArray.get_Item(i));
             }
         }
         if (normal.Equals(GeomUtils.kYAxis)) {
             if (xyzArray[0].Y == offset) {
                 edgesAtOffset.Append(edgeArray.get_Item(i));
             }
         }
         if (normal.Equals(GeomUtils.kZAxis)) {
             if (xyzArray[0].Z == offset) {
                 edgesAtOffset.Append(edgeArray.get_Item(i));
             }
         }
     }
     return edgesAtOffset;
 }
示例#27
0
        /// <summary>
        /// 改正
        /// </summary>
        /// <param name="input"></param>
        public override void Correct(EpochSatellite input)
        {
            var correction = new Dictionary <RinexSatFrequency, double>();

            this.Correction = correction;

            IAntenna antenna = input.SiteInfo.Antenna;

            if (antenna == null)
            {
                if (!WarnedSites.Contains(input.SiteInfo.SiteName))
                {
                    WarnedSites.Add(input.SiteInfo.SiteName);
                    log.Warn(input.Name + "接收机天线为: " + input.SiteInfo.AntennaType + ", " + input.SiteInfo.AntennaNumber + " 没有在天线文件夹中找到该类型的天线,无法进行 PCV 改正,精度影响可达10厘米(特别是高程)!请到 https://www.ngs.noaa.gov/ANTCAL/ 下载对应天线改正信息,并追加到.atx文件中");
                }
                return;
            }
            List <RinexSatFrequency> frequences = input.RinexSatFrequences;

            XYZ rcvPos = input.SiteInfo.EstimatedXyz;

            if (rcvPos.Equals(XYZ.Zero))//测站未获取近似值,不改正
            {
                log.Warn(input.ReceiverTime + ", " + input.Name + ", 测站未获取近似值,不改正PCV");
                this.Correction = correction;
                return;
            }

            var elev = input.GeoElevation;
            var azim = input.Polar.Azimuth;

            foreach (var item in antenna.Data)
            {
                var    satFreq = item.Key;
                double pcv     = 0;
                if (IsUseAzimuthAntenna)
                {
                    pcv = antenna.GetPcvValue(satFreq, elev, azim);
                }
                else
                {
                    pcv = antenna.GetPcvValue(satFreq, elev);
                    ///**PCV 是站星距离,不是ENU, 不用再次改正 */
                    //不信,可以试试:转换成站星方向改正等效距离算法如下:
                    //double rangeCorretion = CoordUtil.GetDirectionLength(pcv, input.Polar);
                    ////approx, 用以验证
                    //double test = pcv.U * Math.Sin(input.GeoElevation * Geo.CoordConsts.DegToRadMultiplier);
                    //double differ = rangeCorretion - test;
                }

                correction.Add(satFreq, pcv);
            }

            //多频的权宜之计
            if (input.EpochInfo.SatelliteTypes.Count > 0)
            {
                correction[RinexSatFrequency.BdsA]     = antenna.GetPcvValue(RinexSatFrequency.GpsA, elev);
                correction[RinexSatFrequency.BdsB]     = antenna.GetPcvValue(RinexSatFrequency.GpsB, elev);
                correction[RinexSatFrequency.GalileoA] = correction[RinexSatFrequency.BdsA];
                correction[RinexSatFrequency.GalileoB] = correction[RinexSatFrequency.BdsB];
            }
            this.Correction = correction;
        }
示例#28
0
        /// <summary>
        /// Given a point, mirrors it along the given axis
        /// </summary>
        /// <param name="point">point to mirror</param>
        /// <param name="axiz">axis to mirror along</param>
        /// <returns>a mirrored point</returns>
        public static XYZ Mirror(XYZ point, XYZ axis)
        {
            XYZ Point = null;
            if (axis.Equals(GeomUtils.kXAxis)) {
                Point = new XYZ(point.X, -point.Y, point.Z);
            }
            if (axis.Equals(GeomUtils.kYAxis)) {
                Point = new XYZ(-point.X, point.Y, point.Z);

            }
            if (axis.Equals(GeomUtils.kZAxis)) {
                Point = new XYZ(point.X, point.Y, -point.Z);

            }
            return Point;
        }
示例#29
0
        /// <summary>
        /// Given a curve, mirrors it along the given axis
        /// </summary>
        /// <param name="curve">curve to mirror</param>
        /// <param name="axis">axis to mirror along</param>
        /// <param name="app">revit application</param>
        /// <returns>a mirrored curve</returns>
        public static Curve Mirror(Curve curve, XYZ axis, Application app)
        {
            XYZ startPt = curve.GetEndPoint(0);
            XYZ endPt = curve.GetEndPoint(1);
            XYZ p = new XYZ();

            XYZ newStart = null;
            XYZ newEnd = null;

            if (axis.Equals(GeomUtils.kXAxis)) {
                newStart = new XYZ(startPt.X, -startPt.Y, startPt.Z);
                newEnd = new XYZ(endPt.X, -endPt.Y, endPt.Z);
            }
            if (axis.Equals(GeomUtils.kYAxis)) {
                newStart = new XYZ(-startPt.X, startPt.Y, startPt.Z);
                newEnd = new XYZ(-endPt.X, -endPt.Y, endPt.Z);
            }
            if (axis.Equals(GeomUtils.kZAxis)) {
                newStart = new XYZ(startPt.X, startPt.Y, -startPt.Z);
                newEnd = new XYZ(endPt.X, endPt.Y, -endPt.Z);
            }
            return Line.CreateBound(startPt, endPt);
        }
示例#30
0
        /// <summary>
        /// Given two points and an axis, returns the 
        /// point with the greater value along the axis
        /// </summary>
        /// <param name="pt1">point 1 to compare</param>
        /// <param name="pt2">point 2 to compare</param>
        /// <param name="axis">axis to compare along</param>
        /// <returns></returns>
        public static XYZ Greater(XYZ pt1, XYZ pt2, XYZ axis)
        {
            XYZ pt = new XYZ();

            if(axis.Equals(kXAxis)){
                if (pt1.X > pt2.X)
                    pt = pt1;
                else
                    pt = pt2;
            }
            if (axis.Equals(kYAxis)) {
                if (pt1.Y > pt2.Y)
                    pt = pt1;
                else
                    pt = pt2;
            }
            if (axis.Equals(kZAxis)) {
                if (pt1.Z > pt2.Z)
                    pt = pt1;
                else
                    pt = pt2;
            }

            return pt;
        }