Skip to content

3D Lines Bending and Changing Colour When Endpoints are Far Away #4243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
charlie572 opened this issue May 9, 2025 · 7 comments
Closed

3D Lines Bending and Changing Colour When Endpoints are Far Away #4243

charlie572 opened this issue May 9, 2025 · 7 comments

Comments

@charlie572
Copy link

Description of bug / unexpected behavior

When the end points of a 3D line are too far outside the scene, the line changes colour, and sometimes curves. I could work around it by moving the end point closer, it was just inconvenient. I've tested it in 2D, and the bug only seems to be present in 3D.

Expected behavior

The line should stay the same colour, and stay straight.

How to reproduce the issue

Code for reproducing the problem
from manim import *

class BendingLine(ThreeDScene):
    def construct(self):
        # Create a point, and move it far away in a particular direction. You get
        # different bugs depending on the starting point and direction

        point = np.array([1, 0, 0], dtype=np.float64)

        # Uncomment one of these lines to see different bugs
        # direction = np.array([1, 1, 0], dtype=np.float64)  # works correctly
        # direction = np.array([2, 0, -1], dtype=np.float64)  # line spreads out
        # direction = np.array([2, 0.1, -1], dtype=np.float64)  # line curves
        direction = np.array([-100000, 0, 0], dtype=np.float64)  # line stays straight, but changes colour

        far_point = point - direction * 100

        # create line
        line = Line3D(ORIGIN, far_point)
        self.add(line)

Additional media files

Images/GIFs

These are the different results you get when uncommenting each of the lines in the code above

Correct behaviour:
Image

Incorrect behaviour:
Image
Image
Image

Logs

Terminal output
Manim Community v0.19.0

[05/09/25 19:38:11] INFO                                scene_file_writer.py:886
                             File ready at                                      
                             '/home/charlie/git_repos/v                         
                             anishing_points/media/imag                         
                             es/bending_line/BendingLin                         
                             e_ManimCE_v0.19.0.png'                             
                                                                                
                    INFO     Rendered BendingLine                   scene.py:255
                             Played 0 animations                                
                    INFO     Previewed File at:                  file_ops.py:237
                             '/home/charlie/git_repos/vanishing_                
                             points/media/images/bending_line/Be                
                             ndingLine_ManimCE_v0.19.0.png' 

System specifications

System Details
  • OS (with version, e.g., Windows 10 v2004 or macOS 10.15 (Catalina)): Ubuntu 24.04.2 LTS
  • RAM: 8GB
  • Python version (python/py/python3 --version): 3.13.1
  • Installed modules (provide output from pip list):
audioop-lts       0.2.1
av                13.1.0
beautifulsoup4    4.13.4
click             8.1.8
cloup             3.0.7
decorator         5.2.1
glcontext         3.0.0
isosurfaces       0.1.2
manim             0.19.0
ManimPango        0.6.0
mapbox_earcut     1.0.3
markdown-it-py    3.0.0
mdurl             0.1.2
moderngl          5.12.0
moderngl-window   3.1.1
networkx          3.4.2
numpy             2.2.5
pillow            11.2.1
pip               24.3.1
pycairo           1.28.0
pydub             0.25.1
pyglet            2.1.6
pyglm             2.8.2
Pygments          2.19.1
rich              14.0.0
scipy             1.15.2
screeninfo        0.8.1
skia-pathops      0.8.0.post2
soupsieve         2.7
srt               3.5.3
svgelements       1.9.6
tqdm              4.67.1
typing_extensions 4.13.2
watchdog          6.0.0
LaTeX details
  • LaTeX distribution (e.g. TeX Live 2020): TeX Live 2023
  • Installed LaTeX packages:

Additional comments

@uwezi
Copy link
Contributor

uwezi commented May 9, 2025

The bending is most likely caused by perspective distortion. Try to use a longer "focal distance".

Just for highlighting your problem, here is the rendered output of your code with the bug uncommented:

class BendingLine(ThreeDScene):
    def construct(self):
        # Create a point, and move it far away in a particular direction. You get
        # different bugs depending on the starting point and direction

        point = np.array([1, 0, 0], dtype=np.float64)

        # Uncomment one of these lines to see different bugs
        # direction = np.array([1, 1, 0], dtype=np.float64)  # works correctly
        # direction = np.array([2, 0, -1], dtype=np.float64)  # line spreads out
        direction = np.array([2, 0.1, -1], dtype=np.float64)  # line curves
        # direction = np.array([-100000, 0, 0], dtype=np.float64)  # line stays straight, but changes colour

        far_point = point - direction * 100

        # create line
        line = Line3D(ORIGIN, far_point)
        self.add(line)

Image

class BendingLine(ThreeDScene):
    def construct(self):
        # Create a point, and move it far away in a particular direction. You get
        # different bugs depending on the starting point and direction
        
        self.camera.set_focal_distance(10000)

        point = np.array([1, 0, 0], dtype=np.float64)

        direction = np.array([2, 0.1, -1], dtype=np.float64)  # line curves

        far_point = point - direction * 100

        # create line
        line = Line3D(ORIGIN, far_point)
        self.add(line)

Image

@charlie572
Copy link
Author

Thanks. Does that mean the line is supposed to bend like that?

@uwezi
Copy link
Contributor

uwezi commented May 10, 2025

it's distortion, just like with a true real-world camera lens.

https://photographylife.com/what-is-distortion

Image
https://arindamdhar.com/lenses-and-perspective/

@charlie572
Copy link
Author

Okay, that's good. So the only bug is that the lines change colour.

@uwezi
Copy link
Contributor

uwezi commented May 11, 2025

Okay, that's good. So the only bug is that the lines change colour.

also this is - I assume - not a bug. It's a matter of reflection of the light source in the scene.

class BendingLine(ThreeDScene):
    def construct(self):
        # Create a point, and move it far away in a particular direction. You get
        # different bugs depending on the starting point and direction

        self.camera.set_focal_distance(10000)

        point = np.array([1, 0, 0], dtype=np.float64)

        direction = np.array([2, 0.1, -1], dtype=np.float64)  # line curves

        far_point = point - direction * 100

        # create line
        line = Line3D(ORIGIN, far_point, color=PURE_BLUE)
        self.add(line)

Image

I suggest you come over to Discord and explain what you want to achieve and how you are hindered by ManimCE. The volunteer helpers there will help you. Discussing whether something is a bug or not on very limited details here seems not to be leading anywhere.

https://docs.manim.community/en/stable/faq/general.html?highlight=discord#where-can-i-find-more-resources-for-learning-manim

@uwezi
Copy link
Contributor

uwezi commented May 11, 2025

Changing the thickness (default value is 0.02) of the line or rendering at a higher resolution also gives your lines back more of the low-saturation default colors:

class BendingLine(ThreeDScene):
    def construct(self):
        # Create a point, and move it far away in a particular direction. You get
        # different bugs depending on the starting point and direction

        self.camera.set_focal_distance(10000)

        point = np.array([1, 0, 0], dtype=np.float64)

        direction = np.array([2, 0.1, -1], dtype=np.float64)  # line curves

        far_point = point - direction * 100

        # create line
        line = Line3D(ORIGIN, far_point, thickness=0.1, color=BLUE)
        self.add(line)

Image

@charlie572
Copy link
Author

Your first comment was exactly what I needed. I just left the issue open because I thought there was something in manim that needed to be fixed. If it's not a bug, then I'll close the issue. Thank you for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🆕 New
Development

No branches or pull requests

2 participants