POV-Ray : Newsgroups : povray.general : Hexagon pattern with 4 or 7 colors? : Re: Hexagon pattern with 4 or 7 colors? Server Time
25 Apr 2024 19:56:12 EDT (-0400)
  Re: Hexagon pattern with 4 or 7 colors?  
From: Bald Eagle
Date: 27 Apr 2018 03:05:01
Message: <web.5ae2218297bd1601c437ac910@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:

> Perhaps if the existing POV-Ray internal function code were posted here, that
> would provide a good jumping-off point?

Good idea Bill, get on that, will you?
Right.
Here ya go.

From fnintern.cpp

DBL f_hex_x(FPUContext *ctx, DBL *ptr, unsigned int fn); // 27
DBL f_hex_y(FPUContext *ctx, DBL *ptr, unsigned int fn); // 28

const Trap POVFPU_TrapTable[] =
{
    { f_hex_x,                   1 + 3 }, // 27
    { f_hex_y,                   1 + 3 }, // 28
};


DBL f_hex_x(FPUContext *ctx, DBL *ptr, unsigned int) // 27
{
    DBL x1,y1,x2,y2, th;
    x1=fabs(fmod(fabs(PARAM_X), sqrt(3.0))-sqrt(3.0)/2);
    y1=fabs(fmod(fabs(PARAM_Y), 3)-1.5);
    x2=sqrt(3.0)/2-x1;
    y2=1.5-y1;
    if ((x1*x1+y1*y1)>(x2*x2+y2*y2))
    {
        x1=x2;
        y1=y2;
    }
    if ((x1==0)&&(y1==0))
        PARAM_X=0.000001;
    th=atan2(y1,x1);
    if (th<M_PI/6)
        return(x1);
    else
    {
        x1=cos(M_PI/3)*x1+sin(M_PI/3)*y1;
        return(x1);
    }
}

DBL f_hex_y(FPUContext *ctx, DBL *ptr, unsigned int) // 28
{
    DBL x1,y1,x2,y2, th;
    x1=fabs(fmod(fabs(PARAM_X), sqrt(3.0))-sqrt(3.0)/2);
    y1=fabs(fmod(fabs(PARAM_Y), 3)-1.5);
    x2=sqrt(3.0)/2-x1;
    y2=1.5-y1;
    if ((x1*x1+y1*y1)>(x2*x2+y2*y2))
    {
        x1=x2;
        y1=y2;
    }
    if ((x1==0)&&(y1==0))
        PARAM_X=0.000001;
    th=atan2(y1,x1);
    if (th<M_PI/6)
        return(y1);
    else
    {
        y1=-sin(M_PI/3)*x1+cos(M_PI/3)*y1;
        return(fabs(y1));
    }
}


Post a reply to this message

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