English: The picture shows formula for coordinates of center of mass for the area below a curve. The manim code follows.
from manim import *
class UrcityIntegral(Scene):
def construct(self):
ax = Axes(
x_range=[-0.1,2.2,10],
y_range=[-0.5,7,100],
tips = False,
x_length=12.5,
y_length=6
).shift(0.5*DOWN)
data_x = np.linspace(0,2,1000)
data_y = 4-3*np.cos(data_x/2*3.14)
mx = data_x*data_y
my = 1/2*data_y**2
obsah = np.trapz(data_y,data_x)
xT = np.trapz(mx,data_x)/obsah
yT = np.trapz(my,data_x)/obsah
funkce = ax.plot(
lambda x: 4-3*np.cos(x/2*3.14),
x_range = [0,2,0.01],
use_smoothing=False
).set_color(RED)
popisky_ab = VGroup(
MathTex("a").next_to(ax.c2p(0,0,0),DOWN),
MathTex("b").next_to(ax.c2p(2,0,0),DOWN),
MathTex("x").next_to(ax.get_x_axis(),UP, aligned_edge = RIGHT),
)
final_int = VGroup(
MathTex(r"S = \int_a^b f(x)\mathrm dx"),
MathTex(r"x_T=\frac 1S \int_a^b xf(x)\,\mathrm{d}x"),
MathTex(r"y_T=\frac 1{2S} \int_a^b f^2(x)\,\mathrm{d}x")
).arrange(DOWN, aligned_edge=LEFT)
final_int.set_color(WHITE).to_edge(UL)
rcts = ax.get_riemann_rectangles(
funkce[-1],
x_range=[0, 2],
dx=0.001,
color=(DARK_BLUE),
input_sample_type="center",
stroke_width = 0
).set_z_index(-1)
Teziste_ = Dot(ax.c2p(xT,yT),radius=0.03).scale(3).set_color(WHITE)
Teziste = VGroup(
Teziste_,
MathTex(r"[x_T,y_T]").next_to(Teziste_)
)
self.add(
rcts,
ax.get_x_axis(),
funkce,
popisky_ab,
final_int,
Teziste
)
self.wait()