POV-Ray : Newsgroups : povray.general : Boneheaded 3D Trig question : Re: Boneheaded 3D Trig question Server Time
8 Aug 2024 22:15:49 EDT (-0400)
  Re: Boneheaded 3D Trig question  
From: Josh English
Date: 12 Sep 2000 14:01:36
Message: <39BE6F8B.EDB7426A@spiritone.com>
If I understand you correctly, you have the direction and length of the branch,
and want to place needles on it, randomizing the way they stick out from the
branch?

If you have this, you can place the needles.

Some code to explore. The variable p is the branch, starting at the origin and
ending at the point p.

#declare p = <2,2,0>;
cylinder { <0,0,0> p 0.05 pigment { rgb 1 } }

// You can make p anything you want, see the warning below.

#declare a = vnormalize(vcross(p,x));
#declare b = vnormalize(vcross(p,y));
#declare c = vnormalize(vcross(p,z));

cylinder { <0,0,0> a 0.04 pigment { rgb x } }
cylinder { <0,0,0> b 0.04 pigment { rgb y } }
cylinder { <0,0,0> c 0.04 pigment { rgb z } }

// These three cylinders show possible placements for the needle. As you can
see, they are
// generated by taking the cross product of p and the unit axis vectors.

#declare a = vaxis_rotate(a,p,30);
#declare b = vaxis_rotate(b,p,30);
#declare c = vaxis_rotate(c,p,30);

cylinder { <0,0,0> a 0.03 pigment { rgb x/2 } }
cylinder { <0,0,0> b 0.03 pigment { rgb y/2 } }
cylinder { <0,0,0> c 0.03 pigment { rgb z/2 } }

// These three cylinders show possible rotations of needles. The pitfall
// is if p is along one of the axes, then a,b,or c will be at the origin.
// My code does not check for this, but it should.

Now to plavce the needles, you can try this little snippet of code:
#declare r1 = seed(352);
#declare r2 = seed(3156);
#declare cnt = 0;
#while ( cnt < 150 )
  #declare l1 = p*rand(r1);
  #declare a = vaxis_rotate(a,p,rand(r2)*360);
  cone { l1,0.02, (a + l1), 0 pigment { rgb y } }
  #declare cnt = cnt + 1;
#end

This will create a bunch of needles that of course need to be moved into the
proper position for the branch.

Funny, no trig needed.

Hope all this pontificating helps.

Josh

Rick Gutleber wrote:

> I've got a simple question that's bugged me for years.  The answers got to
> be simple, but I just can't figure it out.
>
> I'm writing a C++ program to programmatically generate a Christmas tree and
> I'm trying to put needles on the branches.  I have the start and end point
> of the branch so I figured I would create the needles as if the branch
> started at the origin and pointed straight up and then just translate and
> rotate the union of the resulting needles so they actually appear on the
> branch in the scene.  This translatation/rotation can occur in my C++ code
> or the generated POV script, whichever is easier.
>
> I've got an arbitary unit vector that reflects the orientation of the branch
> (from VNormalize( ) in POV, or the good old Pythagorean distance function in
> my C++ code), how do I turn that into an equivalent rotate < x, y, z >
> statement so the needles end up on the branch?  I'm sure it's just the right
> combination of atan( ) calls, but the details elude my addled brain.
>
> Thanks for the help!
>
> Rick
> ric### [at] hiscom

--
Josh English -- Lexiphanic Lethomaniac
eng### [at] spiritonecom
The POV-Ray Cyclopedia http://www.spiritone.com/~english/cyclopedia/


Post a reply to this message

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