# Quaternion of a vector between two points

Having 2 points A and B in 3D space, im trying to workout the orientation of the vector (as a quaternion) between them, so that i can publish a PoseStamped message, which will essentially be the direction of one point to the other. I've been working on this for a bit and can't seem to get it to work properly.

i've provided a minimum working example of the code, I cant add the full python script as the formatting gets screwed up. I'm trying to get some more Karma so that I can add an image to illustrate the point and the code as an attachment.

Any help would be much appreciated.

The coordinate frame is "world". Could the coordinate system be the issue?

```
def publish_pose_from_vector_two(quat_pose, A, B):
a = np.cross(A, B);
x = a[0]
y = a[1]
z = a[2]
A_length = np.linalg.norm(A)
B_length = np.linalg.norm(B)
w = math.sqrt((A_length ** 2) * (B_length ** 2)) + np.dot(A, B);
norm = math.sqrt(x ** 2 + y ** 2 + z ** 2 + w ** 2)
if norm == 0:
norm = 1
x /= norm
y /= norm
z /= norm
w /= norm
pose = PoseStamped()
pose.header.frame_id = "world"
pose.header.stamp = rospy.Time.now()
pose.pose.position.x = A[0]
pose.pose.position.y = A[1]
pose.pose.position.z = A[2]
pose.pose.orientation.x = x
pose.pose.orientation.y = y
pose.pose.orientation.z = z
pose.pose.orientation.w = w
quat_pose.publish(pose)
return
```