• Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

ZMT zurich med tech

How to apply transformations (e.g. Rotation, Translation, Scaling) to model objects using Python?

Scheduled Pinned Locked Moved Python API
pythontransformationrotationtranslationapi
1 Posts 1 Posters 521 Views
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SylvainS Offline
    SylvainS Offline
    Sylvain ZMT
    wrote on last edited by
    #1

    There are Python commands to apply Scaling, Translation, or Rotation transformations to any model entity.

    1. You first have to import the right module:
    from s4l_v1.model import Vec3, Translation, Transform
    
    1. Then you have to define a transformation:
    t = Translation(Vec3(-20, -16, 10))  # for a translation
    t = Rotation(Vec3(0, 0, 1), numpy.pi / 4)  # for a rotation of angle pi/4 around the z-axis
    
    1. Finally you can apply the transformation to a model entity:
    case = model.CreateSolidBlock(Vec3(0, 0, 0), Vec3(40, 16, -140))
    case.ApplyTransform( t )
    

    For further example, users are encouraged to look at the tutorial Python Scripts, as described in section "2.19.2 Examples" of Sim4Life user manual:

    Complete Python script examples can be found in the Public Documents folder of your system under:
    \Sim4Life\3.4\Documentation\Tutorials\Tutorial Scripts.
    Alternatively, access the Tutorials folder via the Windows start menu →→ All Programs →→ Sim4Life V 3.4 →→ Documentation →→Explore Documentation and open Tutorials | Tutorial Scripts. These scripts can be executed directly in Sim4Life and faithfully reproduce the workflow of many > of the provided tutorials. They contain diverse examples of:

    • how to generate 3D model objects
    • how to set up different types of simulations
    • how to post-process the results

    Note also that you can find documentation regarding the different possible transformation in the API Browser (click VIEW-> API Browser in the main menu) or type help(Translation) (for example) in the Console:

    >>> help(Translation)
    Help on built-in function Translation in module XCoreMath:
    
    Translation(...)
        Translation( (Vec3)translation_vec3) -> Transform :
            Constructs a translation Transform given by a translation Vec3.
    
    
    
    >>> help(Rotation)
    Help on built-in function Rotation in module XCoreMath:
    
    Rotation(...)
        Rotation( (Vec3)axis, (float)angle_in_rad) -> Transform :
            Constructs a rotation Transform given the rotation axis as a Vec3 and the rotation angle in radians.
    
        Rotation( (int)axis, (float)angle_in_rad) -> Transform :
            Constructs a rotation Transform given the rotation axis as an integer (0,1,2) and the rotation angle in radians.
    
        Rotation( (Vec3)axis, (Vec3)origin, (float)angle_in_rad) -> Transform :
            Constructs a rotation around the given axis at origin by given angle in radians.
    
        Rotation( (Vec3)from_vector, (Vec3)to_vector) -> Transform :
            <p>Constructs a rotation which maps from a given direction vector to another.</p><p>The rotation axis is chosen to be perpendicular to the plane defined by the two vectors such that the rotational path is the shortest.</p>
    
    1 Reply Last reply
    0

  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Search