Skip to content

Commit

Permalink
fix(shader-ast-stdlib): update incomplete cartesian3, refactor cartes…
Browse files Browse the repository at this point in the history
…ian2
  • Loading branch information
postspectacular committed Jul 8, 2019
1 parent d81656b commit 3299d59
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions packages/shader-ast-stdlib/src/math/cartesian.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ import {
mul,
ret,
sym,
vec2,
Vec2Sym,
Vec2Term,
vec3
} from "@thi.ng/shader-ast";
import { cossin } from "./sincos";

/**
* Converts 2D polar vector `v` to cartesian coordinates. See `polar2()`
* for reverse operation.
* Converts 2D polar vector `v`, i.e. `[r,θ]` (angle in radians) to
* cartesian coordinates. See `polar2()` for reverse operation.
*
* @param v
*/
export const cartesian2 = (v: Vec2Term) => mul(cossin($y(v)), vec2($x(v)));
export const cartesian2 = (v: Vec2Term) => mul(cossin($y(v)), $x(v));

/**
* Converts 3D polar vector `v` to cartesian coordinates. See `polar3()`
* for reverse operation.
* Converts 3D polar/spherical vector `v`, i.e. `[r,θ,ϕ]` (angles in
* radians) to cartesian coordinates. See `polar3()` for reverse
* operation.
*
* @param v
*/
Expand All @@ -36,6 +36,12 @@ export const cartesian3 = defn("vec3", "cartesian3", [["vec3"]], (v) => {
(r = sym($x(v))),
(t = sym(cossin($y(v)))),
(p = sym(cossin($z(v)))),
ret(vec3(mul(mul(r, $x(t)), $x(p))))
ret(
vec3(
mul(mul(r, $x(t)), $x(p)),
mul(mul(r, $x(t)), $y(p)),
mul(r, $y(t))
)
)
];
});

0 comments on commit 3299d59

Please sign in to comment.