from manim import *
class Dot3DPositions(ThreeDScene):
    """3.1 Dot3D 本质是小球，radius 决定大小、resolution 决定球面精细度。
    用 axes.c2p(x, y, z) 把三维坐标换成场景坐标才不会把点放错位置；
    老示例里的 axes 根本没定义，直接复制会 NameError。
    """
    def construct(self):
        self.set_camera_orientation(phi=65 * DEGREES, theta=-50 * DEGREES)
        title = Text("Dot3D 的位置、大小与颜色", font="STLiti", font_size=32).to_edge(UP)
        self.add_fixed_in_frame_mobjects(title)
        axes = ThreeDAxes(x_range=[-4, 4, 1], y_range=[-4, 4, 1],
                          z_range=[-4, 4, 1], x_length=7, y_length=7, z_length=5)
        dot1 = Dot3D(point=axes.c2p(1, 2, 3))
        dot2 = Dot3D(point=axes.c2p(2, 3, -1), radius=0.22, color=RED)
        legend = VGroup(
            Text("白点：默认 radius=0.08、白色", font="STLiti", font_size=21, color=WHITE),
            Text("红点：radius=0.22、color=RED", font="STLiti", font_size=21, color=RED),
        ).arrange(DOWN, aligned_edge=LEFT, buff=0.16).to_corner(UL).shift(DOWN * 1.2)
        self.add_fixed_in_frame_mobjects(legend)
        self.play(FadeIn(title), run_time=0.6)
        self.play(FadeIn(axes), run_time=1.4)
        self.play(LaggedStart(FadeIn(dot1), FadeIn(dot2),
                              lag_ratio=0.5, run_time=1.4))
        self.play(FadeIn(legend), run_time=0.8)
        note = Text("点位用 axes.c2p(1,2,3) 换算，三维坐标不是屏幕坐标",
                    font="STLiti", font_size=20, color=YELLOW).to_edge(DOWN)
        self.add_fixed_in_frame_mobjects(note)
        self.play(FadeIn(note), run_time=0.6)
        self.wait(2.6)
