POV-Ray : Newsgroups : povray.general : What Function to use Server Time
29 Nov 2024 03:26:57 EST (-0500)
  What Function to use (Message 1 to 10 of 10)  
From: POVMAN
Subject: What Function to use
Date: 18 Apr 2006 08:19:53
Message: <4444d969@news.povray.org>
I have an irregular csg object and I want to have objects ( cylinders ) 
stand perpendicular to the surface.  Imagine the csg as being a box, sphere 
and cylinder union.

I'm familiar with using "trace" to place objects (cylinders ) on a surface, 
but I want these objects to stick out from the csg object.

I've set up a model where I can use "trace" to identify where the object is 
to be placed on the surface of the csg but the vector I need to rotate the 
object ( cylinder ) through is beyond me.

Tips Hints anybody?

-- 
#####-----#####-----#####
POV Tips and Hints at ...
http://povman.blogspot.com/


Post a reply to this message

From: Jim Charter
Subject: Re: What Function to use
Date: 18 Apr 2006 08:52:39
Message: <4444e117$1@news.povray.org>
POVMAN wrote:
> I have an irregular csg object and I want to have objects ( cylinders ) 
> stand perpendicular to the surface.  Imagine the csg as being a box, sphere 
> and cylinder union.
> 
> I'm familiar with using "trace" to place objects (cylinders ) on a surface, 
> but I want these objects to stick out from the csg object.
> 
> I've set up a model where I can use "trace" to identify where the object is 
> to be placed on the surface of the csg but the vector I need to rotate the 
> object ( cylinder ) through is beyond me.
> 
> Tips Hints anybody?
> 
trace() returns the normal as the forth parameter


you orient your cylinder using Reorient_Trans()

ie
if you did:
#local Position =
trace ( MyObject, Start, Direction, Normal )


then if your cylinder is in the y axis

then:
cylinder { y*0, y*1, .2
	Reorient_Trans(y, Normal)
	translate Position
}


Post a reply to this message

From: Kyle
Subject: Re: What Function to use
Date: 18 Apr 2006 09:11:35
Message: <09p942hq3okvvp67bafdhf7s91u4ujo9ei@4ax.com>
Here's a snipped of code from a test scene where I did this with cylinders...


#version 3.6;

//+w800 +h800 +a0.0
//+w800 +h800 +q3

#include "stdinc.inc"

global_settings {
  assumed_gamma 1
  max_trace_level 15
}

background { White * 0.75 } 

// primary light ( front, right )
light_source {
  vrotate (<0, 500, -500>, <0, -60, 0>), White
}

// shadow light ( front, left )
light_source {
  vrotate (<0, 500, -500>, <0, 60, 0>), White * 0.25
}

// back light ( rear )
light_source {
  vrotate (<0, 500, -500>, <0, 180, 0>), White * 0.50
}

camera {
  right x*image_width/image_height
  location <1.5, 1.5, -4>
  look_at <0, 0, 0>
}

#declare Model =
  union {
    sphere { 0.933*y, 1/2 }
    cone { -y/2, 1/2, y/2, 1/4 }
    box { -1/2, 1/2 translate -y }
  }
  
#declare ModelMaterial = material { texture { pigment { agate } } }
  
#declare M1 = object { Model rotate z*45 material { ModelMaterial } }

#declare spike = cylinder { 0, y, 0.0075 pigment { rgb <1, 0, 0> } }

// draw the spikes 
#declare S1 = seed(1);
#declare norm = <0, 0, 0>; 
#declare loop = 10000;
#declare BboxMin = min_extent(M1);
#declare BboxMax = max_extent(M1);
#while (loop > 0)
  #declare start = <rand(S1) * (BboxMax.x - BboxMin.x) + BboxMin.x, BboxMax.y + 1,
rand(S1) *
(BboxMax.z - BboxMin.z) + BboxMin.z>; // start above the surface at a random x, z
position
  #declare loc = trace(M1, start, <0, BboxMin.y - 1, 0>, norm); // trace to the
surface
  #if (vlength(norm) != 0)  // do we have a hit?
//    #if ( VAngleD(norm, y) < 10 )  // only place on relatively flat surfaces 
      cylinder {
        loc, loc + norm/20, 0.0075
        pigment { rgb <1, 0, 0> }
      }
//    #end
  #end
  #declare loop = loop - 1;
#end

// draw the object
object { M1 }



Kyle


Post a reply to this message

From: POVMAN
Subject: Re: What Function to use
Date: 18 Apr 2006 09:29:07
Message: <4444e9a3@news.povray.org>
I'll try that tonight, thanks.

-- 
#####-----#####-----#####
POV Tips and Hints at ...
http://povman.blogspot.com/


Post a reply to this message

From: POVMAN
Subject: Re: What Function to use
Date: 18 Apr 2006 09:29:57
Message: <4444e9d5$1@news.povray.org>
Shall try it tonight, thanks.

-- 
#####-----#####-----#####
POV Tips and Hints at ...


Post a reply to this message

From: Jim Charter
Subject: Re: What Function to use
Date: 18 Apr 2006 10:11:09
Message: <4444f37d@news.povray.org>
POVMAN wrote:
> I'll try that tonight, thanks.
> 
Welcome.  You should take a read through
the transforms.inc file.  There is some
great stuff in there.


Post a reply to this message

From: POVMAN
Subject: Re: What Function to use
Date: 18 Apr 2006 11:09:59
Message: <44450147@news.povray.org>
> Welcome.  You should take a read through
> the transforms.inc file.  There is some
> great stuff in there.

I dont think I've ever been in there!  Sounds scary, but I'll embolded my 
spirit and bravely read on...

-- 
#####-----#####-----#####
POV Tips and Hints at ...
http://povman.blogspot.com/


Post a reply to this message

From: Jim Charter
Subject: Re: What Function to use
Date: 18 Apr 2006 11:17:44
Message: <44450318$1@news.povray.org>
POVMAN wrote:
>>Welcome.  You should take a read through
>>the transforms.inc file.  There is some
>>great stuff in there.
> 
> 
> I dont think I've ever been in there!  Sounds scary, but I'll embolded my 
> spirit and bravely read on...
> 
Keep the docs handy.


Post a reply to this message

From: Thomas de Groot
Subject: Re: What Function to use
Date: 19 Apr 2006 03:43:02
Message: <4445ea06@news.povray.org>
"POVMAN" <s### [at] acom> schreef in bericht news:4444d969@news.povray.org...
> I have an irregular csg object and I want to have objects ( cylinders )
> stand perpendicular to the surface.  Imagine the csg as being a box,
sphere
> and cylinder union.
>

You may also want to try this little scene :-)

Thomas

//==========================================================================
==========
// Persistence of Vision Ray Tracer Scene Description File
// File: ?.pov
// Vers: 3.5
// Desc: Shows the trace() function and the Reorient_Trans() function in
action
// Date: may 2004
// Auth: ?
//

#version 3.5;

#include "colors.inc"
#include "rand.inc"
#include "transforms.inc"

global_settings {
  assumed_gamma 1.0
}

// ----------------------------------------

camera {
  location  <0.0, 3, -4.0>
  direction 1.5*z
  right     x*image_width/image_height
  look_at   <0.0, 0.0,  0.0>
}

sky_sphere {
  pigment {
    gradient y
    color_map {
      [0.0 rgb <0.6,0.7,1.0>]
      [0.7 rgb <0.0,0.1,0.8>]
    }
  }
}

light_source {
  <0, 0, 0>            // light's position (translated below)
  color rgb <1, 1, 1>  // light's color
  translate <-30, 30, -30>
}

// ----------------------------------------

plane {
  y, -1
  pigment { color rgb <0.7,0.5,0.3> }
}

#declare MySurface =
// uses image color index as height, extends along X-Z axes
// from <0 0 0> to <1 1 1>
height_field {
  png "plasma3.png"
  texture {
    pigment {
      image_map { png "plasma3.png" map_type 0 interpolate 2 once }
      rotate x*90 // lay X-Y image map down onto X-Z height field plane
    }
  }
  translate <-0.5,0,-0.5>
  scale <5, 1, 5>
}
object {MySurface}

//====================================
#declare CylRed =
cylinder {
  0*y,  0.25*y,  0.01
  texture {pigment { color rgb <1, 0, 0> }}
}
#declare CylGreen =
cylinder {
  0*y,  0.25*y,  0.01
  texture {pigment { color rgb <0, 1, 0> }}
}
#declare CylBlue =
cylinder {
  0*y,  0.25*y,  0.01
  texture {pigment { color rgb <0, 0, 1> }}
}
#declare Seed1=seed(29);
#declare Seed2=seed(4321);
#declare CylCol=0;
// -------- Placing the Objects -------------

#declare Spacing=0.1;
#declare Cnt=0;


#declare PosX = -10;

#while (PosX < 10)
  #declare PosZ = -10;

  #while (PosZ < 10)
    // trace function
    #declare Norm = <0, 0, 0>;
    //#declare Start = <PosX+Spacing, 10, PosZ+Spacing>;
    #declare Start = <PosX+(rand(Seed1)-0.5)*Spacing, 1.0,
PosZ+(rand(Seed2)-0.5)*Spacing>;
    #declare Pos = trace (
                  MySurface,     // object to test
                  Start,           // starting point
                  -y,              // direction
                  Norm );          // normal

    #if (Norm.x != 0 | Norm.y != 0 | Norm.z != 0)   // if intersection is
found, normal differs from 0

      #if ((vdot(Norm, y) > 0.95) & (Pos.y < 500))  // criteria for placing
objects: steep (0.1) to flat (0.95); and below certain level
        #declare CylCol= RRand(0,1,Seed2);
        //#warning concat("Value is ", str(CylCol,3,1), "\n")

        #if (CylCol<0.66)
            #if (CylCol<0.33)
              #declare CylObj=CylRed;
            #else
              #declare CylObj=CylGreen;
            #end
        #else
          #declare CylObj=CylBlue;
        #end // end of color selection

        object {
          CylObj
          Reorient_Trans(y, Norm)
          translate Pos
        }
        #declare Cnt = Cnt+1;
      #end // end of steep/heigth test
    #end // end of Norm intersection

    #declare PosZ = PosZ+Spacing;

  #end // end of while PosZ

  #declare PosX = PosX+Spacing;
#end // end of while PosX

//==========================================================================
==========


Post a reply to this message

From: POVMAN
Subject: Re: What Function to use
Date: 19 Apr 2006 04:22:39
Message: <4445f34f$1@news.povray.org>
> Keep the docs handy.

Tried it, and it worked!  Huzzar!

I had assumed that the "normal" returned by trace would relate to a normal 
in he texture, but at this stage the texture on the csg had no normal.  I 
guess I made a wrong assumption.

Thanks to everyone!

-- 
#####-----#####-----#####
POV Tips and Hints at ...
http://povman.blogspot.com/


Post a reply to this message

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