Welcome to Fractal Forums

Fractal Software => Fragmentarium => Topic started by: SCORPION on October 30, 2014, 12:52:56 PM




Title: DE tetrahedron
Post by: SCORPION on October 30, 2014, 12:52:56 PM
It is impossible to write the function DE Tetrahedron.
That's the way it turns out, a normal Tetrahedron - no. What is wrong?

Code:
#include "DE-Raytracer.frag"

float DE(vec3 p) {

return (max(abs(-p.x-p.y-p.z), 0.0) -0.5 +max(abs(-p.x+p.y-p.z) ,0.0)-0.5 +max(abs(-p.x+p.y+p.z),0.0))-0.5;

}


Title: Re: DE tetrahedron
Post by: claude on October 30, 2014, 02:19:22 PM
Here's one I came up with by trial and error after reading http://mathworld.wolfram.com/Point-PlaneDistance.html

Not sure why it works (I just fiddled with it until it did).  There's probably a better way.

Code:
#include "DE-Raytracer.frag"

float  DE(vec3 z) {
  float d1 = dot(z, normalize(vec3( 1.0,  1.0,  1.0))) + 1.0;
  float d2 = dot(z, normalize(vec3 (1.0, -1.0, -1.0))) + 1.0;
  float d3 = dot(z, normalize(vec3(-1.0  ,1.0, -1.0))) + 1.0;
  float d4 = dot(z, normalize(vec3(-1.0, -1.0,  1.0))) + 1.0;
  return -min(min(min(d1, d2), d3), d4);
}


Title: Re: DE tetrahedron
Post by: SCORPION on October 30, 2014, 02:38:54 PM
Thanks, it works!
so to simplify

Code:
#include "DE-Raytracer.frag"

float  DE(vec3 z) {
  float d1 = dot(z,(vec3( 1.0,  1.0,  1.0)));
  float d2 = dot(z,(vec3 (1.0, -1.0, -1.0)));
  float d3 = dot(z,(vec3(-1.0  ,1.0, -1.0)));
  float d4 = dot(z,(vec3(-1.0, -1.0,  1.0)));
  return -min(min(min(d1, d2), d3), d4)-1;
}

Perhaps there is another way, but I have not found ...