Skip to content

Instantly share code, notes, and snippets.

@saccadic
Last active July 13, 2020 05:27
Show Gist options
  • Save saccadic/cfd6b7415a163c768bee9fa7915bada3 to your computer and use it in GitHub Desktop.
Save saccadic/cfd6b7415a163c768bee9fa7915bada3 to your computer and use it in GitHub Desktop.
楕円の内外判定
# https://www.tutorialspoint.com/check-if-a-point-is-inside-outside-or-on-the-ellipse-in-cplusplus
def isInsideEllipse(ellipse,point):
(x0, y0), bb, aa, phi_b_deg = ellipse
(x1, y1) = point
angle = np.radians(phi_b_deg)
if aa > bb:
a = aa/2
b = bb/2
else:
a = bb/2
b = aa/2
A = ( (x0 - x1)*np.cos(angle) + (y0 - y1)*np.sin(angle)) / a
B = (-(x0 - x1)*np.sin(angle) + (y0 - y1)*np.cos(angle)) / b
R = A*A+B*B
return R
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment