{"__v":0,"_id":"58f7a4c8cbd001190056cc26","category":{"version":"58f7a4c8cbd001190056cbf8","project":"578c4badbd223d2000cc1441","_id":"58f7a4c8cbd001190056cbfe","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-08-01T23:04:12.838Z","from_sync":false,"order":5,"slug":"api-reference","title":"API Reference"},"parentDoc":null,"project":"578c4badbd223d2000cc1441","user":"57bb7e47afc18c0e00529cf3","version":{"__v":1,"_id":"58f7a4c8cbd001190056cbf8","project":"578c4badbd223d2000cc1441","createdAt":"2017-04-19T17:56:24.172Z","releaseDate":"2017-04-19T17:56:24.172Z","categories":["58f7a4c8cbd001190056cbf9","58f7a4c8cbd001190056cbfa","58f7a4c8cbd001190056cbfb","58f7a4c8cbd001190056cbfc","58f7a4c8cbd001190056cbfd","58f7a4c8cbd001190056cbfe"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.1.0","version":"1.1.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-11-17T22:21:20.988Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":30,"body":"While it makes sense to position in cartesian coordinates for 2D space, 3D space lends itself more towards polar coordinates. As a result, we have provided the utlity module `polarToCartesian` which takes in polar coordinates and converts them into cartesian coordinates for your convenience.\n\n#####Description\nThe function has the following signature:\n```\npolarToCartesian(radius, theta, phi)\n\nArguments:\n(float) radius - given in world lengths\n(float) theta - given in degrees\n(float) phi - given in degrees\n```\nand converts the given polar coordinates into cartesian coordinates based on the default user location of (0, 0, 0) with forward vector of (0, 0, -1) and up vector of (0, 1, 0).\n\nFurthermore, polar coordinates of [1, 0, 0] give the forward vector [0, 0, -1] and increasing the theta sweeps the vector to the right whereas increasing the phi value sweeps the vector upwards. Refer to the image below.\n\n#####Example use:\nTo take advantage of this utility, simply import ViroUtils in top of your scene and then create an alias to the function like below:\n\n```\nimport {\n  ViroUtils,\n} from 'react-viro';\n\nlet polarToCartesian = ViroUtils.polarToCartesian;\n```\n\nThen wherever you use position, simply replace it with the function `polarToCartesian`:\n\n```\n<Viro3DObject source={require('./res/skeleton.obj')}\n                          position={polarToCartesian([1, 30, 30])}\n                          materials={[\"skeleton\"]} />\n```\n\n#####Advanced\n\nFor those of you who like to be mathematically accurate, the positive X axis it to the right of the user, the positive Y is \"up\" and the positive Z is straight \"behind\" the user's starting location. As a result, we've provided a variation of the `polarToCartesian` utility which we call `polarToCartesianActual` which take the same arguments as the original.\n\nThe main difference here is that `polarToCartesianActual` is mathematically accurate with the polar coordinates of [1, 0, 0] returning the cartesian coordinates of [1, 0, 0] (to the right of the user) vs [0, 0, -1] (directly in front of the user). As theta increases, the vector sweeps clockwise from the right of the user to directly behind the user and as phi increases, the vector sweeps from the same X-Z plane of the user up towards the [0, 1, 0] vector (directly above the user).\n\nTo use this utility, simply import the new function at the top of your scene:\n\n```\nimport { polarToCartesianActual } from 'polarToCartesian';\n```\n\nAnd use it anywhere you require cartesian coordinates.","excerpt":"","slug":"polartocartesian","type":"basic","title":"PolarToCartesian"}
While it makes sense to position in cartesian coordinates for 2D space, 3D space lends itself more towards polar coordinates. As a result, we have provided the utlity module `polarToCartesian` which takes in polar coordinates and converts them into cartesian coordinates for your convenience. #####Description The function has the following signature: ``` polarToCartesian(radius, theta, phi) Arguments: (float) radius - given in world lengths (float) theta - given in degrees (float) phi - given in degrees ``` and converts the given polar coordinates into cartesian coordinates based on the default user location of (0, 0, 0) with forward vector of (0, 0, -1) and up vector of (0, 1, 0). Furthermore, polar coordinates of [1, 0, 0] give the forward vector [0, 0, -1] and increasing the theta sweeps the vector to the right whereas increasing the phi value sweeps the vector upwards. Refer to the image below. #####Example use: To take advantage of this utility, simply import ViroUtils in top of your scene and then create an alias to the function like below: ``` import { ViroUtils, } from 'react-viro'; let polarToCartesian = ViroUtils.polarToCartesian; ``` Then wherever you use position, simply replace it with the function `polarToCartesian`: ``` <Viro3DObject source={require('./res/skeleton.obj')} position={polarToCartesian([1, 30, 30])} materials={["skeleton"]} /> ``` #####Advanced For those of you who like to be mathematically accurate, the positive X axis it to the right of the user, the positive Y is "up" and the positive Z is straight "behind" the user's starting location. As a result, we've provided a variation of the `polarToCartesian` utility which we call `polarToCartesianActual` which take the same arguments as the original. The main difference here is that `polarToCartesianActual` is mathematically accurate with the polar coordinates of [1, 0, 0] returning the cartesian coordinates of [1, 0, 0] (to the right of the user) vs [0, 0, -1] (directly in front of the user). As theta increases, the vector sweeps clockwise from the right of the user to directly behind the user and as phi increases, the vector sweeps from the same X-Z plane of the user up towards the [0, 1, 0] vector (directly above the user). To use this utility, simply import the new function at the top of your scene: ``` import { polarToCartesianActual } from 'polarToCartesian'; ``` And use it anywhere you require cartesian coordinates.