コード例 #1
0
ファイル: NeighborsComponent.cs プロジェクト: vctcn93/Quelea
        private ISpatialCollection <IQuelea> GetNeighborsInVisionAngle(ISpatialCollection <IQuelea> neighborsInSphere)
        {
            ISpatialCollection <IQuelea> neighborsInVisionAngle = new SpatialCollectionAsList <IQuelea>();
            Point3d  position = agent.Position;
            Vector3d velocity = agent.Velocity;
            Plane    pl1      = new Plane(position, velocity);

            pl1.Rotate(-RS.HALF_PI, pl1.YAxis);
            Plane pl2 = pl1;

            pl2.Rotate(-RS.HALF_PI, pl1.XAxis);
            double halfVisionAngle = agent.VisionAngle * visionAngleMultiplier / 2;

            foreach (IQuelea neighbor in neighborsInSphere)
            {
                Vector3d diff   = Util.Vector.Vector2Point(position, neighbor.Position);
                double   angle1 = Util.Vector.CalcAngle(velocity, diff, pl1);
                double   angle2 = Util.Vector.CalcAngle(velocity, diff, pl2);
                if (Util.Number.DefinitelyLessThan(angle1, halfVisionAngle, Constants.AbsoluteTolerance) &&
                    Util.Number.DefinitelyLessThan(angle2, halfVisionAngle, Constants.AbsoluteTolerance))
                {
                    neighborsInVisionAngle.Add(neighbor);
                }
            }

            return(neighborsInVisionAngle);
        }
コード例 #2
0
        public ISpatialCollection <T> GetNeighborsInSphere(T item, double r)
        {
            ISpatialCollection <T> neighbors = new SpatialCollectionAsList <T>();
            IPosition position = (IPosition)item;

            foreach (T other in this.spatialObjects)
            {
                // DK: changed this:
                // IPosition otherPosition = (IPosition)other;
                // double d = position.getPoint3d().DistanceTo(otherPosition.getPoint3d());
                // if (d < r && !Object.ReferenceEquals(item, other))
                // {
                //   neighbors.Add(other);
                // }
                // to this:
                if (!Object.ReferenceEquals(item, other))
                {
                    Point3d p1       = position.GetPoint3D();
                    Point3d p2       = ((IPosition)other).GetPoint3D();
                    double  dSquared = (Math.Pow(p1.X - p2.X, 2) +
                                        Math.Pow(p1.Y - p2.Y, 2) +
                                        Math.Pow(p1.Z - p2.Z, 2));
                    if (dSquared < r * r)
                    {
                        neighbors.Add(other);
                    }
                }
            }

            return(neighbors);
        }
コード例 #3
0
        public ISpatialCollection <T> GetNeighborsInSphere(T item, double r)
        {
            double rSquared = r * r;
            // ISpatialCollection<T> neighbors = new SpatialCollectionAsBinLattice<T>();
            IPosition position = (IPosition)item;
            //LinkedList<T> possibleNeighbors = getBin(item);
            List <T> possibleNeighbors       = GetBins(item, r);
            ISpatialCollection <T> neighbors = new SpatialCollectionAsList <T>();

            foreach (T other in possibleNeighbors)
            {
                if (!Object.ReferenceEquals(item, other))
                {
                    Point3d p1 = position.GetPoint3D();
                    Point3d p2 = ((IPosition)other).GetPoint3D();
                    if (Util.Point.DistanceSquared(p1, p2) < rSquared)
                    {
                        neighbors.Add(other);
                    }
                }
            }

            return(neighbors);
        }
コード例 #4
0
 public SpatialCollectionAsList(SpatialCollectionAsList <T> collection)
 {
     this.spatialObjects = collection.spatialObjects;
 }