I am trying to graph this function in manim
x^(2/3) + 0.9sqrt(3.5-x^2) * sin(πx*a)
I wrote some simple code to graph it in an animation like style:
from manim import *
import numpy as np
class HeartAnimation(Scene):
def construct(self):
axes = Axes(
x_range=[-10, 10, 1],
y_range=[-7, 7, 1],
axis_config={"color": BLUE},
)
def heart_curve(x):
value = 3.5-x**2
return np.cbrt(x**2) + 0.9*value*np.sin(np.pi * x * 15)
graph = axes.plot(
heart_curve,
color=RED,
x_range=[-np.sqrt(3.5), np.sqrt(3.5)],
use_smoothing=False
)
self.play(Create(axes))
self.play(Create(graph))
self.wait(8)
the result from this code is this:
and what I was looking for is something like this in desmos
is there someway I can mess with the scaling or zooming to achieve something similar to what is produced in desmos? It doesn't have to be a one to one replicate, but it would be good if more of the heart show and the y axis to be scaled properly as it seems to be stretched in the y axis in manim when compared to desmos.
for the sampling rate, you have to add a third element (which will be the step of your sampling).
However it seems like you can't make it too low, so to work aroud this problem, you can just scale the whole thing to be bigger (on both x and y so that shape doesn't change (in the formulas: x->x/scale and y->y*scale)
for that I added a stretch_factor to the code.
(as the sampling rate is higher, the density of curve increase, don't forget to lower the stroke_width in the plot method)
stroke_width=1
and for the shape, I have reworked your formula by using a heart shaped double parabola instead of cuberoot function.
here is the code :
from manim import *
import numpy as np
class HeartAnimation(Scene):
def construct(self):
axes = Axes(
x_range=[-100, 100, 10],
y_range=[-70, 70, 10],
axis_config={"color": BLUE},
)
def heart_curve(x):
stretch_factor = 2
sinus_amp = 10
x = x/stretch_factor
heart_shaped_parabola = max(-((x-8)/2)**2+25,-((x+8)/2)**2+25)
sinus = sinus_amp*(3.5-(abs(x)/10)**3)*np.sin(np.pi * (x/10) * 15)-sinus_amp*(3.5-(x/10)**2)
y = heart_shaped_parabola+sinus
return y
graph = axes.plot(
heart_curve,
color=RED,
x_range=[-np.sqrt(3.5)*16.6, np.sqrt(3.5)*16.6,0.1],
use_smoothing=False,
stroke_width=1
)
self.play(Create(axes))
self.play(Create(graph))
self.wait(8)