Re: [Interest] Rotating leaves

2018-04-02 Thread Bin Chen
Yes when you are using QQuarternion::fromAxisAndAngle() and crossProduct.

The angle around the axis is defined as counter clockwise when you look at the 
axis (the axis is pointing towards you).

dotProduct doesn’t mater the order of the vectors.

Cheers,

Bin


陳斌
Bin Chen

On 2 Apr 2018, at 2:42 pm, Igor Mironchik 
> wrote:


Hi,

On 01.04.2018 23:56, Bin Chen wrote:
Hi, Igor,

1. plainAngle is between 0~180, you want to know when you need to invert it?
I assumed m_transform is for leaf, then swap branch and leaf in 
QVector3D::crossProduct.
No need lessZero() function.

Big thanks. Great, swapping helped. So the rule is when you need to rotate 
something around some axis then first argument of QVector3D::crossProduct and 
QVector3D::dotProduct should be that vector that should be rotated?


2. In this case, be careful when branch and leaf are in the same line (same or 
opposite directions)  , crossProduct produces null vector3d.

Regards,

Bin



On 1 Apr 2018, at 8:56 pm, Igor Mironchik 
> wrote:

Hi,

Sure, I know this...

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 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.

So at this point I found the next solution:

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

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

So I actually asked not for the math as it is but for checking of my solution 
for correctness.

On 01.04.2018 12:48, Konstantin Shegunov wrote:
Hi Igor,
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:
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.
Basically you need to find the matrix that satisfies: b = A  * n (b is the 
branch direction, n is the leaf normal).
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.

[1]: 
https://en.wikipedia.org/wiki/Euler_angles

I hope that helps.
Konstantin.

___
Interest mailing list
Interest@qt-project.org
https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.qt-2Dproject.org_mailman_listinfo_interest=DwICAg=-0XTxx5JZxtPyuSXdvX8qQ=_JxpcpJpSMrVwuVMK05qMw=JDoIqjY-zYljVJcp8DYX1co3l1ElN2hO1_68-23VIAU=iR7_jc5oqZY41bU9FD_ergWeOPoFC0aUG4SyhsDkHIY=

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.   ­­

___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] Rotating leaves

2018-04-01 Thread Igor Mironchik

Hi,


On 01.04.2018 23:56, Bin Chen wrote:

Hi, Igor,

1. plainAngle is between 0~180, you want to know when you need to 
invert it?
    I assumed m_transform is for leaf, then swap branch and leaf in 
QVector3D::crossProduct.

    No need lessZero() function.


Big thanks. Great, swapping helped. So the rule is when you need to 
rotate something around some axis then first argument of 
QVector3D::crossProduct and QVector3D::dotProduct should be that vector 
that should be rotated?




2. In this case, be careful when branch and leaf are in the same line 
(same or opposite directions)  , crossProduct produces null vector3d.


Regards,

Bin


On 1 Apr 2018, at 8:56 pm, Igor Mironchik > wrote:


Hi,

Sure, I know this...

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 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.


So at this point I found the next solution:

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

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

So I actually asked not for the math as it is but for checking of my 
solution for correctness.


On 01.04.2018 12:48, Konstantin Shegunov wrote:

Hi Igor,
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:
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.
Basically you need to find the matrix that satisfies: b = A  * n (b 
is the branch direction, n is the leaf normal).
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.


[1]: https://en.wikipedia.org/wiki/Euler_angles 



I hope that helps.
Konstantin.


___
Interest mailing list
Interest@qt-project.org 
https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.qt-2Dproject.org_mailman_listinfo_interest=DwICAg=-0XTxx5JZxtPyuSXdvX8qQ=_JxpcpJpSMrVwuVMK05qMw=JDoIqjY-zYljVJcp8DYX1co3l1ElN2hO1_68-23VIAU=iR7_jc5oqZY41bU9FD_ergWeOPoFC0aUG4SyhsDkHIY=


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.   ­­ 


___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] Rotating leaves

2018-04-01 Thread Bin Chen
Should not need to invert plainAngle, a code segment for you:


QVector3D leaf(1, 1, 0);

leaf.normalize(); //need to be normalised otherwise the angle could be 
wrong.

qDebug()<> 
wrote:

Hi, Igor,

1. plainAngle is between 0~180, you want to know when you need to invert it?
I assumed m_transform is for leaf, then swap branch and leaf in 
QVector3D::crossProduct.
No need lessZero() function.

2. In this case, be careful when branch and leaf are in the same line (same or 
opposite directions)  , crossProduct produces null vector3d.

Regards,

Bin



On 1 Apr 2018, at 8:56 pm, Igor Mironchik 
> wrote:

Hi,

Sure, I know this...

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 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.

So at this point I found the next solution:

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

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

So I actually asked not for the math as it is but for checking of my solution 
for correctness.

On 01.04.2018 12:48, Konstantin Shegunov wrote:
Hi Igor,
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:
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.
Basically you need to find the matrix that satisfies: b = A  * n (b is the 
branch direction, n is the leaf normal).
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.

[1]: 
https://en.wikipedia.org/wiki/Euler_angles

I hope that helps.
Konstantin.

___
Interest mailing list
Interest@qt-project.org
https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.qt-2Dproject.org_mailman_listinfo_interest=DwICAg=-0XTxx5JZxtPyuSXdvX8qQ=_JxpcpJpSMrVwuVMK05qMw=JDoIqjY-zYljVJcp8DYX1co3l1ElN2hO1_68-23VIAU=iR7_jc5oqZY41bU9FD_ergWeOPoFC0aUG4SyhsDkHIY=

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.   ­­
___
Interest mailing list
Interest@qt-project.org

Re: [Interest] Rotating leaves

2018-04-01 Thread Bin Chen
Hi, Igor,

1. plainAngle is between 0~180, you want to know when you need to invert it?
I assumed m_transform is for leaf, then swap branch and leaf in 
QVector3D::crossProduct.
No need lessZero() function.

2. In this case, be careful when branch and leaf are in the same line (same or 
opposite directions)  , crossProduct produces null vector3d.

Regards,

Bin



On 1 Apr 2018, at 8:56 pm, Igor Mironchik 
> wrote:

Hi,

Sure, I know this...

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 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.

So at this point I found the next solution:

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

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

So I actually asked not for the math as it is but for checking of my solution 
for correctness.

On 01.04.2018 12:48, Konstantin Shegunov wrote:
Hi Igor,
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:
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.
Basically you need to find the matrix that satisfies: b = A  * n (b is the 
branch direction, n is the leaf normal).
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.

[1]: 
https://en.wikipedia.org/wiki/Euler_angles

I hope that helps.
Konstantin.

___
Interest mailing list
Interest@qt-project.org
https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.qt-2Dproject.org_mailman_listinfo_interest=DwICAg=-0XTxx5JZxtPyuSXdvX8qQ=_JxpcpJpSMrVwuVMK05qMw=JDoIqjY-zYljVJcp8DYX1co3l1ElN2hO1_68-23VIAU=iR7_jc5oqZY41bU9FD_ergWeOPoFC0aUG4SyhsDkHIY=

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.   
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] Rotating leaves

2018-04-01 Thread Igor Mironchik

Hi,

Sure, I know this...

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 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.


So at this point I found the next solution:

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

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

So I actually asked not for the math as it is but for checking of my 
solution for correctness.


On 01.04.2018 12:48, Konstantin Shegunov wrote:

Hi Igor,
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:
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.
Basically you need to find the matrix that satisfies: b = A  * n (b is 
the branch direction, n is the leaf normal).
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.


[1]: https://en.wikipedia.org/wiki/Euler_angles 



I hope that helps.
Konstantin.


___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] Rotating leaves

2018-04-01 Thread Konstantin Shegunov
Hi Igor,
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:
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.
Basically you need to find the matrix that satisfies: b = A  * n (b is the
branch direction, n is the leaf normal).
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.

[1]: https://en.wikipedia.org/wiki/Euler_angles

I hope that helps.
Konstantin.
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] Rotating leaves

2018-04-01 Thread Bin Chen
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)).

Cheers,

Bin



On 1 Apr 2018, at 2:45 am, Igor Mironchik 
> wrote:


Vectors are normalized.

On 31.03.2018 19:44, Igor Mironchik wrote:

Hi,

Sorry for the inaccuracy...

<20180331_194006.jpg>
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...

<20180331_104936.jpg>

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@qt-project.org
https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.qt-2Dproject.org_mailman_listinfo_interest=DwICAg=-0XTxx5JZxtPyuSXdvX8qQ=_JxpcpJpSMrVwuVMK05qMw=R-OlZxgObG558WAzim2UDFNCM-g-6GCfsB8tcwXf54s=YmBmeODv8jueT9scHHt5smTmtq-6765c2jqCxwK2ew8=

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.   
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest