Skip to main content
deleted 1013 characters in body
Source Link

I'm trying to understand all primitives In this article.After hard work I just learn Sphere and Cube , I wrote description here.

I could draw 2D shapes but I have trouble understanding 3D below codes:

Tours 2D

Torus - signed - exact

Tour 3D

float sdTorus( vec3 p, vec2 t )
{
  vec2 q = vec2(length(p.xz)-t.x,p.y);
  return length(q)-t.y;
}

Length

I can't imagine how this shape drew and I don't know why two length used here.


Cone 2D

Cone - signed - exact

Cone 3D

float sdCone( vec3 p, vec2 c )
{
    // c must be normalized
    float q = length(p.xy);
    return dot(c,vec2(q,p.z));
}

I don't know why dot product used here?


Hexagon 2D

Hexagonal Prism - signed - exact

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);
}

How the calculations are done? why abs and maximum used ?

Hexagon 3D


Triangle 2D

Triangular Prism - signed - exact

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);
}

How the calculations are done? why abs and maximum used ?

Triangle 3D


Capsule / Line - signed - exact

float sdCapsule( vec3 p, vec3 a, vec3 b, float r )
{
    vec3 pa = p - a, ba = b - a;
    float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
    return length( pa - ba*h ) - r;
}

How the calculations are done? why clamp used here? and why clamp and dot product used here?

Capsule 3D

I'm confused please help me to understand this shapes.I hope someone explain each shape.

I'm trying to understand all primitives In this article.After hard work I just learn Sphere and Cube , I wrote description here.

I could draw 2D shapes but I have trouble understanding 3D below codes:

Tours 2D

Torus - signed - exact

Tour 3D

float sdTorus( vec3 p, vec2 t )
{
  vec2 q = vec2(length(p.xz)-t.x,p.y);
  return length(q)-t.y;
}

Length

I can't imagine how this shape drew and I don't know why two length used here.


Cone 2D

Cone - signed - exact

Cone 3D

float sdCone( vec3 p, vec2 c )
{
    // c must be normalized
    float q = length(p.xy);
    return dot(c,vec2(q,p.z));
}

I don't know why dot product used here?


Hexagon 2D

Hexagonal Prism - signed - exact

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);
}

How the calculations are done? why abs and maximum used ?

Hexagon 3D


Triangle 2D

Triangular Prism - signed - exact

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);
}

How the calculations are done? why abs and maximum used ?

Triangle 3D


Capsule / Line - signed - exact

float sdCapsule( vec3 p, vec3 a, vec3 b, float r )
{
    vec3 pa = p - a, ba = b - a;
    float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
    return length( pa - ba*h ) - r;
}

How the calculations are done? why clamp used here? and why clamp and dot product used here?

Capsule 3D

I'm confused please help me to understand this shapes.I hope someone explain each shape.

I'm trying to understand all primitives In this article.After hard work I just learn Sphere and Cube , I wrote description here.

I could draw 2D shapes but I have trouble understanding 3D below codes:

Tours 2D

Torus - signed - exact

Tour 3D

float sdTorus( vec3 p, vec2 t )
{
  vec2 q = vec2(length(p.xz)-t.x,p.y);
  return length(q)-t.y;
}

Length

I can't imagine how this shape drew and I don't know why two length used here.


Cone 2D

Cone - signed - exact

Cone 3D

float sdCone( vec3 p, vec2 c )
{
    // c must be normalized
    float q = length(p.xy);
    return dot(c,vec2(q,p.z));
}

I don't know why dot product used here?

I'm confused please help me to understand this shapes.I hope someone explain each shape.

added 213 characters in body
Source Link

I'm trying to understand all primitives In this article.After hard work I just learn Sphere and Cube , I wrote description here.

I could draw 2D shapes but I have trouble understanding 3D below codes:

Tours 2D

Torus - signed - exact

Tour 3D

float sdTorus( vec3 p, vec2 t )
{
  vec2 q = vec2(length(p.xz)-t.x,p.y);
  return length(q)-t.y;
}

Length

I can't imagine how this shape drew and I don't know why two length used here.


Cone 2D

Cone - signed - exact

Cone 3D

float sdCone( vec3 p, vec2 c )
{
    // c must be normalized
    float q = length(p.xy);
    return dot(c,vec2(q,p.z));
}

I don't know why dot product used here?


#Update

Hexagon 2D

Hexagonal Prism - signed - exact

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);
}

How the calculations are done? why abs and maximum used ?

Hexagon 3D


Triangle 2D

Triangular Prism - signed - exact

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);
}

How the calculations are done? why abs and maximum used ?

Triangle 3D


Capsule / Line - signed - exact

float sdCapsule( vec3 p, vec3 a, vec3 b, float r )
{
    vec3 pa = p - a, ba = b - a;
    float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
    return length( pa - ba*h ) - r;
}

How the calculations are done? why clamp used here? and why clamp and dot product used here?

Capsule 3D

I'm confused please help me to understand this shapes.I hope someone explain each shape.

I'm trying to understand all primitives In this article.After hard work I just learn Sphere and Cube , I wrote description here.

I could draw 2D shapes but I have trouble understanding 3D below codes:

Tours 2D

Torus - signed - exact

Tour 3D

float sdTorus( vec3 p, vec2 t )
{
  vec2 q = vec2(length(p.xz)-t.x,p.y);
  return length(q)-t.y;
}

Length

I can't imagine how this shape drew and I don't know why two length used here.


Cone 2D

Cone - signed - exact

Cone 3D

float sdCone( vec3 p, vec2 c )
{
    // c must be normalized
    float q = length(p.xy);
    return dot(c,vec2(q,p.z));
}

I don't know why dot product used here?


#Update

Hexagon 2D

Hexagonal Prism - signed - exact

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);
}

Hexagon 3D


Triangle 2D

Triangular Prism - signed - exact

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);
}

Triangle 3D


Capsule / Line - signed - exact

float sdCapsule( vec3 p, vec3 a, vec3 b, float r )
{
    vec3 pa = p - a, ba = b - a;
    float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
    return length( pa - ba*h ) - r;
}

Capsule 3D

I'm confused please help me to understand this shapes.I hope someone explain each shape.

I'm trying to understand all primitives In this article.After hard work I just learn Sphere and Cube , I wrote description here.

I could draw 2D shapes but I have trouble understanding 3D below codes:

Tours 2D

Torus - signed - exact

Tour 3D

float sdTorus( vec3 p, vec2 t )
{
  vec2 q = vec2(length(p.xz)-t.x,p.y);
  return length(q)-t.y;
}

Length

I can't imagine how this shape drew and I don't know why two length used here.


Cone 2D

Cone - signed - exact

Cone 3D

float sdCone( vec3 p, vec2 c )
{
    // c must be normalized
    float q = length(p.xy);
    return dot(c,vec2(q,p.z));
}

I don't know why dot product used here?


Hexagon 2D

Hexagonal Prism - signed - exact

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);
}

How the calculations are done? why abs and maximum used ?

Hexagon 3D


Triangle 2D

Triangular Prism - signed - exact

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);
}

How the calculations are done? why abs and maximum used ?

Triangle 3D


Capsule / Line - signed - exact

float sdCapsule( vec3 p, vec3 a, vec3 b, float r )
{
    vec3 pa = p - a, ba = b - a;
    float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
    return length( pa - ba*h ) - r;
}

How the calculations are done? why clamp used here? and why clamp and dot product used here?

Capsule 3D

I'm confused please help me to understand this shapes.I hope someone explain each shape.

added 1070 characters in body
Source Link

I'm trying to understand all primitives In this article.After hard work I just learn Sphere and Cube , I wrote description here.

I could draw 2D shapes but I have trouble understanding 3D below codes:

Tours 2D

Torus - signed - exact

Tour 3D

float sdTorus( vec3 p, vec2 t )
{
  vec2 q = vec2(length(p.xz)-t.x,p.y);
  return length(q)-t.y;
}

Length

I can't imagine how this shape drew and I don't know why two length used here.


Cone 2D

Cone - signed - exact

Cone 3D

float sdCone( vec3 p, vec2 c )
{
    // c must be normalized
    float q = length(p.xy);
    return dot(c,vec2(q,p.z));
}

I don't know why dot product used here?


#Update

Hexagon 2D

Hexagonal Prism - signed - exact

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);
}

Hexagon 3D


Triangle 2D

Triangular Prism - signed - exact

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);
}

Triangle 3D


Capsule / Line - signed - exact

float sdCapsule( vec3 p, vec3 a, vec3 b, float r )
{
    vec3 pa = p - a, ba = b - a;
    float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
    return length( pa - ba*h ) - r;
}

Capsule 3D

I'm confused please help me to understand this shapes.I hope someone explain each shape.

I'm trying to understand all primitives In this article.After hard work I just learn Sphere and Cube , I wrote description here.

I could draw 2D shapes but I have trouble understanding 3D below codes:

Tours 2D

Torus - signed - exact

Tour 3D

float sdTorus( vec3 p, vec2 t )
{
  vec2 q = vec2(length(p.xz)-t.x,p.y);
  return length(q)-t.y;
}

Length

I can't imagine how this shape drew and I don't know why two length used here.


Cone 2D

Cone - signed - exact

Cone 3D

float sdCone( vec3 p, vec2 c )
{
    // c must be normalized
    float q = length(p.xy);
    return dot(c,vec2(q,p.z));
}

I don't know why dot product used here?

I'm confused please help me to understand this shapes.I hope someone explain each shape.

I'm trying to understand all primitives In this article.After hard work I just learn Sphere and Cube , I wrote description here.

I could draw 2D shapes but I have trouble understanding 3D below codes:

Tours 2D

Torus - signed - exact

Tour 3D

float sdTorus( vec3 p, vec2 t )
{
  vec2 q = vec2(length(p.xz)-t.x,p.y);
  return length(q)-t.y;
}

Length

I can't imagine how this shape drew and I don't know why two length used here.


Cone 2D

Cone - signed - exact

Cone 3D

float sdCone( vec3 p, vec2 c )
{
    // c must be normalized
    float q = length(p.xy);
    return dot(c,vec2(q,p.z));
}

I don't know why dot product used here?


#Update

Hexagon 2D

Hexagonal Prism - signed - exact

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);
}

Hexagon 3D


Triangle 2D

Triangular Prism - signed - exact

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);
}

Triangle 3D


Capsule / Line - signed - exact

float sdCapsule( vec3 p, vec3 a, vec3 b, float r )
{
    vec3 pa = p - a, ba = b - a;
    float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
    return length( pa - ba*h ) - r;
}

Capsule 3D

I'm confused please help me to understand this shapes.I hope someone explain each shape.

edited title
Source Link
Loading
added 6 characters in body
Source Link
Loading
edited body
Source Link
Loading
deleted 198 characters in body
Source Link
Loading
edited title
Link
Loading
deleted 805 characters in body
Source Link
Loading
added 368 characters in body
Source Link
Loading
deleted 5 characters in body
Source Link
Loading
Source Link
Loading