POV-Ray : Newsgroups : povray.newusers : Trig Troubles Server Time
13 Nov 2024 05:19:48 EST (-0500)
  Trig Troubles (Message 1 to 6 of 6)  
From: Matthew Green
Subject: Trig Troubles
Date: 3 Mar 2001 13:31:06
Message: <3aa1386a@news.povray.org>
I want to create a ring of random width made of randomly spaced particles.
What I get is random particles within a square boundary.  I've stared at
this for 45 minutes now.  Where am I screwing up?
looprun, ringminrad1, ringwidth1, seed1-4, and deftex are all previously
declared.

#while (looprun < 4000)
 #declare x1 = (ringminrad1 + (ringwidth1 * rand(seed1))) *
cos(radians(90*rand(seed2)));
 #declare z1 = (ringminrad1 + (ringwidth1 * rand(seed1))) *
sin(radians(90*rand(seed2)));
 #declare posnegx = rand(seed4);
 #if (posnegx < 0.5)
    #declare posnegx = -1;
 #else
    #declare posnegx = 1;
 #end
 #declare posnegz = rand(seed4);
 #if (posnegz < 0.5)
    #declare posnegz = -1;
 #else
    #declare posnegz = 1;
 #end
 sphere {
    <0,0,0>,1
    rotate <90*rand(seed3),90*rand(seed3),90*rand(seed3)>
    scale <rand(seed3),rand(seed3),rand(seed3)>
    translate <posnegx * x1,rand(seed3),posnegz * z1>
    texture {deftex}
 }
 #declare looprun = looprun + 1;

#end


Post a reply to this message

From: Matthew Green
Subject: Re: Trig Troubles
Date: 3 Mar 2001 15:34:25
Message: <3aa15551$1@news.povray.org>
What I'm doing wrong is calling rand twice, once for the x value, the other
for the z, thus getting two different angles for each component.  I'm bound
to get weird results that way.  I should declare the angle beforehand, thus
getting only a single random value with which to translate to a position.

While I'm at it, if I change those 90s to 360s, I don't have to bother with
the posneg determinations...

No need to reply...  I'm an idiot.

Thanks for listening to me babble, though.

- Matthew

"Matthew Green" <iam### [at] yahoocom> wrote in message
news:3aa1386a@news.povray.org...
> I want to create a ring of random width made of randomly spaced particles.
> What I get is random particles within a square boundary.  I've stared at
> this for 45 minutes now.  Where am I screwing up?
> looprun, ringminrad1, ringwidth1, seed1-4, and deftex are all previously
> declared.
>
> #while (looprun < 4000)
>  #declare x1 = (ringminrad1 + (ringwidth1 * rand(seed1))) *
> cos(radians(90*rand(seed2)));
>  #declare z1 = (ringminrad1 + (ringwidth1 * rand(seed1))) *
> sin(radians(90*rand(seed2)));
>  #declare posnegx = rand(seed4);
>  #if (posnegx < 0.5)
>     #declare posnegx = -1;
>  #else
>     #declare posnegx = 1;
>  #end
>  #declare posnegz = rand(seed4);
>  #if (posnegz < 0.5)
>     #declare posnegz = -1;
>  #else
>     #declare posnegz = 1;
>  #end
>  sphere {
>     <0,0,0>,1
>     rotate <90*rand(seed3),90*rand(seed3),90*rand(seed3)>
>     scale <rand(seed3),rand(seed3),rand(seed3)>
>     translate <posnegx * x1,rand(seed3),posnegz * z1>
>     texture {deftex}
>  }
>  #declare looprun = looprun + 1;
>
> #end
>
>
>


Post a reply to this message

From: Setepenaset
Subject: Re: Trig Troubles
Date: 3 Mar 2001 17:50:09
Message: <3aa17521@news.povray.org>
Matthew Green wrote :
No need to reply...  I'm an idiot.
Thanks for listening to me babble, though.

-------------------------------------------------------------------------
Matthew -
Just in passing - it doesn't require idiocy to make a mistake (plus, idiocy
would preclude the likelihood of correcting your problem); and, your
'babble' taught me something. All-in-all, not a bad day's work. :-)
Setep


Post a reply to this message

From: Margus Ramst
Subject: Re: Trig Troubles
Date: 3 Mar 2001 20:14:04
Message: <3AA197D1.A5A6D1F7@peak.edu.ee>
Matthew Green wrote:
> 
> I want to create a ring of random width made of randomly spaced particles.
> What I get is random particles within a square boundary.  I've stared at
> this for 45 minutes now.  Where am I screwing up?

I see you already found the answer to your problem. However I think you could
cut out much of the trig stuff by using POV's built-in vector functions;
v_rotate() in particular seems to do exactly what you need, or perhaps
vaxis_rotate()

-- 
Margus Ramst

Personal e-mail: mar### [at] peakeduee
TAG (Team Assistance Group) e-mail: mar### [at] tagpovrayorg
Home page http://www.hot.ee/margusrt


Post a reply to this message

From: yooper
Subject: Re: Trig Troubles
Date: 4 Mar 2001 10:14:34
Message: <3aa25bda$1@news.povray.org>
Matthew Green wrote :
No need to reply...  I'm an idiot.
Thanks for listening to me babble, though.

-------------------------------------------------------------------------
Matthew -
Just in passing - it doesn't require idiocy to make a mistake (plus, idiocy
would preclude the likelihood of correcting your problem); and, your
'babble' taught me something. All-in-all, not a bad day's work. :-)
Setep
--------------

Yup ... been there, done that ;)
and . . . in my experience, it is the mistakes that usually lead me to
the most interesting places.  Those areas that I never would have
thought to explore . . .  the place where most new ideas spring from.
Serendipity ;)
**
Y


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Trig Troubles
Date: 10 Mar 2001 15:40:53
Message: <3AAA906F.204B1E48@hotmail.com>
Matthew Green wrote:
> 
> I want to create a ring of random width made of randomly spaced particles.
>...

Hello Matthew

POV-Ray has some very useful built in functions that you 
can use for this. So there's no need to do this "manually"
as you seem to be doing.

See my example code below.

It uses the vrotate() function (as also Margus suggested).

-- 
Best regards,

Tor Olav

mailto:tor### [at] hotmailcom
http://hjem.sol.no//t-o-k/tokpicts.html
http://www.crosswinds.net/~tok


>...
> What I get is random particles within a square boundary.  I've stared at
> this for 45 minutes now.  Where am I screwing up?
> looprun, ringminrad1, ringwidth1, seed1-4, and deftex are all previously
> declared.
> 
> #while (looprun < 4000)
>  #declare x1 = (ringminrad1 + (ringwidth1 * rand(seed1))) *
> cos(radians(90*rand(seed2)));
>  #declare z1 = (ringminrad1 + (ringwidth1 * rand(seed1))) *
> sin(radians(90*rand(seed2)));
>  #declare posnegx = rand(seed4);
>  #if (posnegx < 0.5)
>     #declare posnegx = -1;
>  #else
>     #declare posnegx = 1;
>  #end
>  #declare posnegz = rand(seed4);
>  #if (posnegz < 0.5)
>     #declare posnegz = -1;
>  #else
>     #declare posnegz = 1;
>  #end
>  sphere {
>     <0,0,0>,1
>     rotate <90*rand(seed3),90*rand(seed3),90*rand(seed3)>
>     scale <rand(seed3),rand(seed3),rand(seed3)>
>     translate <posnegx * x1,rand(seed3),posnegz * z1>
>     texture {deftex}
>  }
>  #declare looprun = looprun + 1;
> 
> #end


// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =

#version 3.1;

#include "colors.inc"

global_settings { ambient_light color -White }

background { color Blue/2 }

light_source {
  50*<-2, 1, -1>
  color White + Yellow
}

camera {
  location 15*<0, 1, -2>
  look_at <0, -2, 0>
}

#declare DefTex = texture { pigment { color White + Blue } }

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =

#declare RingMinRad = 12;
#declare RingWidth = 4;

#declare RR = seed(314);

#declare LoopRun = 0;
#while (LoopRun < 4000)
  #declare Radius = RingMinRad + RingWidth*rand(RR);
  #declare Angle = 360*rand(RR);
  #declare Vector = Radius*vrotate(x, Angle*y);
  sphere {
    <0, 0, 0>, 1
    scale <rand(RR), rand(RR), rand(RR)>
    rotate 90*<rand(RR), rand(RR), rand(RR)>
    translate Vector + rand(RR)*y
    texture { DefTex }
    no_shadow
  }
  #declare LoopRun = LoopRun + 1;
#end // while

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =


Post a reply to this message

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