Skip to content

Instantly share code, notes, and snippets.

@uwezi
Last active September 4, 2024 19:19
Show Gist options
  • Save uwezi/1d489c4e6689445445eb5a584bad67c6 to your computer and use it in GitHub Desktop.
Save uwezi/1d489c4e6689445445eb5a584bad67c6 to your computer and use it in GitHub Desktop.
[area to y-axis] Get the area between y-axis and curve. #manim #plot #area #axes
from manim import *
# https://discord.com/channels/581738731934056449/753938743366254642/1280965870239223920
class Test(Scene):
def construct(self):
ax1 = Axes(
x_range=[-1, 7, 10],
y_range=[0, 6, 10],
x_length=6,
y_length=5
).add_coordinates()
ax1_labels = ax1.get_axis_labels()
ax1_group = VGroup(ax1, ax1_labels)
f2 = ax1.plot(lambda x: 0.3*x**2, x_range=[0, 4.65538, 0.001], color=BLUE)
self.add(ax1_group, f2)
rect1 = Polygon(
ax1.c2p(0,0),
ax1.c2p(4.65538,0),
ax1.c2p(4.65538,6),
ax1.c2p(0,6),
fill_opacity=0.7
)
self.add(rect1)
area_under = ax1.get_area(f2)
self.add(area_under)
area_above = Difference(rect1,area_under)
self.wait()
self.remove(rect1,area_under)
self.add(area_above)
y1 = 1
y2 = 4
rect = Polygon(
ax1.c2p(0,y1),
ax1.c2p(7,y1),
ax1.c2p(7,y2),
ax1.c2p(0,y2),
fill_opacity=0.7
)
self.add(rect)
area_to_y = Intersection(rect,area_above).set_fill(opacity=0.6,color=RED)
self.add(area_to_y)
self.wait()
self.remove(rect,area_above)
self.wait()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment