-3

I have a set of points in 3d. I form a line by joining these points. I have to obtain another line which is a shifted version of this line, such that the resultant shift is always to the right of the original line. What would be an approach to solve this problem? How to get the up vectors in the right direction each time?

Assume these points to lie on a sphere. Looking at the top view of the sphere i would want something like this

/\/\/\/\
/\/\/\/\

The first line is the original set of points and the second one the shifted set

Ok i am adding the code

std::vector<osg::Vec3> vertArray; // The array containig the 3d points
std::vector<osg::Vec3> shiftVec; // The array to store the shifted vectors

osg::Vec3 line1, line2, result, upVec, p1, p2, cross1, cross2;

result = vertArray[1] - vertArray[0];
result.normalise();
result = result X upVec; // i am not sure how to get this upvec for general set of   points
shiftVec.push_back(result);

for(unsigned int i = 1; i < vertArray.size() - 1; i++)
{
 line 1 = vertArray[i-1] - vertArray[i];
 line 2 = vertArray[i+1] - vertArray[i];
 line1.normalise();
 line2.normalise();
 upVec = line1 X line2;
 line 1 = line1 X upVec;
 p1 = vertArray[i-1] + line1;
 line 2 = line2 X upVec;
 p2 = vertArray[i+1] + line2;
 cross1 = upVec;
 cross2 = (p2-p1)X line2
 float factor = cross2.lenght()/cross1.length();
 result = p1+line1*factor;
 result = result - vertArray[i];
 shiftVec.push_back(result);
}

result = vertArray[i] - vertArray[i-1];
result.normalise();
result = result X upVec; // i am not sure how to get this upvec for general set of points
shiftVec.push_back(result);
sn710
  • 581
  • 5
  • 20

2 Answers2

0

If you three points are A, B and C. Then the three point define a plane. In general the points will not lie on a (straight) line. If they do then it becomes ambiguous what "right" means. If everything is on a sphere, then the three points will define a curve formed by the intersection of the sphere and the plane. You could form another line my finding the intersection of the sphere with a parallel plane.

I'm not quite sure what you want but I'm guessing you want the second line to lie in a parallel plane. You can find the normal to the plane by taking the cross product N=(A-B) X (C-B). It looks like you are doing something like this but you need the ^ operator. See https://www8.cs.umu.se/kurser/TDBD12/VT04/lab/osg/html/doc++/osg/Vec3.html#DOC.2.224.21

upVec = line1 ^ line2;
Salix alba
  • 7,536
  • 2
  • 32
  • 38
  • Yes i do use the "^" operator. I just showed "X" for clarity of a cross product. I dont have three points, i have many more than that. Even if they dont lie on the same plane, if the sense of the vector remains constant i.e. for given points a,b,c,d and e if i form vectors ab, bc, cd, de then "right" would make sense, isnt it? Imagine the top view of sphere. If you are looking along the line, then "right" or "left" would make sense isnt it? – sn710 Jun 03 '14 at 16:59
  • Are your points constrained to lie on a sphere? If so then you won't be able to have a parallel curve, it could lie in a parallel plane but be scalled. Maybe you need to use some sort of continuity. If N1 is a normal from the first triple and N2 calculated from the second triple. Take the dot product of N1 and N2 if its positive then its the right one otherwise take -N2. – Salix alba Jun 03 '14 at 21:16
0

look here: ECEF <-> ENU coordinates this might help

I rather use NEH local North,East,Height(or altitude) coordinate system

  • it is similar to compass + altimeter
  • if you are not looking in rotation axis direction (ECEF Z-axis) ... on poles
  • then North vector is just (0,0,6356754.7)-viewer_position (all in ECEF)
  • East,West vectors can be obtained as North x (0,0,6356754.7)
  • don`t remember if it is east or west (depends on your coordinate system and cross multiplicants order)
  • just check it visually and if wrong reverse the order or negate result
  • Up vector (Height or Altitude) is easy from this just Up=North x East or Up=North x West
  • again if wrong direction reverse order or negate result ...

[Notes]

  • 6356754.7 [m] is earths polar radius
  • if you viewing from poles (ECEF Z-axis)
  • then North vector and Up vector lies on the same axis (in opposite direction)
  • which means there is no east or west (singularity)
  • on south hemisphere is usually used South instead of North
  • in that case South = (0,0,-6356754.7)-viewer_position
Spektre
  • 49,595
  • 11
  • 110
  • 380