# Getting the anchor point of a joint within world space

I'm extending the joint class from JME Physics 2, and in there I have a method that I want to always return the anchor point, but in world space, as getAnchor() just gives the anchor in relation to the first object in the joint. Here is my code:

```       Vector3f pivot = Vector3f.ZERO;       Vector3f pos = joint.getAnchor(null);       pos.mult(anchorLocale.getWorldTranslation());       pivot = anchorLocale.getWorldTranslation().subtract(pos);       return pivot; ```

anchorLocale is set to be the leftNode when two nodes are attached. The problem with this code is that the point it returns is close, but not quite right. It starts off below the leftNode, instead of horizontally next to it, where it should be. Then, as the leftNode moves (force is exerted on it), the point moves along, so when the leftNode has been moves around by about 90 degrees, the point is actually in the correct position! However, the point keeps moving upwards and across. I'm pretty sure this is because I have to do something with the the Vector3f I get from getAnchor(), but I'm not totally sure what. Does anyone have any ideas?

``` Vector3f anchorLocation = new Vector3f(); joint.getAnchor(anchorLocation); // Add the world location of the first node the joint is attached to anchorLocation.addLocal(joint.getNodes().get(0).getWorldTranslation(); ```

Does this do what you want?

Sorry, that doesn’t seem to work. I’ve drawn a diagram to show what I get:

http://s568.photobucket.com/albums/ss127/1mayfly23/?action=view&current=jointProb.jpg

The red cross is the point the code gives me, the green cross is the point I want (which is where I have set the anchor to be). In #1, the whole thing is horizontal, as there is a joint before the one shown that rotates the whole thing. As that (unshown) joint moves round, the point moves back and down till we come to #2, when the unshown first joint is at 90 degrees.

Any other ideas? I’ve been playing around with this for a while, and I can’t seem to get anywhere. And yet it seem so simple!

So it needs to be multiplied by the rotation of the body as well.

What follows is pseudo math and may not be entirely correct…

``` DynamicPhysicsNode node = joint.getNodes().get(0); Vector3f anchorLocation = new Vector3f(); joint.getAnchor(anchorLocation); // Rotate the anchor location to match the body's rotation anchorLocation = node.getWorldRotation().mult(anchorLocation); // Add the world location of the body the joint is attached to anchorLocation.addLocal(node.getWorldTranslation(); ```

Try this! (We're slowly getting there)

Yes! It works. Thank you so much!