__rmul__ Bug



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 08/10/2012 at 08:23, xxxxxxxx wrote:

    Hy there,

    as you can see in the "attached" file, the python __rmul__ is not always correct. Ie. I am suspecting it is the __rmul__, as I can zero-out the offset manually and not use the __rmul__ and then it works fine.

    I really don't know, what could go wrong in this example and how this is related to the spline in use. When you start it, you have a camera which is not aligned to the spline. Looking into the XPresso, you can see, that the __rmul__ seems to return a wrong result. The same code as COFFEE works fine.

    If you switch the spline "This Spline Breaks Python _rmul_" in the XPresso by the "Spline ok", it also works fine. If you use the COFFEE code (re-wire XPresso), it also always works fine.

    So, here something somehow goes wrong.

    Cheers,
    maxx

    Python_rmul_spline_Bug.c4d

    PS: Its really unfortunate, that we can't attach anything here. The linked example won't be there forever, so this post is soon useless. I really can't explain how to get to this "setup", so attaching a "working wrong" example seems the only way here.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 09/10/2012 at 07:43, xxxxxxxx wrote:

    Hi,

    You don't get the same result because COFFEE's GetMulV() doesn't include the offset in the multiplication but Python's __rmul__ does (equivalent to GetMulP()).
    With Python you can call MulV() if you don't want the offset to be taken into account.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 09/10/2012 at 10:16, xxxxxxxx wrote:

    Originally posted by xxxxxxxx

    Hi,

    You don't get the same result because COFFEE's GetMulV() doesn't include the offset in the multiplication but Python's __rmul__ does (equivalent to GetMulP()).
    With Python you can call MulV() if you don't want the offset to be taken into account.

    Hy Yannick,

    yes, it is clear that GetMulV() does not include the offset (as I also pointed out in the second sentence in my first post and in the python code itself). The Python __rmul__ is defined as:

    Matrix.\__rmul\_\_( self , other )

    If both objects are of type Matrix, it multiplies the left hand matrix by the right hand matrix. Is the left object of type Matrix and the right one of Vector so multiply the vector by the matrix, this includes any translation in the matrix. In the last case, the left object can be of type Vector and the right one of type Matrix so it multiplies the vector by the matrix, this does not include any translation.
    So, in the case of the left object being a Vector and the right one being a Matrix , we should get the same result as with COFFEE GetMulV(). This is not the case in the example.

    Edit: Ok, it seems that the offset is the only problem here. This explains all the behaviors, I see now. But still either the docs are wrong, or the way the function works.

    Cheers,
    André



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 09/10/2012 at 15:56, xxxxxxxx wrote:

    Note that the tangent is not a rotation vector.
    It's a position vector, one unit from the point.
    Thus any of your matrix tests might show errors.
    Point being at 0,0,0 then the point and tangent pos
    will give you the rotation.
    (tangent - vector(0,0,0,)) : that is the same as
    the tangent itself in a VectorToHPB() function.

    Since you are getting the global position from your
    spline node, You would only need a matrix output in
    the py node feeding your Cameras Global Matrix.

      
    import c4d   
    from c4d import utils as u   
      
    def main() :   
         global Outm   
         rot = u.VectorToHPB(tangent)   
         m   = u.HPBToMatrix(rot)   
         m.off = oPos   
         Outm = m   
    

    Cheers
    Lennart



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 09/10/2012 at 17:10, xxxxxxxx wrote:

    Hy Lennart,

    Originally posted by xxxxxxxx

    Note that the tangent is not a rotation vector.
    It's a position vector, one unit from the point.
    Thus any of your matrix tests might show errors.
    Point being at 0,0,0 then the point and tangent pos
    will give you the rotation.
    (tangent - vector(0,0,0,)) : that is the same as
    the tangent itself in a VectorToHPB() function.

    I try to follow your explanation here, but I think I don't see your point. Especially:

    Originally posted by xxxxxxxx

    Thus any of your matrix tests might show errors.

    Can you elaborate on this?

    The 'tangent' variable is the direction in which the tangent points, in local coordinates of the spline-object. So in order to align an object absolute (say to the objects Z-Axis), one would need to convert the tangent direction to global coordinates.

      
    import c4d   
    from c4d import utils as u   
      
    def main() :   
       global Outm   
       rot = u.VectorToHPB(tangent)   
       m   = u.HPBToMatrix(rot)   
       m.off = oPos   
       Outm = m   
    

    In this example here, the camera would align to the tangent 'as seen in local spline coordinates', thus would be wrong, as soon as you rotate the axis of the spline. Or did I understand you wrong?

    Originally posted by xxxxxxxx

    Since you are getting the global position from your
    spline node, You would only need a matrix output in
    the py node feeding your Cameras Global Matrix.

    Yes, thanks for the hint. But this is no real-life example :) I was only trying to reproduce this __rmul__ problem, the application (ie. align the camera) is only for demonstration purpose.

    Cheers,
    André



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 09/10/2012 at 17:31, xxxxxxxx wrote:

    You wrote:
    "The 'tangent' variable is the direction in which the tangent points, in local coordinates of the spline-object"

    No, that is what I tried to point out. It is not a (direct) direction.
    It's a position. Using that position will give you the direction using i.e.VectorToHPB().
    The example I made works as it it rotates the Camera along the spline (just as AlignToSpline Tag
    set to tangential) no matter how the spline object is rotated or the camera is placed under a parent.

    Cheers
    Lennart



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 09/10/2012 at 17:58, xxxxxxxx wrote:

    Just that we mean the same, is this how you suggest?

    Align_Test

    Originally posted by xxxxxxxx

    You wrote:
    "The 'tangent' variable is the direction in which the tangent points, in local coordinates of the spline-object"

    No, that is what I tried to point out. It is not a (direct) direction.

    Ok, I will have a look at this.

    Thank you,
    André



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 10/10/2012 at 02:17, xxxxxxxx wrote:

    Originally posted by xxxxxxxx

    Edit: Ok, it seems that the offset is the only problem here. This explains all the behaviors, I see now. But still either the docs are wrong, or the way the function works.

    Yes you're right, the description of __rmul__ is wrong in the case of a left object Vector and a right object Matrix: it includes any translation in the matrix. I'll fix the description.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 10/10/2012 at 04:22, xxxxxxxx wrote:

    Originally posted by xxxxxxxx

    Originally posted by xxxxxxxx

    Edit: Ok, it seems that the offset is the only problem here. This explains all the behaviors, I see now. But still either the docs are wrong, or the way the function works.

    Yes you're right, the description of __rmul__ is wrong in the case of a left object Vector and a right object Matrix: it includes any translation in the matrix. I'll fix the description.

    Ok, thank you!

    Cheers,
    André


Log in to reply