POV-Ray : Newsgroups : povray.advanced-users : New random distribution macros : Re: New random distribution macros Server Time
24 Jun 2021 15:48:28 EDT (-0400)
  Re: New random distribution macros  
From: Bald Eagle
Date: 3 Mar 2021 15:30:07
Message: <web.603ff137296d8a3b1f9dae300@news.povray.org>
Just gonna think out loud here, so that people can follow the thought process
(or lack thereof), and see some of the challenges, limitations, problems,
complexities, hidden difficulties, and perhaps offer some more experienced
insights and solutions for addressing the issues.

I'm working on writing VRand_In_Polygon.
I can't just plug in a polygon object as an argument, because in order to
calculate the winding number to see if the point is inside the polygon, I need
access to the array of points that make up the polygon.   And the user doesn't
have access to that data through SDL.

(I wonder if there's a sort of data-structure "union" that could be implemented,
such that "internal" data of an object could be accessed.   Polygon.array or
something like that.)

So, for testing, I define an array, define a polygon constructed from that
array, and then pass the array on to the VRand_In_Polygon macro.

VRand_In_Polygon now has to do a few interesting things.

First, because I have an array and not an object, I can't use min_extent and
max_extent - I have to initialize min and max with the first element of the
array, and then cycle through the rest of the array, updating the min and max
vertex components.  Using that as my bounding rectangle, I generate a random
point in that rectangle, and pass the test point and the vertex array on to the
WindingNumber macro.

WindingNumber as written, returns 0 for outside, 1 for inside.
return (cn&1);    // 0 if even (out), and 1 if  odd (in)
Not sure what the & notation is - maybe xor or something....

But then it occurred to me that, as a class, many of these
generate-a-random-point macros have 2 glaring problems.

The first, is that a lot of the same data gets repeatedly generated inside the
macro as a result of the macro being called from an external loop.  So if I want
to plot 1000 points inside of a polygon, I have to do ALL of that stuff every
time the macro is called.  Wasteful and foolish.

The second, is that most of these hit-or-miss macros only return a point that
has passed the "inside" or "on" test.  Which is great - but what if a user wants
to plot ALL of the randomly generated points and do something like color the
inside/on points green and the outside/off points red?  Can't do that.

So I'm considering 2 things:

1. Rewrite the macros to accept a number-of-iterations argument, and do all of
the point generation and testing _inside of the macro_ after all of the setup
calculations are done _once_, and then return not a point, but an _array_ of

2. rewriting / supplementing those macros with a version that returns a
4-component vector: <x, y, z, flag>.
That way the output of the test function returns all of the available
information for the user to work with.  Be it plot a point, not plot a point,
count the pass/fail for a graph or histogram / statistical report, etc.
Maybe the testing is done for object placement on terrain, and "inside" is a
lake, and "outside" is land.  Or for an animation, where rain drops are falling,
or the object tests are used to determine if a rubber ball hits a hard or
soft/sticky surface......

Post a reply to this message

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