角度¶
完整名称: manim.mobject.geometry.line.Angle
- class Angle(line1, line2, radius=None, quadrant=(1, 1), other_angle=False, dot=False, dot_radius=None, dot_distance=0.55, dot_color=ManimColor('#FFFFFF'), elbow=False, **kwargs)[source]¶
基类:
VMobject
一个表示两条线之间角度的圆弧或弯头类型mobject。
- 参数:
line1 (Line) – 第一条线。
line2 (Line) – 第二条线。
radius (float | None) –
Arc
的半径。quadrant (AngleQuadrant) – 确定使用哪个象限的两个
int
数字序列。第一个值指示是使弧线锚定在第一条线的终点 (1) 还是起点 (-1) 附近,第二个值类似地指示第二条线的终点 (1) 还是起点 (-1)。可能的取值有: (1,1), (-1,1), (1,-1), (-1,-1)。other_angle (bool) – 在由两点和弧心定义的两个可能角度之间切换。如果设置为 False(默认值),弧线将始终从 line1 上的点逆时针旋转,直到到达 line2 上的点。如果设置为 True,角度将从 line1 顺时针旋转到 line2。
dot (bool) – 允许在弧中添加一个
Dot
。主要用作表示直角的约定。该点可在接下来的三个参数中进行自定义。dot_radius (float | None) –
Dot
的半径。如果未另行指定,此半径将是弧半径的 1/10。dot_distance (float) – 从中心到弧的相对距离:0 表示点在中心,1 表示点在弧本身上。
dot_color (ParsableManimColor) –
Dot
的颜色。elbow (bool) – 生成表示直角的弯头类型mobject,更多信息和简写请参见
RightAngle
。**kwargs (Any) – 传递给
Arc
或Elbow
构造函数的其他关键字参数。
示例
第一个示例显示了一些中间带点的直角,而第二个示例显示了两条线定义的所有 8 种可能的角度。
示例: RightArcAngleExample ¶
from manim import * class RightArcAngleExample(Scene): def construct(self): line1 = Line( LEFT, RIGHT ) line2 = Line( DOWN, UP ) rightarcangles = [ Angle(line1, line2, dot=True), Angle(line1, line2, radius=0.4, quadrant=(1,-1), dot=True, other_angle=True), Angle(line1, line2, radius=0.5, quadrant=(-1,1), stroke_width=8, dot=True, dot_color=YELLOW, dot_radius=0.04, other_angle=True), Angle(line1, line2, radius=0.7, quadrant=(-1,-1), color=RED, dot=True, dot_color=GREEN, dot_radius=0.08), ] plots = VGroup() for angle in rightarcangles: plot=VGroup(line1.copy(),line2.copy(), angle) plots.add(plot) plots.arrange(buff=1.5) self.add(plots)
class RightArcAngleExample(Scene): def construct(self): line1 = Line( LEFT, RIGHT ) line2 = Line( DOWN, UP ) rightarcangles = [ Angle(line1, line2, dot=True), Angle(line1, line2, radius=0.4, quadrant=(1,-1), dot=True, other_angle=True), Angle(line1, line2, radius=0.5, quadrant=(-1,1), stroke_width=8, dot=True, dot_color=YELLOW, dot_radius=0.04, other_angle=True), Angle(line1, line2, radius=0.7, quadrant=(-1,-1), color=RED, dot=True, dot_color=GREEN, dot_radius=0.08), ] plots = VGroup() for angle in rightarcangles: plot=VGroup(line1.copy(),line2.copy(), angle) plots.add(plot) plots.arrange(buff=1.5) self.add(plots)
示例: AngleExample ¶
from manim import * class AngleExample(Scene): def construct(self): line1 = Line( LEFT + (1/3) * UP, RIGHT + (1/3) * DOWN ) line2 = Line( DOWN + (1/3) * RIGHT, UP + (1/3) * LEFT ) angles = [ Angle(line1, line2), Angle(line1, line2, radius=0.4, quadrant=(1,-1), other_angle=True), Angle(line1, line2, radius=0.5, quadrant=(-1,1), stroke_width=8, other_angle=True), Angle(line1, line2, radius=0.7, quadrant=(-1,-1), color=RED), Angle(line1, line2, other_angle=True), Angle(line1, line2, radius=0.4, quadrant=(1,-1)), Angle(line1, line2, radius=0.5, quadrant=(-1,1), stroke_width=8), Angle(line1, line2, radius=0.7, quadrant=(-1,-1), color=RED, other_angle=True), ] plots = VGroup() for angle in angles: plot=VGroup(line1.copy(),line2.copy(), angle) plots.add(VGroup(plot,SurroundingRectangle(plot, buff=0.3))) plots.arrange_in_grid(rows=2,buff=1) self.add(plots)
class AngleExample(Scene): def construct(self): line1 = Line( LEFT + (1/3) * UP, RIGHT + (1/3) * DOWN ) line2 = Line( DOWN + (1/3) * RIGHT, UP + (1/3) * LEFT ) angles = [ Angle(line1, line2), Angle(line1, line2, radius=0.4, quadrant=(1,-1), other_angle=True), Angle(line1, line2, radius=0.5, quadrant=(-1,1), stroke_width=8, other_angle=True), Angle(line1, line2, radius=0.7, quadrant=(-1,-1), color=RED), Angle(line1, line2, other_angle=True), Angle(line1, line2, radius=0.4, quadrant=(1,-1)), Angle(line1, line2, radius=0.5, quadrant=(-1,1), stroke_width=8), Angle(line1, line2, radius=0.7, quadrant=(-1,-1), color=RED, other_angle=True), ] plots = VGroup() for angle in angles: plot=VGroup(line1.copy(),line2.copy(), angle) plots.add(VGroup(plot,SurroundingRectangle(plot, buff=0.3))) plots.arrange_in_grid(rows=2,buff=1) self.add(plots)
示例: FilledAngle ¶
from manim import * class FilledAngle(Scene): def construct(self): l1 = Line(ORIGIN, 2 * UP + RIGHT).set_color(GREEN) l2 = ( Line(ORIGIN, 2 * UP + RIGHT) .set_color(GREEN) .rotate(-20 * DEGREES, about_point=ORIGIN) ) norm = l1.get_length() a1 = Angle(l1, l2, other_angle=True, radius=norm - 0.5).set_color(GREEN) a2 = Angle(l1, l2, other_angle=True, radius=norm).set_color(GREEN) q1 = a1.points # save all coordinates of points of angle a1 q2 = a2.reverse_direction().points # save all coordinates of points of angle a1 (in reversed direction) pnts = np.concatenate([q1, q2, q1[0].reshape(1, 3)]) # adds points and ensures that path starts and ends at same point mfill = VMobject().set_color(ORANGE) mfill.set_points_as_corners(pnts).set_fill(GREEN, opacity=1) self.add(l1, l2) self.add(mfill)
class FilledAngle(Scene): def construct(self): l1 = Line(ORIGIN, 2 * UP + RIGHT).set_color(GREEN) l2 = ( Line(ORIGIN, 2 * UP + RIGHT) .set_color(GREEN) .rotate(-20 * DEGREES, about_point=ORIGIN) ) norm = l1.get_length() a1 = Angle(l1, l2, other_angle=True, radius=norm - 0.5).set_color(GREEN) a2 = Angle(l1, l2, other_angle=True, radius=norm).set_color(GREEN) q1 = a1.points # save all coordinates of points of angle a1 q2 = a2.reverse_direction().points # save all coordinates of points of angle a1 (in reversed direction) pnts = np.concatenate([q1, q2, q1[0].reshape(1, 3)]) # adds points and ensures that path starts and ends at same point mfill = VMobject().set_color(ORANGE) mfill.set_points_as_corners(pnts).set_fill(GREEN, opacity=1) self.add(l1, l2) self.add(mfill)
方法
属性
animate (动画)
用于动画化
self
的任何方法的应用。animation_overrides (动画覆盖)
颜色
depth (深度)
mobject 的深度。
fill_color (填充颜色)
如果存在多种颜色(用于渐变),则返回第一种颜色
height (高度)
mobject 的高度。
n_points_per_curve (每条曲线的点数)
sheen_factor (光泽因子)
stroke_color (描边颜色)
width (宽度)
mobject 的宽度。
- _original__init__(line1, line2, radius=None, quadrant=(1, 1), other_angle=False, dot=False, dot_radius=None, dot_distance=0.55, dot_color=ManimColor('#FFFFFF'), elbow=False, **kwargs)¶
初始化自身。有关准确签名,请参阅 help(type(self))。
- 参数:
line1 (Line)
line2 (Line)
radius (float | None)
quadrant (AngleQuadrant)
other_angle (bool)
dot (bool)
dot_radius (float | None)
dot_distance (float)
dot_color (ParsableManimColor)
elbow (bool)
kwargs (Any)
- 返回类型:
无
- static from_three_points(A, B, C, **kwargs)[source]¶
线段 AB 和 BC 之间的角度。
这会构造角度 \(\\angle ABC\)。
- 参数:
A (Point3DLike) – 第一个角边(线段)的端点
B (Point3DLike) – 角度的顶点
C (Point3DLike) – 第二个角边(线段)的端点
**kwargs (Any) – 其他关键字参数将传递给
Angle
。
- 返回:
Angle(line1, line2, radius=0.5, quadrant=(-1,1), stroke_width=8), Angle(line1, line2, radius=0.7, quadrant=(-1,-1), color=RED, other_angle=True),
- 返回类型:
从三个点计算的角度
示例
示例: AngleFromThreePointsExample ¶
from manim import * class AngleFromThreePointsExample(Scene): def construct(self): sample_angle = Angle.from_three_points(UP, ORIGIN, LEFT) red_angle = Angle.from_three_points(LEFT + UP, ORIGIN, RIGHT, radius=.8, quadrant=(-1,-1), color=RED, stroke_width=8, other_angle=True) self.add(red_angle, sample_angle)
class AngleFromThreePointsExample(Scene): def construct(self): sample_angle = Angle.from_three_points(UP, ORIGIN, LEFT) red_angle = Angle.from_three_points(LEFT + UP, ORIGIN, RIGHT, radius=.8, quadrant=(-1,-1), color=RED, stroke_width=8, other_angle=True) self.add(red_angle, sample_angle)
- get_lines()[source]¶
获取构成
Angle
类角度的线。示例
>>> line_1, line_2 = Line(ORIGIN, RIGHT), Line(ORIGIN, UR) >>> angle = Angle(line_1, line_2) >>> angle.get_lines() VGroup(Line, Line)
- get_value(degrees=False)[source]¶
获取
Angle
类角度的值。- 参数:
degrees (bool) – 一个布尔值,用于决定返回角度值的单位(度/弧度)。
- 返回:
一个
Angle
类角度的度/弧度值。- 返回类型:
浮点数
示例
示例: GetValueExample ¶
from manim import * class GetValueExample(Scene): def construct(self): line1 = Line(LEFT+(1/3)*UP, RIGHT+(1/3)*DOWN) line2 = Line(DOWN+(1/3)*RIGHT, UP+(1/3)*LEFT) angle = Angle(line1, line2, radius=0.4) value = DecimalNumber(angle.get_value(degrees=True), unit=r"^{\circ}") value.next_to(angle, UR) self.add(line1, line2, angle, value)
class GetValueExample(Scene): def construct(self): line1 = Line(LEFT+(1/3)*UP, RIGHT+(1/3)*DOWN) line2 = Line(DOWN+(1/3)*RIGHT, UP+(1/3)*LEFT) angle = Angle(line1, line2, radius=0.4) value = DecimalNumber(angle.get_value(degrees=True), unit=r"^{\circ}") value.next_to(angle, UR) self.add(line1, line2, angle, value)