POV-Ray : Newsgroups : povray.programming : Superellipsoid bug (job000190) : Re: Superellipsoid bug (job000190) Server Time
28 Jul 2024 06:12:38 EDT (-0400)
  Re: Superellipsoid bug (job000190)  
From: Massimo Valentini
Date: 18 Oct 2002 12:34:42
Message: <3db03822@news.povray.org>
"Massimo Valentini" ha scritto 
: 
: #macro S(E,N,P)
:   superellipsoid { <E, N> translate P scale 2*y+1 pigment {rgb
: <1,1,0>} }
: #end
: light_source { -35*z, rgb 1 }
: camera {location -35*z look_at 0 }
: 
: #declare E = 5;
: #declare P = -20*x;
: #while (E > 0.00001)
:   S(E,.1,P+3.5*y)
:   S(E, E, P)
:   S(.1,E,P-3.5*y)
:   #declare P = P + 5*x;
:   #declare E = E / 5;
: #end
: 

With the following patch to the original file super.cpp it's
possible to obtain a better image for the previous scene.

I modified the even the function evaluate_superellipsoid too and
introduced a helper function.

HTH Massimo


479,480d478
<   DBL k, x, y, z;
<   VECTOR P, N, E;
481a480,481
>   VECTOR const& E = Superellipsoid->Power;
>   VECTOR P, N;
487,491c487,492
<   Assign_Vector(E, Superellipsoid->Power);
< 
<   x = fabs(P[X]);
<   y = fabs(P[Y]);
<   z = fabs(P[Z]);
---
>   DBL r, z2n = 0;
>   if (P[Z] != 0)
>   {
>     z2n = power(fabs(P[Z]), E[Z]);
>     P[Z] = z2n / P[Z];
>   }
493c494,496
<   k = power(power(x, E[X]) + power(y, E[X]), E[Y] - 1.0);
---
>   if (fabs(P[X]) > fabs(P[Y]))
>   {
>     r = power(fabs(P[Y] / P[X]), E[X]);
495,497c498,503
<   N[X] = k * SGNX(P[X]) * power(x, E[X] - 1.0);
<   N[Y] = k * SGNX(P[Y]) * power(y, E[X] - 1.0);
<   N[Z] =     SGNX(P[Z]) * power(z, E[Z] - 1.0);
---
>     P[X] = (1-z2n)  /  P[X];
>     P[Y] = P[Y] ? (1-z2n) * r / P[Y] : 0;
>   }
>   else if (P[Y] != 0)
>   {
>     r = power(fabs(P[X] / P[Y]), E[X]);
498a505,508
>     P[X] = P[X] ? (1-z2n) * r / P[X] : 0;
>     P[Y] = (1-z2n) / P[Y];
>   }
>   if (P[Z]) P[Z] *= (1 + r);
501c511
<   MTransNormal(Result, N, Superellipsoid->Trans);
---
>   MTransNormal(Result, P, Superellipsoid->Trans);
1084a1095,1111
> static DBL my_g(DBL x, DBL y, DBL e)
> {
>   DBL g = 0;
>   if (x > y)
>   {
>     g = 1 + power(y/x, e);
>     if (g != 1) g = power(g, 1/e);
>     g *= x;
>   }
>   else if (y != 0)
>   {
>     g = 1 + power(x/y, e);
>     if (g != 1) g = power(g, 1/e);
>     g *= y;
>   }
>   return g;
> }
1088,1094c1115,1117
<   VECTOR V1;
< 
<   V1[X] = power(fabs(P[X]), Superellipsoid->Power[X]);
<   V1[Y] = power(fabs(P[Y]), Superellipsoid->Power[X]);
<   V1[Z] = power(fabs(P[Z]), Superellipsoid->Power[Z]);
< 
<   return(power(V1[X] + V1[Y], Superellipsoid->Power[Y]) + V1[Z] - 1.0);
---
>   DBL f = my_g(fabs(P[X]), fabs(P[Y]), Superellipsoid->Power[X]);
>   f = my_g(f, fabs(P[Z]), Superellipsoid->Power[Z]);
>   return f - 1;


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.