POV-Ray : Newsgroups : povray.general : Boneheaded 3D Trig question Server Time
9 Aug 2024 01:22:08 EDT (-0400)
  Boneheaded 3D Trig question (Message 1 to 5 of 5)  
From: Rick Gutleber
Subject: Boneheaded 3D Trig question
Date: 12 Sep 2000 12:24:38
Message: <39be58c6@news.povray.org>
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


Post a reply to this message

From: Josh English
Subject: Re: Boneheaded 3D Trig question
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

From: John VanSickle
Subject: Re: Boneheaded 3D Trig question
Date: 12 Sep 2000 22:28:11
Message: <39BEE705.2B268552@erols.com>
Rick Gutleber wrote:
> 
I have a macro that will take an object pointing in any direction and
point it in any other direction.  Surf over to

  users.erols.com/vansickl/macs.htm

I also have a page that explains how to use the matrix transform.  This
page can be found at:

  users.erols.com/vansickl/matrix.htm

Hope this helps,
John
-- 
ICQ: 46085459


Post a reply to this message

From: Jennifer Zycha Gutleber
Subject: Re: Boneheaded 3D Trig question
Date: 12 Sep 2000 22:33:21
Message: <39bee771@news.povray.org>
Wow, John.  Thanks a lot.  The macros on your page look thoroughly useful!

"John VanSickle" <van### [at] erolscom> wrote in message
news:39BEE705.2B268552@erols.com...
> Rick Gutleber wrote:
> >
> I have a macro that will take an object pointing in any direction and
> point it in any other direction.  Surf over to
>
>   users.erols.com/vansickl/macs.htm
>
> I also have a page that explains how to use the matrix transform.  This
> page can be found at:
>
>   users.erols.com/vansickl/matrix.htm
>
> Hope this helps,
> John
> --
> ICQ: 46085459


Post a reply to this message

From: Tom Melly
Subject: Re: Boneheaded 3D Trig question
Date: 13 Sep 2000 06:19:43
Message: <39bf54bf$1@news.povray.org>
"John VanSickle" <van### [at] erolscom> wrote in message
news:39BEE705.2B268552@erols.com...
> Rick Gutleber wrote:
>
> I also have a page that explains how to use the matrix transform.  This
> page can be found at:
>
>   users.erols.com/vansickl/matrix.htm

and a very good explanation it is too - unfortunately, like quantum
mechanics, the moment I stop reading, I stop understanding. ;)


Post a reply to this message

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