This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Transform ParametrizedLine

Tags: None
(comma "," separated)
kamre
Registered Member
Posts
6
Karma
0

Transform ParametrizedLine

Fri Dec 09, 2016 11:45 am
Hello!

What is a concise and preferred way to apply transformation to instance of ParametrizedLine class?
Something like Hyperplane::transform.
kamre
Registered Member
Posts
6
Karma
0

Re: Transform ParametrizedLine

Thu Dec 15, 2016 12:54 pm
Ok, lets look at some code:
Code: Select all
#include <Eigen/Geometry>
#include <iostream>

int main()
{
  using namespace Eigen;
  // line
  ParametrizedLine<double, 3> line(Vector3d(0, 0, 0), Vector3d(1, 0, 0));
  // transformation
  Affine3d transform = Affine3d::Identity();
  transform.rotate(AngleAxisd(EIGEN_PI/2, Vector3d(0, 0, 1)));
  transform.translate(Vector3d(1, 2, 3));
  // apply transformation to line
  line.origin() = transform*line.origin();                // <== any way to simplify this?
  line.direction() = transform.linear()*line.direction(); //
  // print transformed line
  std::cout << "origin: " << line.origin().transpose()
            << "\ndirection: " << line.direction().transpose() << std::endl;
}

Is there any more concise way?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Transform ParametrizedLine

Thu Dec 15, 2016 8:49 pm
Nothing shorter for now, but feel free to propose a patch adding ParametrizedLine::transform methods similar to HyperPlane::transform with respective unit tests in test/geo_parametrizedline.cpp.
kamre
Registered Member
Posts
6
Karma
0

Re: Transform ParametrizedLine

Fri Dec 16, 2016 5:55 pm
Hello, here is the proposed patch.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Transform ParametrizedLine

Sun Dec 18, 2016 9:47 pm
Thank you for the patch. For the record, it is now applied in the default branch.
kamre
Registered Member
Posts
6
Karma
0

Re: Transform ParametrizedLine

Mon Dec 19, 2016 5:23 am
By the way I have a question about Hyperplane::transform implementation. Lets look at this code:
Code: Select all
#include <Eigen/Geometry>
#include <iostream>

using namespace Eigen;

int main()
{
  Vector3d a(1, 0, 0);
  Vector3d b(0, 1, 0);
  Vector3d c(0, 0, 1);
  Vector3d z(0, 0, 0);
  auto p = Hyperplane<double, 3>::Through(a, b, c);
  auto print = [&] {
    std::cout << "normal: " << p.normal().transpose()
              << ", norm: " << p.normal().norm()
              << ", dist: " << p.signedDistance(z) << std::endl;
  };
  print();
  auto t = Affine3d::Identity();
  t.scale(0.5);
  p.transform(t);
  print();
}

It prints the following to screen:
Code: Select all
normal: -0.57735 -0.57735 -0.57735, norm: 1, dist: 0.57735
normal: -1.1547 -1.1547 -1.1547, norm: 2, dist: 0.57735

Here we apply scaling transformation to Hyperplane and the resulting plane doesn't have unit normal vector. It leads to incorrect distance calculation from transformed plane to a point. Is this correct behavior?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Transform ParametrizedLine

Tue Dec 20, 2016 8:19 am
You are right, it is missing a normalized.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Transform ParametrizedLine

Tue Dec 20, 2016 8:37 am
Fixed in default, 3.3, and 3.2


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]