<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
Hi, Igor, 
<div class=""><br class="">
</div>
<div class="">1. plainAngle is between 0~180, you want to know when you need to invert it? </div>
<div class="">    I assumed m_transform is for leaf, then swap branch and leaf in QVector3D::crossProduct.</div>
<div class="">    No need lessZero() function.</div>
<div class=""><br class="">
</div>
<div class="">2. In this case, be careful when branch and leaf are in the same line (same or opposite directions)  , crossProduct produces null vector3d. </div>
<div class=""><br class="">
</div>
<div class="">Regards,</div>
<div class=""><br class="">
</div>
<div class="">Bin</div>
<div class=""><br class="">
</div>
<div class="">    </div>
<div class="">
<div><br class="">
<blockquote type="cite" class="">
<div class="">On 1 Apr 2018, at 8:56 pm, Igor Mironchik <<a href="mailto:igor.mironchik@gmail.com" class="">igor.mironchik@gmail.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div bgcolor="#FFFFFF" text="#000000" class="">Hi,<br class="">
<br class="">
Sure, I know this...<br class="">
<br class="">
const QVector3D branch(...);<br class="">
const QVector3D leaf( 0.0f, 1.0f, 0.0f );<br class="">
const QVector3D axis = QVector3D::crossProduct( branch, leaf );<br class="">
const float cosPlainAngle = QVector3D::dotProduct( branch, leaf );<br class="">
const float plainAngle = qRadiansToDegrees( std::acos( cosPlainAngle ) );<br class="">
const QQuaternion quat = Qt3DCore::QTransform::fromAxisAndAngle( axis, plainAngle );<br class="">
m_transform->setRotation( quat );<br class="">
<br class="">
But in a view of Qt 3D this is only a half of the solution. In a half of cases this works, but in another cases I need -plainAngle.<br class="">
<br class="">
So at this point I found the next solution:<br class="">
<br class="">
static inline bool lessZero( const QVector3D & v )<br class="">
{<br class="">
    return ( v.x() < 0.0f || v.y() < 0.0f || v.z() < 0.0f );<br class="">
}<br class="">
<br class="">
if( lessZero( branch ) )<br class="">
        plainAngle = -plainAngle;<br class="">
<br class="">
So I actually asked not for the math as it is but for checking of my solution for correctness.<br class="">
<br class="">
<div class="moz-cite-prefix">On 01.04.2018 12:48, Konstantin Shegunov wrote:<br class="">
</div>
<blockquote type="cite" cite="mid:CAAz9bHuzYXGVt4cKkRY2Mj3emHoDLVuUfx2PaQhY8PiYhQ7Nug@mail.gmail.com" class="">
<div dir="ltr" class="">Hi Igor,<br class="">
What Bin Chen wrote is probably the most painless way of achieving what you want. If you are however interested in the math, here goes my stab:<br class="">
If I understand you correctly, you know the leaf normal, and the branch direction vector, then you're searching for the matrix that transforms the former to the latter.<br class="">
Basically you need to find the matrix that satisfies: b = A  * n (b is the branch direction, n is the leaf normal).<br class="">
This equation however is underdetemined, meaning you can have several rotations done in sequence that give you the same result, so you'd need to do some "trickery". One of the usual ways to solve such a problem is to use Euler angles[1], where the idea is to
 make elemental rotations with respect to the principle axes of the (global) coordinate systems. To that end you'd need to calculate the projections (i.e. dot products) of b and n to the principal axes and extract the angles of rotation from there, then construct
 each rotation matrix around a principal axis of the coordinate system and finally multiply them to obtain the final transformation.<br class="">
<br class="">
[1]: <a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__en.wikipedia.org_wiki_Euler-5Fangles&d=DwMDaQ&c=-0XTxx5JZxtPyuSXdvX8qQ&r=_JxpcpJpSMrVwuVMK05qMw&m=JDoIqjY-zYljVJcp8DYX1co3l1ElN2hO1_68-23VIAU&s=tezn68iaGXO6oGne6GHcWtS-CoDkU-Uj0fztStttyik&e=" target="_blank" moz-do-not-send="true" class="">https://en.wikipedia.org/<wbr class="">wiki/Euler_angles</a><br class="">
<br class="">
I hope that helps.<br class="">
Konstantin.</div>
</blockquote>
<br class="">
</div>
_______________________________________________<br class="">
Interest mailing list<br class="">
<a href="mailto:Interest@qt-project.org" class="">Interest@qt-project.org</a><br class="">
https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.qt-2Dproject.org_mailman_listinfo_interest&d=DwICAg&c=-0XTxx5JZxtPyuSXdvX8qQ&r=_JxpcpJpSMrVwuVMK05qMw&m=JDoIqjY-zYljVJcp8DYX1co3l1ElN2hO1_68-23VIAU&s=iR7_jc5oqZY41bU9FD_ergWeOPoFC0aUG4SyhsDkHIY&e=<br class="">
</div>
</blockquote>
</div>
<br class="">
</div>
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.   ­­ 
</body>
</html>