Boost logo

Geometry :

Subject: [geometry] translation and rotation proposal
From: Adam Wulkiewicz (adam.wulkiewicz_at_[hidden])
Date: 2013-05-27 17:42:32


Hi,

I've been thinking about additional concepts like vector, matrix, etc.
and how they could be used in Boost.Geometry. In our context they
probably should be seen only as translation and rotation representations.

So I think about following use cases:

<code>

using namespace geometry;

model::point<double, 2, cs::cartesian> p2, p21, p22;
model::point<double, 3, cs::cartesian> p3, p31, p32;

// TRANSLATION

model::vector<double, 2> v2, v21, v22;
model::vector<double, 3> v3, v31, v32;

// void translation(const Point&, const Point&, Vector&)
translation(p21, p22, v2);
translation(p31, p32, v3);

// Vector return_translation(const Point&, const Point&)
v2 = return_translation(p21, p22);
v3 = return_translation(p31, p32);

// void translate(Geometry&, const Vector&)
translate(p2, v2);
translate(p3, v3);

// void translated(const Geometry&, const Vector&, Geometry&)
translated(p21, v2, p2);
translated(p31, v3, p3);

// Geometry return_translated(const Geometry&, const Vector&)
p2 = return_translated(p21, v2);
p3 = return_translated(p31, v3);

// translation(), return_translation() would work only for Points.
// translate(), translated(), would work for all geometries.

// ROTATION

model::rotation_matrix<double, 2> r2; // matrix 2x2
model::rotation_matrix<double, 3> r3; // matrix 3x3
model::rotation_quaternion<double> q3;
model::rotation_angle<double> a2;
model::rotation_axis_angle<double> aa3; // or <double, double>

/*We could generalize rotation_angle and implement rotation_euler_angles
however we must know the desired sequence of angles, axes direction etc.
We could pass them as a template parameters. Positive indicates "normal"
cartesian coordinate system with angles increasing CCW:*/

model::rotation_euler_angles<double, yaw, pitch, roll> ea3;
model::rotation_euler_angles<double, yaw, -pitch, -roll> ea32;
model::rotation_euler_angles<double, roll, pitch, roll> ea33;
// etc.

// void rotation(const PointOrVector&, const PointOrVector&, Rotation&)
rotation(p21, p22, r2);
rotation(v21, v22, r2);
rotation(p31, p32, r3);
rotation(v31, v32, r3);
rotation(p31, p32, q3);
rotation(v31, v32, q3);
// etc.

// Rotation return_rotation(const PointOrVector, const PointOrVector)
r2 = rotation(p21, p22);

// void rotate(Geometry&, const Rotation&)
rotate(p2, r2);

// void rotated(const Geometry&, const Rotation&, Geometry&)
rotated(p21, r2, p2);

// Geometry return_rotated(const Geometry&, const Rotation&)
p2 = return_rotated(p21, r2);

// rotation(), return_rotation() would work for Points and Vectors.
// rotate(), rotated(), return_rotated() would work for all geometries.

// CONVERSION:

// angle to matrix2x2
convert(a2, r2);
// axis-angle to quaternion
convert(aa3, q3);
// euler angles to matrix3x3
convert(ea3, r3);

// ACCESS

x = get<0>(v2);
y = get<1>(v2);
e00 = get<0,0>(r2); // row 0, col 0
e01 = get<0,1>(r2); // row 0, col 1
a = get<0>(a2); // rotation angle, must be 0!

// not sure about those below:

ax = get<axis_vector, 0>(aa3); // x coordinate of rotation axis
a = get<angle_value, 0>(aa3); // rotation angle, must be 0!

a = get<yaw>(ea3);
a = get<pitch>(ea3);
a = get<roll>(ea3);

c = get<0>(q3); // quaternion's component

// not sure which one should be 0, probably first imaginary because
// it corresponds to rotation axis x then:

c = get<3>(q3);

// would be real one, corresponding to the rotation half-angle.

// or just something like:
get<quaternion_w>(q3);
get<quaternion_x>(q3);
get<quaternion_y>(q3);
get<quaternion_z>(q3);

</code>

Above this, probably model::transformation could be implemented with
functions transformation(), transform(), transformed(), etc.

Thoughts?

Regards,
Adam


Geometry list run by mateusz at loskot.net