网站建设市场需求分析,a站插画,上海网页制作找哪家,杭州软件定制用Manim实现——计算和绘制图形下方区域
get_area 函数 get_area是一个用于计算和绘制图形下方区域的函数#xff0c;常用于图形动画库#xff08;如 Manim#xff09;
get_area(graph, x_rangeNone, color(ManimColor(#58C4DD),ManimColor(#83C167)), opacity0.3, bounde…用Manim实现——计算和绘制图形下方区域
get_area 函数 get_area是一个用于计算和绘制图形下方区域的函数常用于图形动画库如 Manim
get_area(graph, x_rangeNone, color(ManimColor(#58C4DD),ManimColor(#83C167)), opacity0.3, bounded_graphNone, **kwargs)
它主要用于在特定图形graph下方填充颜色以便可视化特定区间上方的面积。
参数解释 graph: 要填充其下方区域的图形对象。通常是一个数学函数图形。 x_range: 绘制区域的 x 范围。可以是一个元组例如 (x_start, x_end)用于指定在哪个 x 轴范围内填充颜色。 color: 这是一个包含两个颜色的元组用于填充图形下方区域的渐变颜色。例子中使用了 ManimColor 类来为颜色提供支持。 opacity: 确定填充颜色的不透明度值通常在 0 到 1 之间0 表示完全透明1 表示完全不透明。 bounded_graph: 可选参数通常用于指定一个函数作图的下界。 kwargs: 其他可选关键字参数可以用于进一步自定义图形的属性或行为。 示例1
from manim import * class GetAreaExample012(Scene): def construct(self): ax Axes().add_coordinates() curve ax.plot(lambda x: 2 * np.sin(x), colorDARK_BLUE) sin_x Text(sin(x), colorRED).scale(1).next_to(curve, UP3*RIGHT, -0.4)# 计算面积区域 area ax.get_area( curve, x_range(PI / 2, 3 * PI / 2), color(GREEN_A, GREEN_E), opacity1, ) self.add(ax, curve, area,sin_x) # 在面积上方添加圆圈及“” plus_circle Circle(radius0.2, colorWHITE).shift(ax.c2p(2*PI/3, 1)) # 调整位置 plus_text Text(, colorRED).scale(0.65).move_to(plus_circle.get_center()) # 在面积下方添加圆圈及“-” minus_circle Circle(radius0.2, colorWHITE).shift(ax.c2p(1PI ,-1)) # 调整位置 minus_text Text(-, colorYELLOW).scale(1.52).move_to(minus_circle.get_center()) # 添加圆圈和文本 self.add(plus_circle, plus_text, minus_circle, minus_text) 运行结果 示例2
from manim import * class AreaUnderGraph011(Scene): def construct(self): # 创建一个正弦函数 graph FunctionGraph(np.sin, x_range[-3, 3], colorBLUE) ax Axes().add_coordinates()# 获取图形下方区域 area ax.get_area( graph, x_range[0, PI], color(ManimColor(#58C4DD), ManimColor(#83C167)), opacity0.5 ) # 添加图形和填充区域到场景中 self.add(ax,graph, area) # 动画效果 self.play(Create(graph), FadeIn(area)) self.wait(2)
运行结果
示例3
from manim import *
import numpy as np class AreaUnderCustomGraph003(Scene): def construct(self): # 定义自定义函数 f(x) def f(x): return np.exp(-x**2) # 例如高斯函数 # 创建函数图形 graph FunctionGraph(f, x_range[-3, 3], colorYELLOW) ax Axes().add_coordinates()# 获取图形下方区域 area ax.get_area( graph, x_range[-3, 3],colorBLUE, opacity0.5, stroke_width0 ) # 添加图形和填充区域到场景中 self.add(ax,graph, area) # 动画效果 self.play(Create(graph), FadeIn(area)) self.wait(2)
运行结果