[Interest] Rotating leaves

Bin Chen bchen at topcon.com
Sun Apr 1 10:33:12 CEST 2018

Hi, Igor,

To get a rotation quaternion from a vector to the other, in your case, the leave normal(0,1,0) and the branch direction (-1, 0, 0), I would use
QQuaterion::rotationTo(QVector3D(0, 1, 0), QVector3D(-1, 0, 0)).



On 1 Apr 2018, at 2:45 am, Igor Mironchik <igor.mironchik at gmail.com<mailto:igor.mironchik at gmail.com>> wrote:

Vectors are normalized.

On 31.03.2018 19:44, Igor Mironchik wrote:


Sorry for the inaccuracy...

On 31.03.2018 12:44, Igor Mironchik wrote:


Not sure how, but I did:

static inline bool lessZero( const QVector3D & v )
    return ( v.x() < 0.0f || v.y() < 0.0f || v.z() < 0.0f );

... Sorry for skipped code, just hope that I'm clear.

if( lessZero( branch ) )
        plainAngle = -plainAngle;

And seems that with inverting angle of rotation of leaf's plain to branch on less zero components in branch vector always set leaf perpendicularly to branch. Could anybody explain the math here, please?

Not sure in this solution but it works :)

On 31.03.2018 11:00, Igor Mironchik wrote:


The task is simple on one side and complicated on another. I need to rotate a leaf around a branch to make leaf perpendicular to branch.

In theory all is simple...


Great. In the code I have...

const QVector3D branch(...);
const QVector3D leaf( 0.0f, 1.0f, 0.0f );
const QVector3D axis = QVector3D::crossProduct( branch, leaf );
const float cosPlainAngle = QVector3D::dotProduct( branch, leaf );
const float plainAngle = qRadiansToDegrees( std::acos( cosPlainAngle ) );
const QQuaternion quat = Qt3DCore::QTransform::fromAxisAndAngle( axis, plainAngle );
m_transform->setRotation( quat );

But it works correctly not in all situations. In some cases I need to increment plainAngle by 90.0 degrees.

So my question is what should I care in the code to handle all situations correctly?

Thank you.

Interest mailing list
Interest at qt-project.org<mailto:Interest at qt-project.org>

Confidentiality Notice: This message (including attachments) is a private communication solely for use of the intended recipient(s). If you are not the intended recipient(s) or believe you received this message in error, notify the sender immediately and then delete this message. Any other use, retention, dissemination or copying is prohibited and may be a violation of law, including the Electronic Communication Privacy Act of 1986.   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180401/a55d0d2f/attachment.html>

More information about the Interest mailing list