POV-Ray : Newsgroups : povray.general : Debugging help Server Time
20 Apr 2024 06:02:45 EDT (-0400)
  Debugging help (Message 1 to 10 of 17)  
Goto Latest 10 Messages Next 7 Messages >>>
From: Anthony D  Baye
Subject: Debugging help
Date: 22 May 2017 03:15:01
Message: <web.59228e7d3389885cfd6b6fe10@news.povray.org>
Back working on my Seraglio project after a bit of a hiatus due to work and
other issues.

Been working on this all weekend.  It's beginning to take shape, but there's
something wrong with the math.

It works until (I think) the vector changes signs... the bricks start generating
perpendicular to the wall direction, rather than with it.

the code is supposed to build the wall brick-wise from isosurface blocks. It's a
bit overkill, but I'm horrible at texturing. And a bit obsessive when it comes
to detail.

If anyone can help me with this problem, I'd appreciate it.

#version 3.7;

#include "math.inc"
#include "functions.inc"
#include "rad_def.inc"
#include "kolors.inc"
#include "rand.inc"

#default {
    pigment { rgb <0.07,0.37,0.75> }
    finish { ambient 0 }
    }
#local FAST = 1;
#local FANCY = 2;
#local FANCIER = 3;
/* !- Global Switches -! */
#declare RAD = off      ;
#declare PHO = off      ;
#declare TEX = on       ;
#declare LGT = FAST     ;
/* --------------------- */

#if(RAD)
    #if(LGT = FANCIER)
        #declare Count_Max = 160000;
        #default {
            radiosity { importance 0.001 }
            }
//intersection {
    #else
        #declare Count_Max = 160;
        #default {
            radiosity { importance 1.0 }
            }
    #end
#end

global_settings {
#if(RAD)
     radiosity {
        pretrace_start 0.08
        pretrace_end   0.004
        count Count_Max

        nearest_count 8
        error_bound 0.15
        recursion_limit 2
        low_error_factor 0.5
        gray_threshold 0.2
        minimum_reuse 0.015
        brightness 1.0
        normal off

        adc_bailout 0.01/2
       }
#end

#if (PHO)
    photons {
        // count 20000
        spacing 1/1000
//        autostop 0.51
//        jitter 0.4
        }
#end
     assumed_gamma 1.0
     // max_trace_level 10
     }

light_source { <60.0, 120.0, -50.0> rgb 1 }

camera {
    ultra_wide_angle
    location <30.0, 75.0, -100.0>
//    location <0.0, 15.0, -25.0>
    up y
    right x*(image_width/image_height)
    look_at <0.0, 6.0, 25.0>
    }

#declare F_RoughBrick =
function {
     pattern {
          wrinkles
          turbulence <0.3, 0.1, 0.5>
    scale <1.0, 1.0, 0.125>
          }
     }
#declare F_GraniteFacing =
function {
     pattern {
          granite
          turbulence <0.3, 0.1, 0.5>
    scale 0.01
          }
     }

#declare F_Sandstone =
function {
     pattern {
          bozo
          turbulence 0.7
          ramp_wave
          rotate -90.0 * x
          }
     }

#macro Block(X, Y, Z)
#local pattern_seed = 15643544181;
#local _X = Rand_Normal(0.0, 1.0, RdmA)*2e5;
#local _Y = Rand_Normal(0.0, 1.0, RdmB)*2e5;
#local _Z = Rand_Normal(0.0, 1.0, RdmC)*2e5;

isosurface {
 function {
      f_rounded_box(x,y,z,0.0625,
           X-0.0078125*F_RoughBrick(x-_X,y-_Y,z-_Z),
           Y-0.0078125*F_RoughBrick(x-_X,y-_Y,z-_Z),
           Z/2-0.078125*F_RoughBrick(x-_X,y-_Y,z-_Z))
      }
 threshold 0
 max_gradient 2
 contained_by { box { <0.0, 0.0, -Z/2> <X, Y, Z/2> } }
 all_intersections
     // translate <0.5*L, 0.5*T, 0.0>
 }
#end

#macro Wall(START, END, HEIGHT, BSIZE, MWIDTH)

    #local wall_vec = vnormalize(END - START);
    #local wall_vec = <wall_vec.u, 0, wall_vec.v>;
    #local wall_dlength = vlength(END - START);
    #local wall_perp = vcross(wall_vec, y);
    #local wall_th  = degrees(acos(vdot(wall_vec,x)));
    #local remainder = 0;

//intersection {
    union {
    #local wall_aheight = 0.0;
    #while(wall_aheight < HEIGHT)
    #local wall_alength = 0.0;
        #while(wall_alength < wall_dlength)
            #local nbLength = (remainder > 0 ? remainder : min(BSIZE.x,
wall_dlength - wall_alength));
            #local remainder = 0;
            object { Block(nbLength, BSIZE.y, BSIZE.z) rotate -(wall_th)*y
translate <START.u, wall_aheight, START.v> + wall_alength*wall_vec }
        #local wall_alength = wall_alength + nbLength + MWIDTH;
        #end
    #local remainder = BSIZE.x - nbLength;
    #local wall_aheight = wall_aheight + BSIZE.y + MWIDTH;
    #end
        }
/*    prism {
        0, HEIGHT, 5
        START - BSIZE.z*0.5*<wall_perp.x, wall_perp.z>, END -
BSIZE.z*0.5*<wall_perp.x, wall_perp.z>,
        END + BSIZE.z*0.5*<wall_perp.x, wall_perp.z>, START +
BSIZE.z*0.5*<wall_perp.x, wall_perp.z>,
        START - BSIZE.z*0.5*<wall_perp.x, wall_perp.z>
        }
    }*/
#end

#macro hexTower(MINR, PROTR, HEIGHT, OFFSET)

#local minR = MINR;
#local majR = minR/cosd(30);
#local pR = PROTR;
#local Offset2 = OFFSET;

#declare tArray =
array[19] {
    majR*<cosd(0), sind(0)>,
    <majR*cosd(60) - pR*sind(60 + 150), majR*sind(60) + pR*cosd(60 + 150)>,
    <(majR + Offset2)*cosd(60) - pR*sind(60 + 150), (majR + Offset2)*sind(60) +
pR*cosd(60 + 150)>,
    (majR + Offset2)*<cosd(60), sind(60)>,
    <(majR + Offset2)*cosd(60) - pR*sind(60 + 30), (majR + Offset2)*sind(60) +
pR*cosd(60 + 30)>,
    <majR*cosd(60) - pR*sind(60 + 30), majR*sind(60) + pR*cosd(60 + 30)>
    majR*<cosd(120), sind(120)>,
    <majR*cosd(180) - pR*sind(180 + 150), majR*sind(180) + pR*cosd(180 + 150)>,
    <(majR + Offset2)*cosd(180) - pR*sind(180 + 150), (majR + Offset2)*sind(180)
+ pR*cosd(180 + 150)>,
    (majR + Offset2)*<cosd(180), sind(180)>,
    <(majR + Offset2)*cosd(180) - pR*sind(180 + 30), (majR + Offset2)*sind(180)
+ pR*cosd(180 + 30)>,
    <majR*cosd(180) - pR*sind(180 + 30), majR*sind(180) + pR*cosd(180 + 30)>
    majR*<cosd(240), sind(240)>,
    <majR*cosd(300) - pR*sind(300 + 150), majR*sind(300) + pR*cosd(300 + 150)>,
    <(majR + Offset2)*cosd(300) - pR*sind(300 + 150), (majR + Offset2)*sind(300)
+ pR*cosd(300 + 150)>,
    (majR + Offset2)*<cosd(300), sind(300)>,
    <(majR + Offset2)*cosd(300) - pR*sind(300 + 30), (majR + Offset2)*sind(300)
+ pR*cosd(300 + 30)>,
    <majR*cosd(300) - pR*sind(300 + 30), majR*sind(300) + pR*cosd(300 + 30)>,
    majR*<cosd(0), sind(0)>
    }

#for(c, 0, 17, 1)
    Wall(tArray[c], tArray[c + 1], 10.0, <2.25, 0.75, 1.25>, 0.375/12)
#end

#end

plane { y, 0 pigment { White } }

union { hexTower(35.0 + 2.25/cosd(30), 10.0 + 2.25/cosd(30), 10.0, 5.0) }
//Wall(<-15.0, 10.0>, <15.0, 25.0>, 10.0, <2.25, 0.75, 1.25>, 0.375/12)


Post a reply to this message

From: Thomas de Groot
Subject: Re: Debugging help
Date: 22 May 2017 07:33:04
Message: <5922cc70@news.povray.org>
On 22-5-2017 9:11, Anthony D. Baye wrote:
> It works until (I think) the vector changes signs... the bricks start generating
> perpendicular to the wall direction, rather than with it.

Not perpendicular it seems, but at a 30 degrees angle... I guess this 
happens somewhere in tArray.

>
> the code is supposed to build the wall brick-wise from isosurface blocks. It's a
> bit overkill, but I'm horrible at texturing. And a bit obsessive when it comes
> to detail.
>

It is a nice way of building :-)

-- 
Thomas


Post a reply to this message

From: Kenneth
Subject: Re: Debugging help
Date: 22 May 2017 07:55:00
Message: <web.5922d0a81ef603fe883fb31c0@news.povray.org>
I've at least narrowed-down the problem, but I haven't found the solution yet. I
can give hints, though:

This line in your code, in your WALL #macro, seems to be the prime culprit--the
way it rotates the individual wall sections...

object { Block(nbLength, BSIZE.y, BSIZE.z) rotate -1*(wall_th)*y

Change the minus sign to a plus sign, and it will cause the 'problem' walls to
suddenly appear on the opposite side of the fort! That rotation entry makes use
of  your  wall_th  variable. Apparently, the *sign* of that rotation needs to
flip from minus to plus, depending on how *much* rotation it specifies. (The
problem seems to occur when an individual wall section rotates past 90-deg(?) or
180-deg(?) from its original orientation. It's hard to tell which is correct.
Maybe both(?!))  Perhaps the underlying problem stems from one of these two
lines, also in the WALL macro...

#local wall_vec = <wall_vec.u, 0, wall_vec.v>;

#local wall_th  = degrees(acos(vdot(wall_vec,x)));


[By the way, this line there serves no purpose...]

#local wall_perp = vcross(wall_vec, y);


Post a reply to this message

From: Kenneth
Subject: Re: Debugging help
Date: 22 May 2017 08:05:01
Message: <web.5922d3541ef603fe883fb31c0@news.povray.org>
"Kenneth" <kdw### [at] gmailcom> wrote:

>
> [By the way, this line there serves no purpose...]
>
> #local wall_perp = vcross(wall_vec, y);

Oops, that's because I deleted your (commented-out) PRISM block. Sorry.


Post a reply to this message

From: Bald Eagle
Subject: Re: Debugging help
Date: 22 May 2017 10:15:00
Message: <web.5922f2261ef603fec437ac910@news.povray.org>
"Kenneth" <kdw### [at] gmailcom> wrote:

> This line in your code, in your WALL #macro, seems to be the prime culprit--the
> way it rotates the individual wall sections...
>
> object { Block(nbLength, BSIZE.y, BSIZE.z) rotate -1*(wall_th)*y
>
> Change the minus sign to a plus sign, and it will cause the 'problem' walls to
> suddenly appear on the opposite side of the fort! That rotation entry makes use
> of  your  wall_th  variable. Apparently, the *sign* of that rotation needs to
> flip from minus to plus, depending on how *much* rotation it specifies.

I don't presently have much time to test this out, but I'm going to guess that
maybe for those sections there needs to be a switching of the start and end
points - which will flip that vector 180 deg.
As Thomas noted - they're "30 deg" off - I'd say if they were rotated (*) in the
opposite direction, they'd be in line.
Try editing your input array - at least for one of those sections.

(*) I may find it useful for future clarity to start differentiating between
rotation and revolution.
Rotation would be before any translation, so it would rotate around the origin
which lies on its own axis.   Revolution would be after a translation, and so
the object would revolve around the origin - not it's own axis.


Post a reply to this message

From: clipka
Subject: Re: Debugging help
Date: 22 May 2017 12:01:21
Message: <59230b51$1@news.povray.org>
Am 22.05.2017 um 13:51 schrieb Kenneth:

> object { Block(nbLength, BSIZE.y, BSIZE.z) rotate -1*(wall_th)*y
> 
> Change the minus sign to a plus sign, and it will cause the 'problem' walls to
> suddenly appear on the opposite side of the fort! That rotation entry makes use
> of  your  wall_th  variable. Apparently, the *sign* of that rotation needs to
> flip from minus to plus, depending on how *much* rotation it specifies. (The
> problem seems to occur when an individual wall section rotates past 90-deg(?) or
> 180-deg(?) from its original orientation. It's hard to tell which is correct.
> Maybe both(?!))  Perhaps the underlying problem stems from one of these two
> lines, also in the WALL macro...
> 
> #local wall_vec = <wall_vec.u, 0, wall_vec.v>;
> 
> #local wall_th  = degrees(acos(vdot(wall_vec,x)));

My spontaneous guess would be that the use of `acos` here might be to
blame, as it will only return values in the range from -90 to +90
degrees, losing information about the quadrant. Maybe try rephrasing
that as an expression satisfying the form `atan(A/B)`, and then use
`atan2(A,B)` instead to make sure you get the quadrant right.

I haven't fully thought it through, but I think the following should do
the trick:

    #local wall_th = degrees(atan2(wall_vec.x, wall_vec.z));

(You may need to tweak the expression a bit, e.g. swapping the `.x` and
`.z`, and/or changing the sign of one or both of them.)


Post a reply to this message

From: Kenneth
Subject: Re: Debugging help
Date: 22 May 2017 13:50:01
Message: <web.592323ab1ef603fe883fb31c0@news.povray.org>
By the way, I added a few things to your code, to help clarify the visual nature
of the problem: X- and Z-axis markers (horizontal cylinders) and a camera
looking straight down. It was difficult to see (solely from the complex code,
or even from a render) where the 'start' wall section was placed.


Post a reply to this message

From: Kenneth
Subject: Re: Debugging help
Date: 22 May 2017 16:55:01
Message: <web.59234eb71ef603fe883fb31c0@news.povray.org>
By the way, the isosurface() object in the BLOCK macro has a max_gradient value
that's really difficult to nail down, for some reason; it's either too high or
too low for any particular individual block object. The result is that the macro
generates hundreds (thousands?!) of 'warning' messages, at the end of a render--
maybe a message for each block! I had to invoke "All_Console=off" in my
resolution .ini file, to supress them. Maybe the blocks are not 'rounded'
enough, and are causing steep-slope max_gradient errors(?)


Post a reply to this message

From: omniverse
Subject: Re: Debugging help
Date: 22 May 2017 23:45:01
Message: <web.5923b0011ef603fe9c5d6c810@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:
>
> My spontaneous guess would be that the use of `acos` here might be to
> blame, as it will only return values in the range from -90 to +90
> degrees, losing information about the quadrant. Maybe try rephrasing
> that as an expression satisfying the form `atan(A/B)`, and then use
> `atan2(A,B)` instead to make sure you get the quadrant right.
>
> I haven't fully thought it through, but I think the following should do
> the trick:
>
>     #local wall_th = degrees(atan2(wall_vec.x, wall_vec.z));
>
> (You may need to tweak the expression a bit, e.g. swapping the `.x` and
> `.z`, and/or changing the sign of one or both of them.)

Well, since no one has actually posted about the solution to this given there I
thought I would try it. Rendered okay as done for macro portion below.

I was looking at it yesterday and thought it must be possible just to put
conditional #if regarding certain degrees for wall_th but only got me thoroughly
confused. I'm no math wizard, by far! Just wanted to see how this went.

#macro Wall(START, END, HEIGHT, BSIZE, MWIDTH)

    #local wall_vec = vnormalize(END - START);
    #local wall_vec = <wall_vec.u, 0, wall_vec.v>;
    #local wall_dlength = vlength(END - START);
    #local wall_perp = vcross(wall_vec, y);
  // #local wall_th  = degrees(acos(vdot(wall_vec,x))); // replaced with...
#local wall_th = degrees(atan2(wall_vec.z, wall_vec.x)); // ...Clipka answer
    #local remainder = 0;
// commented intersection removed from here
    union {
    #local wall_aheight = 0.0;
    #while(wall_aheight < HEIGHT)
    #local wall_alength = 0.0;
        #while(wall_alength < wall_dlength)
            #local nbLength =
            (remainder > 0 ? remainder : min(BSIZE.x, wall_dlength -
wall_alength));
            #local remainder = 0;
            object {
             Block(nbLength, BSIZE.y, BSIZE.z) rotate -(wall_th)*y
translate <START.u, wall_aheight, START.v> + wall_alength*wall_vec
} // object closing brace
        #local wall_alength = wall_alength + nbLength + MWIDTH;
        #end
    #local remainder = BSIZE.x - nbLength;
    #local wall_aheight = wall_aheight + BSIZE.y + MWIDTH;
    #end
    } // union closing brace
// prism removed from here
#end


Post a reply to this message

From: Anthony D  Baye
Subject: Re: Debugging help
Date: 23 May 2017 03:35:00
Message: <web.5923e5451ef603fefd6b6fe10@news.povray.org>
"omniverse" <omn### [at] charternet> wrote:
> clipka <ano### [at] anonymousorg> wrote:
> >
> > My spontaneous guess would be that the use of `acos` here might be to
> > blame, as it will only return values in the range from -90 to +90
> > degrees, losing information about the quadrant. Maybe try rephrasing
> > that as an expression satisfying the form `atan(A/B)`, and then use
> > `atan2(A,B)` instead to make sure you get the quadrant right.
> >
> > I haven't fully thought it through, but I think the following should do
> > the trick:
> >
> >     #local wall_th = degrees(atan2(wall_vec.x, wall_vec.z));
> >
> > (You may need to tweak the expression a bit, e.g. swapping the `.x` and
> > `.z`, and/or changing the sign of one or both of them.)
>
> Well, since no one has actually posted about the solution to this given there I
> thought I would try it. Rendered okay as done for macro portion below.
>
> I was looking at it yesterday and thought it must be possible just to put
> conditional #if regarding certain degrees for wall_th but only got me thoroughly
> confused. I'm no math wizard, by far! Just wanted to see how this went.
>
> #macro Wall(START, END, HEIGHT, BSIZE, MWIDTH)
>
>     #local wall_vec = vnormalize(END - START);
>     #local wall_vec = <wall_vec.u, 0, wall_vec.v>;
>     #local wall_dlength = vlength(END - START);
>     #local wall_perp = vcross(wall_vec, y);
>   // #local wall_th  = degrees(acos(vdot(wall_vec,x))); // replaced with...
> #local wall_th = degrees(atan2(wall_vec.z, wall_vec.x)); // ...Clipka answer
>     #local remainder = 0;
> // commented intersection removed from here
>     union {
>     #local wall_aheight = 0.0;
>     #while(wall_aheight < HEIGHT)
>     #local wall_alength = 0.0;
>         #while(wall_alength < wall_dlength)
>             #local nbLength =
>             (remainder > 0 ? remainder : min(BSIZE.x, wall_dlength -
> wall_alength));
>             #local remainder = 0;
>             object {
>              Block(nbLength, BSIZE.y, BSIZE.z) rotate -(wall_th)*y
> translate <START.u, wall_aheight, START.v> + wall_alength*wall_vec
> } // object closing brace
>         #local wall_alength = wall_alength + nbLength + MWIDTH;
>         #end
>     #local remainder = BSIZE.x - nbLength;
>     #local wall_aheight = wall_aheight + BSIZE.y + MWIDTH;
>     #end
>     } // union closing brace
> // prism removed from here
> #end

Yeah... I did try it,but I got interrupted while I was replying and never got
back to it.

No joy so far.

Regards,
A.D.B.


Post a reply to this message

Goto Latest 10 Messages Next 7 Messages >>>

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