We are about to switch to a new forum software. Until then we have removed the registration on this forum.

- All Categories 25.7K
- Announcements & Guidelines 13
- Common Questions 30
- Using Processing 22.1K
- Programming Questions 12.2K
- Questions about Code 6.4K
- How To... 4.2K
- Hello Processing 72
- GLSL / Shaders 292
- Library Questions 4K
- Hardware, Integration & Other Languages 2.7K
- Kinect 668
- Arduino 1K
- Raspberry PI 188
- Questions about Modes 2K
- Android Mode 1.3K
- JavaScript Mode 413
- Python Mode 205
- Questions about Tools 100
- Espanol 5
- Developing Processing 548
- Create & Announce Libraries 211
- Create & Announce Modes 19
- Create & Announce Tools 29
- Summer of Code 2018 93
- Rails Girls Summer of Code 2017 3
- Summer of Code 2017 49
- Summer of Code 2016 4
- Summer of Code 2015 40
- Summer of Code 2014 22
- p5.js 1.6K
- p5.js Programming Questions 947
- p5.js Library Questions 315
- p5.js Development Questions 31
- General 1.4K
- Events & Opportunities 289
- General Discussion 365

Hi there, please could somebody show me how to get the same x,y,z result but having the origin at c? I appreciate this is mainly a maths problem and sorry if has been answered before but I have been searching/trying to work this out for days now. Thank you

```
PVector a;
PVector b;
PVector c;
void setup(){
size(500,500,P3D);
a = new PVector(300, 154, 407);
b = new PVector(0, 0, 0);
c = new PVector(55, 233, 82);
}
void draw(){
background(255);
float rad = PVector.dist(a, b);
float theta = atan2(a.z, a.x);
float phi = acos(a.y/rad);
float x = rad * sin(phi) * cos(theta);
float y = rad * cos(phi);
float z = rad * sin(phi) * sin(theta);
println(x,y,z);
}
```

Tagged:

## Answers

The solution is to subtract the origin coordinates from the vector

`a`

beforecalculating the spherical coordinates.When transforming back to cartesian coordinates you need to add the origin coordinates

aftercalculating the cartesian coordinates.If you are going to be doing a lot of these calculations then I suggest you creates functions to do it for you.

Out of curiosity I have created two functions to convert

cartesian --> spherical coordinates, and

spherical --> cartesian coordinates

If you want, I will post them here provided you assure me that it is not part of some academic assessment.

Thanks very much quark,

I assure you my academic years are well behind me and use processing purely as a hobby.

OK well here is the code. Hopefully the comments explain what is happening but if you have any questions please ask.

Thanks again quark :)