## Global coordintes to local (not on Matlab 2012!)

on 29 Jan 2013

### Jan Simon (view profile)

Hey,

I have been searching for a way to be able to define spherical coordinates of the points in a XYZ matrix, based on a local coordinate system (new origin and xyz axes). All I have been running into is this new global2localcoord code in Matlab 2012 that the previous versions apparently don't have.

Could someone help me figure out how to do this?

## Products

No products are associated with this question.

### Jan Simon (view profile)

on 30 Jan 2013
Edited by Jan Simon

### Jan Simon (view profile)

on 30 Jan 2013

The general procedure is:

```localCoor                 = rand(3, 100);
translationOfLocalOrigin  = rand(3, 1);
rotationOfLocalCoorSystem = <DirectionCosinMatrix>;  % [3 x 3] matrix
```
```globalCoor = bsxfun(@minus, localCoor, translationOfLocalOrigin);
globalCoor = rotationOfLocalCoorSystem * globalCoor;
```

If you need more details, e.g. for the paraphrased "<DirectionCosinMatrix>", please post more details for your available input.

Doctor61

### Doctor61 (view profile)

on 30 Jan 2013

Thanks for your respond. What you proposed is actually very helpful, but I guess you got it backwards, I have a matrix with the global xyz coordinates, then I want to define a new set of coordinate system with a new origin and angles axes (which would be using the translationOfLocalOrigin and rotationOfLocalCoorSystem you defined above) and find my new xyz or eventually r,phi,theta with respect to that global coords.

#### Join the 15-year community celebration.

Play games and win prizes!

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi