Jump to content

Donovan

Members
  • Posts

    2
  • Joined

  • Last visited

Reputation

0 Neutral

Profile Information

  • About me
    Curious George
  1. There is a really fast way to compute the shortest distance between a point and a line segment that doesn't require any trig functions or vectors. It should also solve vardicd's problem. There are two cases to consider: the projection of the point may be outside the line segment or it may be between the endpoints of the line segment (note that a is the distance to the closer endpoint). In both cases, the law of cosines gives: The "outside" case is θ > 90°, which is equivalent to cos θ < 0 and d2 + a2 - b2 < 0 (since the denominator cannot be negative). In other words, this numerator tells us which case we are in. In the "outside" case the distance is just a. In the "between" case the distance is the height of the triangle: Note that the quantity being squared is the same numerator as before. I wrote up a quick function that you can use as a helper in your ToadicusTools (didn't have a chance to compile and test it though). It cross-multiplies in order to avoid the division, so this is literally just some addition/subtraction/multiplication of doubles. /// <summary> /// Returns true if CelestialBody does not occlude the distant point from the local point, false otherwise. /// </summary> /// <returns><c>true</c>, if this Vessel has line of sight to the target Vessel, <c>false</c> otherwise.</returns> /// <param name="sqrA">The square of the distance from the local point to the center of the CelestialBody</param> /// <param name="sqrB">The square of the distance from the distant point to the center of the CelestialBody</param> /// <param name="sqrD">The square of the distance from the local point to the distant point</param> /// <param name="sqrRadius">The square of the radius of the CelestialBody, including any "grace" ratio.</param> private static bool IsLineOfSightHelper( double sqrA, double sqrB, double sqrD, double sqrRadius ) { // Make it so A is the shorter of the two distances to the CelestialBody if ( sqrA > sqrB ) { double temp = sqrA; sqrA = sqrB; sqrB = temp; } // Calculate numerator double num = sqrD + sqrA - sqrB; // Handle case where the projected center of the CelestialBody is outside the two points if ( num <= 0 ) return sqrA >= sqrRadius; // Handle case where the projected center of the CelestialBody is between the two points return 4 * sqrD * sqrA - num * num >= 4 * sqrD * sqrRadius; } Donovan
  2. Does anyone have a working download link for this now that SpacePort is gone?
×
×
  • Create New...