-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Fixed Arrow3D.put_start_and_end_on()
to use the actual end of the arrow
#3706
Fixed Arrow3D.put_start_and_end_on()
to use the actual end of the arrow
#3706
Conversation
…at everything is fine. Issue is solved!
Could a |
Could you send me the code? I will try to figured it out. On discord i have the same nick-name |
Here's a somewhat minimal and reasonably fast snippet for jupyter notebook cells: from manim import *
import numpy as np
def shrink(arrow, *, small=1e-2, animate=False):
hawkeye = arrow.animate if animate else arrow
if not getattr(arrow, 'shrunk', False):
arrow.shrunk = True
vect = normalize(arrow.get_end() - arrow.get_start())
return hawkeye.put_start_and_end_on(arrow.get_start(), vect * small + arrow.get_start())
else:
return hawkeye.set_opacity(0) %%manim -ql -v WARNING TestArrow
class TestArrow(ThreeDScene):
def construct(self):
arrow = Arrow3D(ORIGIN, np.array([1, 1, 0]))
self.add(arrow)
for _ in range(3):
self.play(shrink(arrow, animate=True), rate_func=linear, run_time=0.5)
arrow.set_opacity(1)
# arrow.cone.tip.set_opacity(0)
arrow.shrunk = False
self.play(
arrow.animate.put_start_and_end_on(ORIGIN, np.array([-1, 1, 0])),
rate_func=linear,
run_time=0.5) Maybe a |
Some of the code is also trying to sort out another Arrow3D quirk: arrows can never have zero length or it raises an error about trying to move the endpoints of a closed loop. What would you think about updating Arrow3D's (or maybe better to do Cylinder or Line3D's) def put_start_and_end_on(arrow, start, end, *, animate=False, small=1e-2):
hawkeye = arrow.animate if animate else arrow
if np.array_equal(start, end):
if not getattr(arrow, 'shrunk', False):
arrow.shrunk = True
vect = unit_vector(arrow.get_end() - arrow.get_start())
return hawkeye.put_start_and_end_on(start, vect * small + start)
else:
return hawkeye.set_opacity(0)
else:
arrow.shrunk = False
arrow.set_opacity(1)
arrow.cone.tip.set_opacity(0)
arrow.cone.base_circle.set_opacity(0)
return hawkeye.put_start_and_end_on(start, end) Sorry I hardly ever go on discord. |
I will check this out after Monday, tommorow I will not have enough time. Thanks for the code 🙂 |
Cool -Awesome Change - Makes the System more ROBUST - the scaling factors for Manim is a bit tricky Now that somebody has taken care of the 3D Objects for the General MANIM CE, the Axes-System in ManimLib seems more improved than the before. |
Okay, now I have a little time to think about this, but I just started the project on quantum computing...
I assume that our discussion about the changes and this PR, has to stay here. |
To addition: maybe I have found a solution, but eee i am not sure. What if we in |
Thanks for taking a look! 1-2. I see. Perhaps simply a smaller Dot3D? Or maybe we could override the set_opacity method for the All that said, I think the opacity of the arrow tip is still a fairly minor issue unlikely to affect many users, and this PR brings significant value to anyone using |
Why? I mean, what is the unexpected behavior? |
|
This is my proposition, for cone class def get_end(self) -> np.ndarray:
direction = self.direction / np.linalg.norm(self.direction)
cone_base = self.base_circle.get_center()
return cone_base + direction * self.height |
added: i added self.height parameter in Cone class my tests passes
…nd get_end for the Arrow3D class to ensure they return accurate geometrical points after transformations. Additionally, I've included unit tests to verify the correctness of these methods for the Cone class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Arrow3D.put_start_and_end_on()
to use the actual end of the arrow
self.start_point = VMobject().set_points_as_corners([start] * 3) | ||
self.end_point = VMobject().set_points_as_corners([end] * 3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the tripled reference to start
and end
cause any harm here? (Modifying any of the entries will modify all three of them in the same way.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that it must be the same point three times. Otherwise we will get a 3d curve wich would be visible, and we don't want this. My solution based on merge #3358 or #3718. I am not sure why we might have problem here, because we are calculating everything internally based on user start and end points. Maybe I missunderstood you question
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe he is talking about this behavior
x = [1]
y = [x]*3
x.append(2)
print(y)
Which results in
[[1, 2], [1, 2], [1, 2]]
Because y
simply stores a list of 3 "pointers" to x
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly, this is what I was referring to!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, but should we care about it? They are local variables, as long as direction, get_center and new_height will return propper types we will not have a problem here. I could add type checking but I am not sure that we need it here. Why? Because if direction won't have a proper type cone and cilinder will through the error same for height, if get_center will have invalid type all manim will be broken. I could add it but IMO if the type of the variables used in this method other part of the code will through the error ealier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will push today the VectorizedPoint version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any update on this? It would be nice to have it merged before the v0.19.0 release :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had problems with my laptop (and I was finishing my 4th physic semester)
I will push tuday the newest version of the code
Sorry
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i just switched to new PC, i will install manim tomorrow and then i will add changes -> push.|
For some reason the changes which i made, wasn't saved, i have no idea why
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have seen the changes, thanks!
Overview: What does this pull request change?
I have fixed the issue #3655
the problem was that in the
put_start_and_end_on
method we got the not true end of the arrow, but the end of the cylinder. What I did, was I added the invisible point attached to the tip of the cone, and in theget_end
method I returned the coordinates of this point -> the length of the vector was wrong the saling factor was alwasy larger than 1.In the new implementation, I also changed a little bit of the
Cone
class: the base is always added but with a different opacity, 0 or 1.Motivation and Explanation: Why and how do your changes improve the library?
Links to added or changed documentation pages
#3655
Further Information and Comments
Reviewer Checklist