Distance function for N-prism Im looking for distance function that describes N prism. Im looking for pentagon prism, heptagon prism and octagon prism functions.
Function accepts vec3 position, which is observer position. Function returns one value, which is shortest distance to the surface of the prism. 
Function doesnt provide where the pierce point is.
Function also might accept additional params like radius and height of the prism or it might be cosntant. 
Prism center is always at [0, 0, 0] coordinate and it can be rotated or scaled as you want/need. 
Formula can be used for raymarching algorithm.
Formulas for Triangular Prism and Hexagonal Prism I have found:
// p is position of the observer, h.x is prism radius, h.y is halved height of the prism
float sdHexPrism( vec3 p, vec2 h )
{
    vec3 q = abs(p);
    return max(q.z-h.y,max((q.x*0.866025+q.y*0.5),q.y)-h.x);
}

float sdTriPrism( vec3 p, vec2 h )
{
    vec3 q = abs(p);
    return max(q.z-h.y,max(q.x*0.866025+p.y*0.5,-p.y)-h.x*0.5);
}

Im looking for any closer explination or ideas you might have, also both algebraic or programatic formulas.
EDIT:
Based on comments, I must admit, question might be difficult. Here I provided as many tips as I could. Because obviously I dont know the right answer... 


*

*Provided formulas doesnt contain rotation or scale. Rotation and scale is constant. 

*What is max(x, y)? higher value is returned 

*What is abs(p)? (Absolute value) If the observer position is [-2,-3,4] it becomes [2,3,4]. Dont know why...

*What is the number 0.866025? No idea, big question for me.

*max(q.z-h.y, unknown); first part is probably how far is the base of the object from observer


In addition, I will try to provide test tool that you can use to verify the formula. 
 A: A general solution for an N-gon Signed Distance Function (SDF) is provided by Inigo Quilez here:
float nGon(in int n, in vec2 p, in float r) {
    // these 2 lines can be precomputed
    float an = 6.2831853 / float(n);
    float he = r * tan(0.5 * an);

    // rotate to first sector
    p = -p.yx; // if you want the corner to be up
    float bn = an * floor((atan(p.y, p.x) + 0.5 * an) / an);
    vec2 cs = vec2(cos(bn), sin(bn));
    p = mat2(cs.x, -cs.y, cs.y, cs.x) * p;

    // side of polygon
    return length(p - vec2(r, clamp(p.y, -he, he))) * sign(p.x-r);
}

Any polygon can be converted to a prism by "boxing" it by depth:
// for the distance result of any 2D SDF, returns a 3D prism for the 3rd axis position value v
float toPrism(in float d2d, in float v, in float size) {
    vec2 d = vec2(d2d, abs(v) - 0.5 * size);
    return length(max(d, 0.0)) + min(max(d.x, d.y), 0.0);
}

So a general function for an N-prism SDF is:
float nPrism(in int n, in vec3 p, in float r, in float depth) {
    float d = nGon(n, p.xy, r);
    return toPrism(d, p.z, depth);
}

More information here.
