Agent.Point3d.DistanceSquared C# (CSharp) Method

DistanceSquared() public method

public DistanceSquared ( Point3d pt ) : double
pt Point3d
return double
    public double DistanceSquared(Point3d pt)
    {
      return (Math.Pow(this.X - pt.X, 2) +
              Math.Pow(this.Y - pt.Y, 2) +
              Math.Pow(this.Z - pt.Z, 2));
    }

Usage Example

Example #1
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();
                    if (p1.DistanceSquared(p2) < r * r)
                    {
                        neighbors.Add(other);
                    }
                }
            }

            return(neighbors);
        }