POV-Ray : Newsgroups : povray.advanced-users : [Long] Points on a sphere? Not really. : Re: [Long] Points on a sphere? Not really. Server Time
29 Jul 2024 14:19:58 EDT (-0400)
  Re: [Long] Points on a sphere? Not really.  
From: Tor Olav Kristensen
Date: 16 Jan 2002 20:20:32
Message: <3C462654.32935357@hotmail.com>
Deaken wrote:
> 
>     #declare DotsArray[MinP2] = Normalize (
>       (
>         <
>           ( DotsArray[MinP1].x + PlusElem ) * ( DotsArray[MinP2].x -
> DotsArray[MinP1].x ),
>           ( DotsArray[MinP1].y + PlusElem ) * ( DotsArray[MinP2].y -
> DotsArray[MinP1].y ),
>           ( DotsArray[MinP1].z + PlusElem ) * ( DotsArray[MinP2].z -
> DotsArray[MinP1].z ),
>         >
>       )
>     );
>     #declare DotsArray[MinP1] = Normalize (
>       (
>         <
>           ( DotsArray[MinP1].x - MinusElem ) * ( DotsArray[MinP2].x -
> DotsArray[MinP1].x ),
>           ( DotsArray[MinP1].y - MinusElem ) * ( DotsArray[MinP2].y -
> DotsArray[MinP1].y ),
>           ( DotsArray[MinP1].z - MinusElem ) * ( DotsArray[MinP2].z -
> DotsArray[MinP1].z ),
>         >
>       )
>     );
>     #declare Loop = Loop + 1;
>   #end
>   union {
>     sphere {
>       <0,0,0>, 1
>       texture { pigment { color rgbt <0.7, 1, 0.7, 0.8+0.15> } }
>     }
>     #declare Loop = 0;
>     #while ( Loop < NumDots )
>       sphere {
>         DotsArray[Loop]*0.9825,
>         0.025
>         texture {
>           pigment {
>             color rgbt <0, 1, 0, 0.5>
>           }
>         }
>       }
>       #declare Loop = Loop + 1;
>     #end
>   }
> #end
>...
 
>...
> I thought the problem might be in the multi-line DotsArray[MinP2] (and
> MinP1) statements, but I've tried many things there, and none of them
> have worked.
>...

Here's a reformatted version of what you wrote:

#declare DotsArray[MinP2] =
Normalize(
  (
    <
      (DotsArray[MinP1].x + PlusElem)*(DotsArray[MinP2].x - DotsArray[MinP1].x),
      (DotsArray[MinP1].y + PlusElem)*(DotsArray[MinP2].y - DotsArray[MinP1].y),
      (DotsArray[MinP1].z + PlusElem)*(DotsArray[MinP2].z - DotsArray[MinP1].z),
    >
  )
);

Above there's one level of parentheses more
than necessary:

Normalize((  ));

And the last comma should not be there.

You can replace your Normalize() macro with
a call to the built in vnormalize() operator.

And the parentheses in these three expressions
were not present in Paul Bourke's code:

(DotsArray[MinP1].x + PlusElem)
(DotsArray[MinP1].y + PlusElem)
(DotsArray[MinP1].z + PlusElem)

(Will lead to a serious calculation error)

Also note that all the declarations of the
variables that are only being used within
your macro should be declared with the
#local directive.

So the corrected code should be:

#local DotsArray[MinP2] =
vnormalize(
  <
    DotsArray[MinP1].x + PlusElem*(DotsArray[MinP2].x - DotsArray[MinP1].x),
    DotsArray[MinP1].y + PlusElem*(DotsArray[MinP2].y - DotsArray[MinP1].y),
    DotsArray[MinP1].z + PlusElem*(DotsArray[MinP2].z - DotsArray[MinP1].z)
  >
);

Which can be rewritten like this:

#local DotsArray[MinP2] =
vnormalize(
  <
    DotsArray[MinP1].x,
    DotsArray[MinP1].y,
    DotsArray[MinP1].z
  >
  + PlusElem*
  <
    DotsArray[MinP2].x - DotsArray[MinP1].x,
    DotsArray[MinP2].y - DotsArray[MinP1].y,
    DotsArray[MinP2].z - DotsArray[MinP1].z
  >
);

And further:

#local DotsArray[MinP2] =
vnormalize(
  <DotsArray[MinP1].x, DotsArray[MinP1].y, DotsArray[MinP1].z>
  + PlusElem*
  (
    <DotsArray[MinP2].x, DotsArray[MinP2].y, DotsArray[MinP2].z>
    -
    <DotsArray[MinP1].x, DotsArray[MinP1].y, DotsArray[MinP1].z>
  )
);

All the way to this:

#local DotsArray[MinP2] =
vnormalize(
  DotsArray[MinP1] + PlusElem*(DotsArray[MinP2] - DotsArray[MinP1])
);

Doing the same with your second declaration above:

#local DotsArray[MinP1] =
vnormalize(
  DotsArray[MinP1] - MinusElem*(DotsArray[MinP2] - DotsArray[MinP1])
);


Also have a look at this:

p[p1] = p1 - 0.01*(p2 - p1)

p[p2] = p1 + 1.01*(p2 - p1)
p[p2] = p1 + (1.01*p2 - 1.01*p1)
p[p2] = p1 + 1.01*p2 - 1.01*p1
p[p2] = 1.01*p2 - 0.01*p1
p[p2] = p2 + 0.01*p2 - 0.01*p1
p[p2] = p2 + 0.01*(p2 - p1)

This means that you don't have to use two
different constants for the percent amount to
move the points.

I.e. you can replace both the PlusElem and the
MinusElem constants with e.g. MovePercent if
you rewrite the expression for DotsArray[MinP2]
a little.

And since both expressions use a common sub
expression and to make things easier to
understand, you could pre-calculate this
common expression and put it in a separate
variable; vDir.

Now we have this:

#local MovePercent = 5/100;
#local vDir = DotsArray[MinP2] - DotsArray[MinP1];
#local DotsArray[MinP1] = vnormalize(DotsArray[MinP1] - MovePercent*vDir);
#local DotsArray[MinP2] = vnormalize(DotsArray[MinP2] + MovePercent*vDir);


I hope this helped a little.
(But note that I have not tested any of the code above.)


Tor Olav


Post a reply to this message

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