ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

Okay, if I can summarise what you've said to make sure I understand it properly. The input to your process is a vector defined by it's start and end points. From this information you want to generate a set of vectors parallel to this input vector but spaced in a square grid formation if viewed along the direction of the input vector. Is this correct?

As you've found the main challenge here is finding the two direction vectors which are orthogonal to the input vector, when you have these you can easily create the sets of start and end points you want.

If I've understood the problem correctly then it's not fully defined, the rotation of the square grids around the input vector is not determined. So the solution I'm about to describe assumes any rotation is acceptable.

The tool we're going to use is the vector cross product, if you calculate this product for any non-parallel vectors the result will be a vector orthogonal to both input vectors with a length which is the scalar produce of the lengths of the two input vectors. This is available to you in the tf::Vector3::Cross method.

  1. First find the direction vector of your input by subtracting the start point from the end point.
  2. Normalise this direction vector (divide it by it's length) so that it's a unit vector.
  3. Choose an axis unit vector (x, y, or z) which is not parallel to the input vector, it doesn't matter which.
  4. Calculate the cross product of this axis vector with the direction vector, the result is the first orthogonal vector for your grid of points.
  5. Finally calculate the cross product of the first orthogonal vector with the direction vector, the result is the direction orthogonal vector for the grid.

You can now use the two orthogonal direction vectors along with the original start and end points to create the grid of vectors you need. Hope this helps you get this working.

Okay, if I can summarise what you've said to make sure I understand it properly. The input to your process is a vector defined by it's start and end points. From this information you want to generate a set of vectors parallel to this input vector but spaced in a square grid formation if viewed along the direction of the input vector. Is this correct?

As you've found the main challenge here is finding the two direction vectors which are orthogonal to the input vector, when you have these you can easily create the sets of start and end points you want.

If I've understood the problem correctly then it's not fully defined, the rotation of the square grids around the input vector is not determined. So the solution I'm about to describe assumes any rotation is acceptable.

The tool we're going to use is the vector cross product, if you calculate this product for any non-parallel vectors the result will be a vector orthogonal to both input vectors with a length which is the scalar produce of the lengths of the two input vectors. This is available to you in the tf::Vector3::Cross method.

  1. First find the direction vector of your input by subtracting the start point from the end point.
  2. Normalise this direction vector (divide it by it's length) so that it's a unit vector.
  3. Choose an axis unit vector (x, y, or z) which is not parallel to the input vector, it doesn't matter which.
  4. Calculate the cross product of this axis vector with the direction vector, the result is the first orthogonal vector for your grid of points.
  5. Finally calculate the cross product of the first orthogonal vector with the direction vector, the result is the direction second orthogonal vector for the grid.

You can now use the two orthogonal direction vectors along with the original start and end points to create the grid of vectors you need. Hope this helps you get this working.