I am trying to draw a line using sensor coordinates and orientation angles. The one end of the line is sensor current location and i want to find the other end with same orientation as the current point. to achieve this i created a rotation matrix and multiplied it with the point that i want to rotate.
The line rotation is correct when it is in (0, 90, 0) location. But when the line is tilted and rotated in z axis, the topCurrentpoint seems to be revolving around the currentpoint at a certain height. How can i solve this ?
Here is the code i used.
double currentpoint[3];
currentpoint[0] = sphere_x;
currentpoint[1] = sphere_y;
currentpoint[2] = sphere_z;
double topCurrentpoint[3];
topCurrentpoint[0] = sphere_x;
topCurrentpoint[1] = sphere_y;
topCurrentpoint[2] = sphere_z + (110 * scale_z);
vtkSmartPointer<vtkTransform> needleTransform_init = vtkSmartPointer<vtkTransform>::New();
needleTransform_init->Translate(currentpoint[0], currentpoint[1], currentpoint[2]);
needleTransform_init->RotateX(90);
needleTransform_init->Translate(-currentpoint[0], -currentpoint[1], -currentpoint[2]);
needleTransform_init->TransformPoint(topCurrentpoint, topCurrentpoint);
qDebug()<<" angles before rea"<<roll<<elevation<<azimuth;
vtkSmartPointer<vtkTransform> needleTransform = vtkSmartPointer<vtkTransform>::New();
needleTransform->Translate(currentpoint[0], currentpoint[1], currentpoint[2]);
needleTransform->RotateZ(180+roll); // (180+roll)
needleTransform->RotateX(elevation); // (elevation)
needleTransform->RotateY(180-azimuth); // (180-azimuth)
needleTransform->Translate(-currentpoint[0], -currentpoint[1], -currentpoint[2]);
needleTransform->TransformPoint(topCurrentpoint, topCurrentpoint);
vtkNew<vtkLineSource> lineSource;
lineSource->SetPoint1(currentpoint);
lineSource->SetPoint2(topCurrentpoint);
It was the 180-roll and 180-azimuth that made the errors.
needleTransform->RotateZ(azimuth);
needleTransform->RotateX(elevation);
needleTransform->RotateY(roll);
This is the answer.