# [Interest] Rotating leaves

Igor Mironchik igor.mironchik at gmail.com
Sat Mar 31 18:44:09 CEST 2018

```Hi,

Sorry for the inaccuracy...

On 31.03.2018 12:44, Igor Mironchik wrote:
>
> 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/69c878cc/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 20180331_194006.jpg
Type: image/jpeg
Size: 171104 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180331/69c878cc/attachment.jpg>
-------------- 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/69c878cc/attachment-0001.jpg>
```