Menu

Rotation object

Help
2018-02-05
2018-03-05
  • shine world

    shine world - 2018-02-05

    I need to rotate an object, and all its children, around X axis (pitch action).
    To do that I use myobject.Pitch(degreeAngle).
    The object rotate correctly of degree angle.

    At this point I need to move the rotation Y axis offset to an arbitrary position and not to 0 default value.

    For eg:
    My object draw a square with lines (0/0/0, 10/0/0, 10/10/0, 10/0/0, 0/0/0).
    I would like pitch X using a Y different than 0, for example Y=50, so actually my only solution is to drive square how (0/-50/0, 10/-50/0, 10/-40/0, 0/-40/0, 0/-50/0) and then set object.position.y to 50 so it draw to scene at (0/0/0, 10/0/0, 10/10/0, 10/0/0, 0/0/0) and when I object.Pitch(30) I can se the object rotate in a large circle.

    There is a way to move the Y ration fulcrum without move entrire object coordinates ?

    Thank you very much

     

    Last edit: shine world 2018-02-06
  • Jerome.D (BeanzMaster)

    Hi Silverio i don't understand your question

    There is a way to move the Y ration fulcrum without move entrire object coordinate

    An object is define by many vertices (in you case 4) if you rotate object, all vertices are rotated. it's a normal behaviour. Remember apply rotation to parent rotate child around. Child object are not independant. so you must travel your parent object and apply rotation to child one by one

     
  • shine world

    shine world - 2018-02-07

    Before to insert images or video I will try to explain in another way.

    Any object, in my case a TGLLines, can be placed in the scene using its Position property.
    Any object can pitch, roll, and turn, but uses always x0:y0:z0 how fulcrum of rotation.
    I would like to pitch,roll and turn changing this point, for example in the x10:y12:z3 in a object with with100height100deep100.

    I'm using this to rotate a toolpath, stored in TGLLines, in a CNC program.
    In CNC system the rotation axis (A) is used to rotate the toolpath and can be placed anywhere in the axes table (not fixed to x0y0z0 of toolpath object).

    Thank you very much in advance.

     

    Last edit: shine world 2018-02-07
  • Jerome.D (BeanzMaster)

    Ok if i understand well rotation is with arbitary axis. This axis is alway place at 0,0,0 in world space ? or in the ModelSpace ?I see 2 solutions
    1st : Have auxiliarry axis based on the object position.
    In GLVectorGeometry unit you can find :

    { Calculates a vector perpendicular to N.
       N is assumed to be of unit length, subtract out any component parallel to N }
    function VectorPerpendicular(const V, N: TAffineVector): TAffineVector;
    // Reflects vector V against N (assumes N is normalized)
    function VectorReflect(const V, N: TAffineVector): TAffineVector;
    // Rotates Vector about Axis with Angle radians
    procedure RotateVector(var vector : TVector; const axis : TAffineVector; angle : Single); overload;
    // Rotates Vector about Axis with Angle radians
    procedure RotateVector(var vector : TVector; const axis : TVector; angle : Single); overload;
    
    // Rotate given vector around the Y axis (alpha is in rad)
    procedure RotateVectorAroundY(var v : TAffineVector; alpha : Single);
    // Returns given vector rotated around the X axis (alpha is in rad)
    function VectorRotateAroundX(const v : TAffineVector; alpha : Single) : TAffineVector; overload;
    // Returns given vector rotated around the Y axis (alpha is in rad)
    function VectorRotateAroundY(const v : TAffineVector; alpha : Single) : TAffineVector; overload;
    // Returns given vector rotated around the Y axis in vr (alpha is in rad)
    procedure VectorRotateAroundY(const v : TAffineVector; alpha : Single; var vr : TAffineVector); overload;
    // Returns given vector rotated around the Z axis (alpha is in rad)
    function VectorRotateAroundZ(const v : TAffineVector; alpha : Single) : TAffineVector; overload;
    

    in each GLScene'sObject you can find some usefull function and propertie like :

    { Calculates the object's barycenter in absolute coordinates.
           Default behaviour is to consider Barycenter=AbsolutePosition
           (whatever the number of children). 
           SubClasses where AbsolutePosition is not the barycenter should
           override this method as it is used for distance calculation, during
           rendering for instance, and may lead to visual inconsistencies. }
        function BarycenterAbsolutePosition: TVector; virtual;
        { Calculates the object's barycenter distance to a point. }
        function BarycenterSqrDistanceTo(const pt: TVector): Single;
        { Shall returns the object's axis aligned extensions.
           The dimensions are measured from object center and are expressed
           <i>with</i> scale accounted for, in the object's coordinates
           (not in absolute coordinates).
           Default value is half the object's Scale.  }
        function AxisAlignedDimensions: TVector; virtual;
        function AxisAlignedDimensionsUnscaled: TVector; virtual;
    
    ect....
    and
    

    procedure MoveObjectAround(anObject: TGLBaseSceneObject; pitchDelta, turnDelta: Single);
    So i think by using MoveObjectAround it will be possible. For example, if i understand you have a toolpath like a simple circle. This Toolpath is alway place at 0,0,0. your object is at 10,15,20.
    Solution :
    1. Make a copy of the toolpath
    2. Move, and rotate the temp toolpath relative to the axis of the object and rotation axis choosen
    3. Translate the object along the chosen axis of Circle Toolpath Radius
    4. Do a MoveObjectAround

    2nd : You need translate your object at 0,0,0 (like in this video i found on subject : https://www.youtube.com/watch?v=yELs34X2UXc )
    Make the transformation and replace the objet to initial pos

    I hope it will help a little

     
  • shine world

    shine world - 2018-02-09

    Thank you for suggestions,
    I will try early monday to evaluate this way and show you a resulting video :)

    THANK YOU very MUCH !!!

     
  • shine world

    shine world - 2018-02-19

    Thank you Jerome.D,
    now 4th axis (A) rotate correctly my model also when not placed on x/y/z = 0/0/0.

    A little demo of resulting rotation:
    https://youtu.be/a4f76WfcFWc

     
  • Jerome.D (BeanzMaster)

    Nice Job, at final how do you do ?

     
  • shine world

    shine world - 2018-02-19

    I've traslated all TGLLines vectors with the desired offset in X/Y/Z (model world), so the TGLLines object (scene world) can be moved in scene using same complementary offset in Position.x/y/z property and then I can rotate/turn/pitch :)

    Another sample of pitch on X:
    https://youtu.be/pa4vNTYA_q8

    GLScene is a very amazing tool !!!

     

    Last edit: shine world 2018-02-19
  • Jerome.D (BeanzMaster)

    Very very impressive. I have a question what's name of your tool for making video ?

     
  • shine world

    shine world - 2018-02-19

    Thank you,
    without the help of this site I think I would not have arrived where I am now.
    GLSCENE make simple to use OpenGL to everyone and reduce a lot the amount of required code.

    I'm using a free software called Open Broadcaster Software, very powerfull !!!

    https://obsproject.com/

     

    Last edit: shine world 2018-02-19
  • Jerome.D (BeanzMaster)

    Thanks for the link. Wait to see the next generation, you'll can use Lazarus for update your project :).

     
  • Jerome.D (BeanzMaster)

    Hi by finding some in informations, in GLGizmoEx I fell back on top

    procedure RotateAroundArbitraryAxis (const anObject: TGLBaseSceneObject; const Axis, Origin: TAffineVector; const angle: Single);
    var
      M, M1, M2, M3: TMatrix;
    begin
      M1: = CreateTranslationMatrix (VectorNegate (Origin));
      M2: = CreateRotationMatrix (Axis, Angle * PI / 180);
      M3: = CreateTranslationMatrix (Origin);
      M: = MatrixMultiply (M1, M2);
      M: = MatrixMultiply (M, M3);
      anObject.AbsoluteMatrix: = MatrixMultiply (anObject.AbsoluteMatrix, M);
    
      // Just a workaround to Update angles ...
      anObject.Roll (0);
      anObject.Pitch (0);
      anObject.Turn (0);
    end;
    

    It's a little late but hey, it's up to you

    A +

     

    Last edit: Jerome.D (BeanzMaster) 2018-02-24
  • shine world

    shine world - 2018-03-05

    Thanks Jerome,
    I was far from office for some days and I saw just now your last message.
    Wonderful piece of software which can simplify my code.

    :)

    Thank you so much !!!

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.