  ## octogonPrismSDF (`lygia`/`sdf`/`octogonPrismSDF`)

generate the SDF of a octogon prism

Use:

``````<float> octogonPrismSDF( in <vec3> p, in <float> r, <float> h )
``````

Check it on Github

``````
#ifndef FNC_OCTOGONPRISMSDF
#define FNC_OCTOGONPRISMSDF

float octogonPrismSDF( in vec3 p, in float r, float h ) {
vec3 k = vec3( -0.9238795325,   // sqrt(2+sqrt(2))/2
0.3826834323,   // sqrt(2-sqrt(2))/2
0.4142135623 ); // sqrt(2)-1
// reflections
p = abs(p);
p.xy -= 2.0*min(dot(vec2( k.x,k.y),p.xy),0.0)*vec2( k.x,k.y);
p.xy -= 2.0*min(dot(vec2(-k.x,k.y),p.xy),0.0)*vec2(-k.x,k.y);
// polygon side
p.xy -= vec2(clamp(p.x, -k.z*r, k.z*r), r);
vec2 d = vec2( length(p.xy)*sign(p.y), p.z-h );
return min(max(d.x,d.y),0.0) + length(max(d,0.0));
}

#endif
``````

Use:

``````<float> octogonPrismSDF( in <float3> p, in <float> r, <float> h )
``````

Check it on Github

``````
#ifndef FNC_OCTOGONPRISMSDF
#define FNC_OCTOGONPRISMSDF

float octogonPrismSDF( in float3 p, in float r, float h ) {
float3 k = float3(-0.9238795325,   // sqrt(2+sqrt(2))/2
0.3826834323,   // sqrt(2-sqrt(2))/2
0.4142135623 ); // sqrt(2)-1
// reflections
p = abs(p);
p.xy -= 2.0*min(dot(float2( k.x,k.y),p.xy),0.0)*float2( k.x,k.y);
p.xy -= 2.0*min(dot(float2(-k.x,k.y),p.xy),0.0)*float2(-k.x,k.y);
// polygon side
p.xy -= float2( clamp(p.x, -k.z*r, k.z*r), r);
float2 d = float2( length(p.xy)*sign(p.y), p.z-h );
return min(max(d.x,d.y),0.0) + length(max(d,0.0));
}

#endif
``````