Comments (6)
The problem only arises when later adding a tip to the NumberLine()
object. Scaling of both tipped and untipped nmberlines works as expected
class nlineScaling(Scene):
def construct(self):
nline1 = NumberLine(
x_range=[0,10,1],
length=8,
font_size=16,
label_direction=UP,
).add_numbers().to_corner(UL)
dot1 = Dot(nline1.n2p(5),color=RED)
self.add(nline1, dot1)
nline2 = nline1.copy().scale(1.5).next_to(nline1,DOWN,aligned_edge=LEFT)
dot2 = Dot(nline2.n2p(5),color=BLUE)
self.add(nline2,dot2)
nline3 = nline2.copy().next_to(nline2,DOWN,aligned_edge=LEFT)
nline3.add_tip()
dot3 = Dot(nline3.n2p(5),color=YELLOW)
self.add(nline3,dot3)
nline4 = NumberLine(
x_range=[0,10,1],
length=12,
font_size=16,
label_direction=UP,
include_tip=True,
).add_numbers().next_to(nline3,DOWN,aligned_edge=LEFT)
dot4 = Dot(nline4.n2p(5),color=TEAL)
self.add(nline4,dot4)
nline5 = NumberLine(
x_range=[0,10.5,1],
length=12.5,
font_size=16,
label_direction=UP,
include_tip=True,
).add_numbers().next_to(nline4,DOWN,aligned_edge=LEFT)
dot5 = Dot(nline5.n2p(5),color=ORANGE)
self.add(nline5,dot5)
nline6 = nline5.copy().scale(0.7).next_to(nline5,DOWN,aligned_edge=LEFT)
dot6 = Dot(nline6.n2p(5),color=GREEN)
self.add(nline6,dot6)
from manim.
I may take a stab at this one, if no one objects.
from manim.
I have been doing some digging when I have the chance, and it seems if you remove and replace the ticks and numbers after adding the tip places them in the same positions as if the tip is added during creation. This makes sense, since it is what occurs during initialization. It seems the easy fix would be to reset these within add_tip, but to me it seems like not the right way to go about this.
Here's an example that shows what I mean.
class nlineScaling(Scene):
def construct(self):
# add_tip by itself
nline1 = NumberLine(
x_range=[0,10,1],
length=8,
font_size=16,
label_direction=UP,
).add_numbers().to_corner(UL)
nline1.add_tip()
dot = Dot(nline1.n2p(5), color=YELLOW)
self.add(nline1, dot)
# add_tip, followed by resetting the ticks
nline2 = NumberLine(
x_range=[0,10,1],
length=8,
font_size=16,
label_direction=UP,
).add_numbers().next_to(nline1,DOWN,aligned_edge=LEFT)
nline2.add_tip()
nline2.remove(nline2.ticks).remove(nline2.numbers)
nline2.add_ticks()
nline2.add_numbers()
dot2 = Dot(nline2.n2p(5), color=RED)
self.add(nline2, dot2)
# Adding the tip from the beginning
nline3 = NumberLine(
x_range=[0,10,1],
length=8,
font_size=16,
label_direction=UP,
include_tip=True,
).add_numbers().next_to(nline2,DOWN,aligned_edge=LEFT)
dot3 = Dot(nline3.n2p(5), color=GREEN)
self.add(nline3, dot3)
and the resulting image
I also suspect there may be a deeper issue with the way add_tip works, but it'll take a bit more digging.
from manim.
Looking into theTipableVMobject
class, the end of the number line should be at the base of the tip, but is instead being set to the end of the tip when calculating the tick locations and any other use of n2p
. n2p
is incorrectly incorporating the length of the tip into its calculations. Oddly enough, calling add_tip
after creation actually results in the correct display for the number line (with the end of the number line placed at the base of the tip), though subsequent n2p
calls result in incorrect locations being calculated along the number line.
So the solution should be as "simple" as removing the length of the tip from the calculations for n2p
.
from manim.
Ok, I think I got it!
The issue was with the way the TipableVMobject
defined get_end
(and by extension get_start
). It was using the tip's get_end
method, which doesn't actually get the base location, but rather the end of the polygon that defines the arrow tip (which happens to be the very tip of the arrow).
def get_end(self) -> Point3D:
if self.has_tip():
return self.tip.get_end()
else:
return super().get_end()
By changing the method to use the tip's base
property, it fixes the positioning problem.
def get_end(self) -> Point3D:
if self.has_tip():
return self.tip.base
else:
return super().get_end()
Using the same test code from above with the updated get_end
method, I get the following image:
Now, there's an issue with the last line where it doesn't show the last tick mark.
from manim.
Ok, got the tick mark appearing the same after adding a tip after the fact as well as during creation.
And with the code supplied by @uwezi
from manim.
Related Issues (20)
- 'RuntimeWarning: divide by zero encountered in scalar divide' causing Axes rendering failure for axis values 0 HOT 3
- How do I set the background color of code in Manim? HOT 1
- SurroundingRectangle supports *mobjects
- Improvement on the python-dev version
- Trying to make a vector field, I got a message telling me to make a bug report HOT 1
- Axes don't work correctly HOT 3
- Tex-Mobject width and font_size arguments affect eachother HOT 4
- Updaters not refreshing between animations HOT 1
- Axes and the unit_size HOT 3
- Uhhh... help? HOT 1
- Manim HOT 1
- Manim render command leads to "cannot import name 'DEFAULT_DASH_LENGTH' from 'manim.mobject.geometry'" error HOT 1
- Color palette format and builder
- LaggedStart animation bugs when z-index of animated mobject is non-positive HOT 4
- Text repr to display current text
- ParametricFunction: wrong type hint HOT 1
- Transparent background with Opengl
- apply_complex_function HELP HOT 3
- Intersection and difference bug HOT 3
- ValueTracker bug HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from manim.