## torusSDF (`lygia`/`sdf`/`torusSDF`)

generate the SDF of a torus

Use:

``````<float> torusSDF( in <vec3> pos, in <vec2> h [, in <float> ra, in <float> rb] )
``````

Check it on Github

``````
#ifndef FNC_TORUSSDF
#define FNC_TORUSSDF
float torusSDF( vec3 p, vec2 t ) { return length( vec2(length(p.xz)-t.x,p.y) )-t.y; }

float torusSDF(in vec3 p, in vec2 sc, in float ra, in float rb) {
p.x = abs(p.x);
float k = (sc.y*p.x>sc.x*p.y) ? dot(p.xy,sc) : length(p.xy);
return sqrt( dot(p,p) + ra*ra - 2.0*ra*k ) - rb;
}
#endif
``````

Use:

``````<float> torusSDF( in <float3> pos, in <float2> h [, in <float> ra, in <float> rb] )
``````

Check it on Github

``````
#ifndef FNC_TORUSSDF
#define FNC_TORUSSDF
float torusSDF( float3 p, float2 t ) { return length( float2(length(p.xz)-t.x,p.y) )-t.y; }

float torusSDF(in float3 p, in float2 sc, in float ra, in float rb) {
p.x = abs(p.x);
float k = (sc.y*p.x>sc.x*p.y) ? dot(p.xy,sc) : length(p.xy);
return sqrt( dot(p,p) + ra*ra - 2.0*ra*k ) - rb;
}
#endif
``````

Check it on Github

``````
fn torusSDF(p: vec3f, t: vec2f ) -> f32 {
return length( vec2f(length(p.xz) - t.x, p.y) ) - t.y;
}
``````