Place object in scene with Quaterion and distance

I have a vector that I set at an origin O = new Vector3f( 0.0f, 0.0f, 0.0f), I rotate the vector to point in a direction with a quaterion
quat = new Quaternion(x, y, z, w);
I have a distance from that vector O, 123CM away in that direction, how do I place a geometry( box,sphere or what ever) in that direction that far away? I don’t know the sequence of commands to place something in a direction some distance away from a point/origin.

K recommend reading Keynote

1 Like

that helps with the information presented but does not really show how to, from a objects origin, and direction its pointing, go out in that direction some distance and create a new object.
I can using polar coordinates FINGER out the location and convert to Cartesian coordinates, but what I suspect is there is an easier way? Maybe?

If O is a Vector3f then there is no setLocalRotation(). So the above is nonsense.

…but even it if weren’t, no matter how much you rotate 0,0,0 it will always be 0,0,0.

Never mind that, though:

Well, your direction needed to start somewhere. For example:
Vector3f v = new Vector3f(distance, 0, 0);
Quaternion quat = someRotation;
Vector3f rotatedV = quat.mult(v);

…but maybe v should have been new Vector3f(0, distance, 0) or Vector3f(0, 0, distance).

You’ve jumped off and are drowning in a very deep end of the ocean. You aren’t even to the knowledge level where you can ask questions. So we’re going to keep posting articles like:

Not trying to be mean… just trying to get you up to the level where the questions you ask start making sense.

pspee I can’t argue with that. My ignorance is not bliss :frowning:

So I can place items some distance in a direction when I convert from Cartesian to polar using the Quaterion to give me the angle of rotation on the x/y then use the distance as the radius. What I am asking is there some better way to do this, that I currently am not aware?
( a JME3 way to do this)

quat = new Quaternion(x, y, z, w);// IMU rotation
pivot.setLocalRotation(quat);// node that represents device with IMU
float[] angles = new float[3];// place to hold the angles of rotation
quat.toAngles(angles);// Get angels of direction to use as polar coords
SphericalCoordinates sc = new SphericalCoordinates(dis / 100.0f,angles[0], angles[1]);// dis is distance in cm from this node, this is an object to do the Polar to Cartesian
Vector3f location = sc.getCartesian().toVector3f();// convert polar to cartesian
Geometry leftQuad = new Geometry(“sphere”, smallSphere);

I don’t know what “SphericalCoordinates” is doing.

“Rotate this distance around the origin” doesn’t make any sense on its own. Distance down what axis? Is the first important question. It’s the missing piece.

SphericalCoordinates take radius, theta,phi and converts it to Cartesian. As you know JME3 uses Cartesian coords. So from the local origin of the node 0,0,0 I point in the direction with theta and phi ( the x angle and the y angle from the quaterion ) and set the radius at the distance. Then convert back to Cartesian coordinates to set the location of where I will place the object.
So one object points in a direction some distance from that object I place another object.
Is there a more effective or efficient way to do this? Whats key is the object I want to place other objects around has a location and a direction it is pointing, I place new objects relative to the direction it is pointing i.e. north , south, up, down , or which ever direction it is currently pointing.
I know what I want, and I am able to do it , but is this the best way to do it?

Ok, I’m going to ask my question another way: If you have spherical coordinates of radius=10, theta=0, and phi=0… what direction would you expect it to point. Along the X axis? Along the Y axis? Along the Z axis?

It matters.

public static void main(String[] args) {
double radius = 10.0;
double theta=0;
double phi=0;
SphericalCoordinates sc = new SphericalCoordinates(radius,theta,phi);
Vector3f location = sc.getCartesian().toVector3f();
System.out.println( location);


output is
(0.0, 0.0, 10.0)

Easiest way:
Node pivot = new Node(“pivot”);
Geometry myGeom = …
myGeom.setLocalTranslation(0, 0, radius);
pivot.setLocalRotation(new Quaternion().fromAngles(theta, phi, 0));

…depending on what theta and phi really mean. Might need to swap them. If theta is like latitude and phi is like longitude then it should work as I wrote it.


thank you pspeed I can’t wait to try it out

1 Like