POV-Ray : Newsgroups : povray.newusers : Add leaf on my tree Server Time
26 Nov 2024 03:28:22 EST (-0500)
  Add leaf on my tree (Message 1 to 4 of 4)  
From: sap
Subject: Add leaf on my tree
Date: 23 Oct 2004 02:46:48
Message: <4179fe58@news.povray.org>
Hello;

I have made a tree macro and would like to add leaf on my tree. You can see 
the result in the p.b.i.

So how to translate some object along all cylinder and orient them like an 
umbrella ?


#include "colors.inc"
#include "math.inc"
#include "rand.inc"

camera {

  location  <12, 2, -30>
  direction 1.5*z
  right     x*image_width/image_height
  look_at   <10,1,0>
}

light_source{< 1000, 500,-1000> color White}

// p0: Origin position of the lower cylinder
// p1: Upper position of the lower cylinder
// L: recursion level (WARNING: after 5 or 6 a big pc needed)
// d: Rayon of the lower cylinder

#macro arbre(p0,p1,L,d)
 #local nd=d-(d*0.5);

 cylinder{p0,p1,nd}
 sphere{p1,nd}

 #local ang=VAngle(p0,p1);
 #local Np0=vrotate(p1,ang);
 #local Np1=Np0+< rand(Ra)/3,rand(Ra)/2, rand(Ra)/3>*3;
 #local Np2=Np0+<-rand(Ra)/3,rand(Ra)/2,-rand(Ra)/3>*3;
 #local Np3=Np0+< rand(Ra)/3,rand(Ra)/2,-rand(Ra)/3>*3;
 #local Np4=Np0+<-rand(Ra)/3,rand(Ra)/2, rand(Ra)/3>*3;

 cylinder{Np0,Np1,nd/2}
 cylinder{Np0,Np2,nd/2}
 cylinder{Np0,Np3,nd/2}
 cylinder{Np0,Np4,nd/2}

 sphere{Np1,nd/2}
 sphere{Np2,nd/2}
 sphere{Np3,nd/2}
 sphere{Np4,nd/2}


 #if(L>0)
 #local NL=L-1;

 arbre(Np0,Np1,NL,nd)
 arbre(Np0,Np2,NL,nd)
 arbre(Np0,Np3,NL,nd)
 arbre(Np0,Np4,NL,nd)

 #end
#end
#declare r=seed(0);
#declare a=0;
#while(a<4)
#declare b=0;
#while (b<4)
#declare Ra=seed(RRand(100,500,r));
union{
arbre(<0,0,0>,<RRand(-0.2,0.2,r),RRand(0.3,1.5,r),RRand(-0.2,0.2,r)>,3,0.3)
translate<RRand(3,8,int(Ra))*a,0,RRand(6,8,int(Ra))*b>
}
#declare b=b+1;
#end
#declare a=a+1;
#end


plane{y,0 pigment{rgb<0.5,0.9,0.4>}}

sky_sphere {
  pigment {
    gradient y
    color_map { [0.0 color rgb <0.7,0.7,1.0>] [1.0 color blue 0.5] }
  }
}


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Add leaf on my tree
Date: 26 Oct 2004 20:23:00
Message: <417eea64$1@news.povray.org>
sap wrote:
> Hello;
> 
> I have made a tree macro and would like to add leaf on my tree. You can see 
> the result in the p.b.i.
...
>  #local ang=VAngle(p0,p1);
>  #local Np0=vrotate(p1,ang);
...

I have not looked at all of your code, but I spotted this:

In the code above you calculate an angle and then you rotate
a vector around all the x, y and z axes.

Is this intentionally ?

Note that:

   vrotate(p1, ang)

evaluates to:

   vrotate(p1, <ang, ang, ang>)

or equivalently:

   vrotate(p1, ang*x + ang*y + ang*z)

I.e. the p1 vector is first rotated around the x-axis, then
around the y-axis and finally around the z-axis.

Also: vrotate() expects its 2nd argument to be a vector with
components in degrees, while the angle returned from the
VAngle() macro is in radians.

(The VAngleD() macro will return an angle in degrees.)


You may want to read these sections once more:

http://www.povray.org/documentation/view/3.6.1/459/
---> 2.7.9.2 Vector functions and macros

http://www.povray.org/documentation/view/3.6.1/229/
---> 2.2.1.4.5 Functions


Also note that there is a built in function; vaxis_rotate(),
which will rotate a vector around an arbitrary vector.

-- 
Tor Olav
http://subcube.net
http://subcube.com


Post a reply to this message

From: sap
Subject: Re: Add leaf on my tree
Date: 27 Oct 2004 14:46:35
Message: <417fed0b@news.povray.org>
Thanks for your answer Tor, i use vrotate ans Vangle to attache my cylinder 
at they extremity. When i use VDangle, cylinders are not attached. Then i 
dont rotate my cylinder but i take the point Np0 and add it a random vector 
in the +y direction to make my tree grow.

Its my firt macro in that way and i am now blocked because i cant translate 
and rotate an object along and around cylinders.

My way to place cylinders is certenly the most rational way but it's the 
onely one i found.


message de news: 417eea64$1@news.povray.org...
> sap wrote:
>> Hello;
>>
>> I have made a tree macro and would like to add leaf on my tree. You can 
>> see the result in the p.b.i.
> ...
>>  #local ang=VAngle(p0,p1);
>>  #local Np0=vrotate(p1,ang);
> ...
>
> I have not looked at all of your code, but I spotted this:
>
> In the code above you calculate an angle and then you rotate
> a vector around all the x, y and z axes.
>
> Is this intentionally ?
>
> Note that:
>
>   vrotate(p1, ang)
>
> evaluates to:
>
>   vrotate(p1, <ang, ang, ang>)
>
> or equivalently:
>
>   vrotate(p1, ang*x + ang*y + ang*z)
>
> I.e. the p1 vector is first rotated around the x-axis, then
> around the y-axis and finally around the z-axis.
>
> Also: vrotate() expects its 2nd argument to be a vector with
> components in degrees, while the angle returned from the
> VAngle() macro is in radians.
>
> (The VAngleD() macro will return an angle in degrees.)
>
>
> You may want to read these sections once more:
>
> http://www.povray.org/documentation/view/3.6.1/459/
> ---> 2.7.9.2 Vector functions and macros
>
> http://www.povray.org/documentation/view/3.6.1/229/
> ---> 2.2.1.4.5 Functions
>
>
> Also note that there is a built in function; vaxis_rotate(),
> which will rotate a vector around an arbitrary vector.
>
> -- 
> Tor Olav
> http://subcube.net
> http://subcube.com


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Add leaf on my tree
Date: 28 Oct 2004 10:05:18
Message: <4180fc9e$1@news.povray.org>
sap wrote:
> Thanks for your answer Tor, i use vrotate ans Vangle to attache my cylinder 
> at they extremity. When i use VDangle, cylinders are not attached.

They are not really attached when using Vangle() either.

Just look closely at the first branch. (Btw.: I suggest
that you add at least one texture to your trees first.)

The "misuse" of VAngle() just results in smaller angles
when radians are interpreted as degrees. This causes
the disattachments(?) to be less visible.

To see this, just try to increase the rotation angles
by scaling them a little:

   #local ang = VAngle(p0, p1)*4;

Also try:

   #local ang = VAngle(p0, p1)*0;

- which will attach them to each other again.

This means that the rotation of p1 does not make much
sense the way it is done now.


> Then i 
> dont rotate my cylinder but i take the point Np0 and add it a random vector 
> in the +y direction to make my tree grow.
> 
> Its my firt macro in that way and i am now blocked because i cant translate 
> and rotate an object along and around cylinders.
> 
> My way to place cylinders is certenly the most rational way but it's the 
> onely one i found.

But it seems that you misunderstand something...

I'm not sure what you want to achieve with the rotation
vector above, so I'm not able to guess what your mis-
conseption might be...

Could it be that rotation of objects is not performed
"locally", but "globally" ?

(I.e. not about the axes "local" to objects but about
"global" axes through origo <0, 0, 0>)

-- 
Tor Olav
http://subcube.net
http://subcube.com


Post a reply to this message

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