# Math, Rotation, inaccurate rotation

Hello everybody,

My goal is to create a “line” at the center of a sphere, rotate it to the center of another sphere, sometimes it works sometimes not.

The problem is best described with a picture:

The positioning should be fine, i guess i’am missing something important in terms of rotation, i guess.

[java]
Vector3f origin = a.getSpatial().getWorldBound().getCenter();
Vector3f destination = b.getSpatial().getWorldBound().getCenter();
float distance = origin.distance(destination)/2;
Box box = new Box(0.01f, distance, 0.01f);

Vector3f angle = destination.subtract(origin);
geom.rotateUpTo(destination.normalize());
[/java]

Does someone have a good hint for me?

i might point out that there is a Line mesha lso,

anyway, why do you need to use the worldbounds for a sphere?
Isn’t it already centerd? eg couldn’t you simply use getTranslation?

Also are those balls attached in a tree like structurein the scenegraph, or not?
Can they move or are the (mostly) static?

It’s interesting that you calculate a local relative vector ‘angle’ but then you use the completely random, non-local ‘destination’ to set your up vector.

@Empire

1. Line mesh, true.
2. I didn’t thought about that, because i used boxes instead of spheres at first^^
3. they are children of rootnode for now, and will not move like crazy but “vibrate”

@pspeed

i had to move the connections ( line boxes ) in the direction of the destination sphere with an offset because the boxes get stretched from 0. in both directions and i want both ends to be in the center of sphere

@EMPJ said: @Empire
1. Line mesh, true.
2. I didn’t thought about that, because i used boxes instead of spheres at first^^
3. they are children of rootnode for now, and will not move like crazy but “vibrate”

@pspeed

i had to move the connections ( line boxes ) in the direction of the destination sphere with an offset because the boxes get stretched from 0. in both directions and i want both ends to be in the center of sphere

I think you are missing what I’m saying.

This:
geom.rotateUpTo(destination.normalize());

Is most certainly wrong. You probably want:
geom.rotateUpTo(angle.normalize());

thank you pspeed … now i feel stupid lol^^