Rotating a vector


#1

Hi,

In Processing I can do something like this: (rotating a line by 45 degrees,shrinking it by half):
PVector dir = PVector.sub(end, begin);
dir.rotate(PI / 6);
dir.mult(0.5);
PVector newEnd = PVector.add(end, dir);

how I can do a similar rotation in Cinder ?
Vec2 dir = end - begin;
//rotate(PI / 6,dir ) ?!
dir = dir * 0.5;
//etc…

Thanks.


#2

hey, cinder uses glm library for general math stuff.

so in order to rotate a vector you would:

    vec2 dir = vec2{ 100, 0 };

    auto rotatedDir = glm::rotate(dir, glm::radians(-45.f));

    auto c = getWindowCenter();
    gl::drawLine( c, c + dir );
    gl::drawLine( c, c + rotatedDir );
    console()  << rotatedDir << std::endl;