Skip to content
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

applying transform #1111

Closed
smoothumut opened this issue May 7, 2024 · 2 comments
Closed

applying transform #1111

smoothumut opened this issue May 7, 2024 · 2 comments

Comments

@smoothumut
Copy link

Hi Marco,

I have this code and trying to change the transformation of the c2 object but I cant succeed with it.
Am I doing something wrong here, or there is a something wrong in apply_transform?

    from vedo import Cube, show, settings,LinearTransform
    settings.use_parallel_projection = True
    import numpy as np
    
    
    c1 = Cube().rotate_z(25).pos(2,1).mirror().alpha(0.5)
    c1.transform.print()  

    T = c1.transform  
 
    c2 = Cube().c('red4').wireframe().lw(10).lighting('off')

    c2.apply_transform(T)     ### this one works
 
    
    new_transform = LinearTransform()  ## or c2.transform
    np_identity = np.eye(4)
    np_identity[0][3] = 0.1
    new_transform.matrix = np_identity
    
    c2.apply_transform(new_transform, concatenate=False)
    
    show(c2, "The c2 should be close to identity!", axes=1).close()

In the code above, I have changed the np_identity little bit, otherwise apply transform skip the transormation and return itself.
Also how can I reset the object's transformation and apply a matrix to an object

Many thanks in advance

@marcomusy
Copy link
Owner

Thanks @smoothumut I have removed the concatenate kw in the master version.

from vedo import Cube, show, settings, LinearTransform
import numpy as np

settings.use_parallel_projection = True

c1 = Cube().rotate_z(25).pos(2,1).mirror().alpha(0.5)
c1.transform.print()  

T = c1.transform  

c2 = Cube().c('red4').wireframe().lw(10).lighting('off')

c2.apply_transform(T)     ### this one works

# new_transform = LinearTransform()  ## or c2.transform
np_identity = np.eye(4)
np_identity[0][3] = 0.0001
# new_transform.matrix = np_identity

c2.apply_transform(T.compute_inverse()).apply_transform(np_identity)

show(c2, "The c2 should be close to identity!", axes=1).close()

the best way to undo a transformation is to make a copy of the original object. Otherwise you may invert the transformation and apply this inverse.

@smoothumut
Copy link
Author

Thank you very much Marco,
It helped a lot 👍
Have a great day

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

No branches or pull requests

2 participants