# [Interest] Rotating leaves

Igor Mironchik igor.mironchik at gmail.com
Sat Mar 31 11:44:02 CEST 2018

```Hi,

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:
>
> Hello,
>
> 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...
>
> Theory
>
> 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.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180331/7420483f/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 20180331_104936.jpg
Type: image/jpeg
Size: 125570 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180331/7420483f/attachment.jpg>
```

More information about the Interest mailing list