Пример #1
0
 /// <summary>
 /// is the other atom above this one
 /// </summary>
 /// <param name="other_atom"></param>
 public float Above(nodeSpatial other_atom)
 {
     float dist = position[axis_vertical] - other_atom.position[axis_vertical];
     if (dist > 0)
         return(dist);
     else
         return(-1);
 }
Пример #2
0
        /// <summary>
        /// returns the relative distance of atom1 from this atom compared to atom2
        /// eg. "is X further away from you than Y?"
        /// </summary>
        /// <param name="other_atom"></param>
        public float GetDistanceRelative(nodeSpatial atom1, nodeSpatial atom2)
        {
            // distance to the first atom
            float dist1 = GetDistance(atom1);

            // distance to the second atom
            float dist2 = GetDistance(atom2);

            return(dist1 - dist2);
        }
Пример #3
0
        /// <summary>
        /// is the first atom more distant from this one than the second
        /// if so return the relative distance
        /// eg. "is X further away from you than Y?" 
        /// </summary>
        /// <param name="other_atom"></param>
        public float MoreDistant(nodeSpatial atom1, nodeSpatial atom2)
        {
            // distance to the first atom
            float dist1 = GetDistance(atom1);

            // distance to the second atom
            float dist2 = GetDistance(atom2);

            if (dist1 > dist2)
                return(dist1 - dist2);
            else
                return(-1);
        }
Пример #4
0
 /// <summary>
 /// returns the distance to another atom in 3D
 /// </summary>
 /// <param name="other_atom"></param>
 public float GetDistance3D(nodeSpatial other_atom)
 {
     return(GetDistance(other_atom, 3));
 }
Пример #5
0
        /// <summary>
        /// returns the distance to another atom
        /// </summary>
        /// <param name="other_atom"></param>
        /// <param name="max_dimensions">maximum number of dimensions to use when calculating distance (for example you might want to restrict distance calculation to 2D)</param>
        public float GetDistance(nodeSpatial other_atom, int max_dimensions)
        {
            float dist = 0;
            for (int i = 0; i < max_dimensions; i++)
            {
                float diff = position[i] - other_atom.position[i];
                dist += (diff * diff);
            }
            dist = (float)Math.Sqrt(dist);

            return(dist);
        }
Пример #6
0
        /// <summary>
        /// returns the distance to another atom
        /// </summary>
        /// <param name="other_atom"></param>
        public float GetDistance(nodeSpatial other_atom)
        {
            // find the smallest number of dimensions
            int dimensions = this.position.Length;
            if (other_atom.position.Length < dimensions)
                dimensions = other_atom.position.Length;

            float dist = 0;
            for (int i = 0; i < dimensions; i++)
            {
                float diff = position[i] - other_atom.position[i];
                dist += (diff * diff);
            }
            dist = (float)Math.Sqrt(dist);

            return(dist);
        }
Пример #7
0
        /// <summary>
        /// is the first atom closer to this one than the second
        /// if so return the relative distance
        /// eg. "is X closer to you than Y?"
        /// </summary>
        /// <param name="other_atom"></param>
        public float CloserTo(nodeSpatial atom1, nodeSpatial atom2)
        {
            // distance to the first atom
            float dist1 = GetDistance(atom1);

            // distance to the second atom
            float dist2 = GetDistance(atom2);

            if (dist1 < dist2)
                return(dist2 - dist1);
            else
                return(-1);
        }
Пример #8
0
 /// <summary>
 /// is the other atom at the same position as this, within some tollerance distance
 /// </summary>
 /// <param name="other_atom"></param>
 public bool AtSamePosition(nodeSpatial other_atom, float tollerance)
 {
     float dist = GetDistance(other_atom);
     if (dist < tollerance)
         return(true);
     else
         return(false);
 }