admin管理员组文章数量:1356860
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.
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.
Share Improve this question asked Mar 31 at 7:08 just_a_kid_coder_123just_a_kid_coder_123 1058 bronze badges 1 |1 Answer
Reset to default 1for 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 fet 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)
hope this helps you
本文标签: pythonHow to achieve similar desmos visuals in manimStack Overflow
版权声明:本文标题:python - How to achieve similar desmos visuals in manim - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743963603a2569481.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
np.sqrt( value )
rather thanvalue
puts it a little closer, but still not quite the same. I also suspect that you used a 5 rather than a 15 inside the sin() term to produce your manim image: count the peaks. – lastchance Commented Mar 31 at 9:25