Determine whether a point is within an ellipse

Does Cesium have a function to determine whether a point falls within an ellipse? This is currently what I'm using, but it's not as precise as I need it to be.

/* Test whether point (x,y) falls within ellipse centered at (h,k); since Cesium's distances are in meters, the degrees must be converted into meters */
function(x, y) {
    var hInMeters = this.h * (111319.5 * Math.cos(this.k));
    var kInMeters = this.k * 111111.1;
    var xInMeters = x * (111319.5 * Math.cos(y));
    var yInMeters = y * 111111.1;
    var cosA = Math.cos(this.rotation);
    var sinA = Math.sin(this.rotation);

    /* minMin and majMaj are the squares of the respective radii */
    var minMin = (this.minorAxis / 2) * (this.minorAxis / 2);
    var majMaj = (this.majorAxis / 2) * (this.majorAxis / 2);
      
    var calcA = (cosA * (xInMeters - hInMeters)) + (sinA * (yInMeters - kInMeters));
    var calcB = (sinA * (xInMeters - hInMeters)) - (cosA * (yInMeters - kInMeters));

    /* if the result is less than 1, the point falls within the ellipse. */
    var result = ((calcA * calcA) / minMin) + ((calcB * calcB) / majMaj)
}

Hi there,

We don’t have direct support for this, but (haven’t tested it) at a glance your logic looks reasonable. This should be pretty similar to computing the points on the perimeter of the ellipse.

Hope that helps,

  • Rachel