I am trying to plot Cassini ovals in Python using these parametric equations for x,y.
https://mathcurve.com/courbes2d.gb/cassini/cassini.shtml
Here is my program.
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
cnt = 20
plt.figure(figsize=(12,8))
for a in np.linspace(1,20,cnt):
b = 0.9*a
t = np.linspace(a + np.sqrt(a**2-b**2), a + np.sqrt(a**2+b**2),200)
x = (b**4 - t**4)/(4*a*(t**2))
y = np.sqrt(t**2 - ((x-a)**2))
plt.plot(x, y)
plt.plot(x, -y)
I am not sure if it works OK, I do get some nice plot but I am not sure if the Cassini ovals are full. Are they full/complete or just partially plotted? Btw, they just look like circles, not quite what I was hoping for.
When I increase
cnt(say to 100), I start getting weird warningsRuntimeWarning: invalid value encountered in sqrt: y = np.sqrt(t**2 - ((x-a)**2))I don't know why I am not getting these warnings when cnt is smaller. Why am I getting these for larger values ofcnt?
How can I fix this code?
The first picture below is for cnt=20, the second one is for cnt=100.
The second one has these blank areas, I think that's where the quantity under the sqrt sign becomes negative (or something), and probably that's when I get these warnings. But why? I just programmed literally the two parametric equations. I am not quite sure what's wrong.



