don't understand how rotation is done

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

don't understand how rotation is done

cantcode
in void RS_Ellipse::draw()
there is this line: auto&& ap1=getTangentDirection(vp).angle();
"RS_Vector RS_Ellipse::getTangentDirection(const RS_Vector& point) const" uses
   RS_Vector RS_Vector::rotate(const RS_Vector& angleVector)
can someone please tell me what this method does?
I don't understand how a vector can be rotated by a vector.
"Rotates this vector around 0/0 by the given vector"

/**
 * Rotates this vector around 0/0 by the given vector
 * if the vector is a unit, then, it's the same as rotating around
 * 0/0 by the angle of the vector
 */
RS_Vector RS_Vector::rotate(const RS_Vector& angleVector) {
//        RS_DEBUG->print("RS_Vector::rotate: rotating Vecotr: %g/%g", x,y);
//        RS_DEBUG->print("RS_Vector::rotate: rotating by Vecotr: %g/%g", angleVector.x,angleVector.y);
        double x0 = x * angleVector.x - y * angleVector.y;
        y = x * angleVector.y + y * angleVector.x;
        x = x0;
//        RS_DEBUG->print("RS_Vector::rotate: rotated x/y: %f/%f", x, y);
    return *this;
}


btw. what does getEllipseAngle() return (which angle and which units? deg,rad,grad,...)
thought it just returns majorP.angle() but it seems like there is more done.
and in  "auto&& ap1" is ap1 a reference of a reference???
Reply | Threaded
Open this post in threaded view
|

Re: don't understand how rotation is done

dxli
This post was updated on .
hi,

2D rotation around origin can be done equivalently by:

1, angle;
2, unit complex number (vector);
3, matrix;

3D rotation around origin is trickier, but can be rotated equivalently by:

1, axis-angle;
2, unit quaternion; (vector)
3, matrix;

to rotate a complex by a unit complex number:

z= x + i y;
angleVector = cos t + i sin t;

rotate z by angleVector using multiplication of complex number:

(x + i y) ( cos t + i sin t) = x cos t - y sin t + i ( x sin t + y cos t)

to rotate around any point P, simply translate P to origin, do rotation
around origin, translate back by -P, something like conjugate,

Translate(P)^-1 Rotate(angle) Translate(P)

thanks,

Dongxu


On Fri, Jun 7, 2013 at 8:31 AM, cantcode [via LibreCAD] <
ml-node+s1049103n5708244h32@n5.nabble.com> wrote:

> in void RS_Ellipse::draw()
> there is this line: auto&& ap1=getTangentDirection(vp).angle();
> "RS_Vector RS_Ellipse::getTangentDirection(const RS_Vector& point) const"
> uses
>    RS_Vector RS_Vector::rotate(const RS_Vector& angleVector)
> can someone please tell me what this method does?
> I don't understand how a vector can be rotated by a vector.
> "Rotates this vector around 0/0 by the given vector"
>
> /**
>  * Rotates this vector around 0/0 by the given vector
>  * if the vector is a unit, then, it's the same as rotating around
>  * 0/0 by the angle of the vector
>  */
> RS_Vector RS_Vector::rotate(const RS_Vector& angleVector) {
> //        RS_DEBUG->print("RS_Vector::rotate: rotating Vecotr: %g/%g",
> x,y);
> //        RS_DEBUG->print("RS_Vector::rotate: rotating by Vecotr: %g/%g",
> angleVector.x,angleVector.y);
>         double x0 = x * angleVector.x - y * angleVector.y;
>         y = x * angleVector.y + y * angleVector.x;
>         x = x0;
> //        RS_DEBUG->print("RS_Vector::rotate: rotated x/y: %f/%f", x, y);
>     return *this;
> }
>
>
> btw. what does getEllipseAngle() return (which angle and which units?
> deg,rad,grad,...)
> thought it just returns majorP.angle() but it seems like there is more
> done.
> and in  "auto&& ap1" is ap1 a reference of a reference???
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://forum.librecad.org/don-t-understand-how-rotation-is-done-tp5708244.html
>  To start a new topic under LibreCAD-dev, email
> ml-node+s1049103n4361976h24@n5.nabble.com
> To unsubscribe from LibreCAD-dev, click here<http://forum.librecad.org/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4361976&code=ZG9uZ3h1bGkyMDExQGdtYWlsLmNvbXw0MzYxOTc2fDE5NTI0NzgyMw==>
> .
> NAML<http://forum.librecad.org/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>



--
Dongxu Li, Ph.D.
www.librecad.org
Reply | Threaded
Open this post in threaded view
|

Re: don't understand how rotation is done

dxli
In reply to this post by cantcode
2D rotation around origin can be down equivalently by:

1, angle;
2, unit complex number (vector);
3, matrix;

3D rotation around origin is trickier, but can be rotated equivalently by:

1, axis-angle;
2, unit quaternion; (vector)
3, matrix;

to rotate a complex by a unit complex number:

z= x + i y;
angleVector = cos t + i sin t;

rotate z by angleVector using multiplication of complex number:

(x + i y) ( cos t + i sin t) = x cos t - y sin t + i ( x sin t + y cos t)

to rotate around any point P, simply translate P to origin, do rotation around origin, translate back by -P, something like conjugate,

Translate(P)^-1 Rotate(angle) Translate(P)

forgot to answer on ellipse angle:

ellipse angle is the angle used in parametric equation of ellipse, namely,

x = a cos t
y = b sin t

and the angle t is called ellipse angle, which is related to the actual angle of the point by:

tan(angle)=x/y = a/b tan(t)