POV-Ray : Newsgroups : povray.general : objects NEAR object Server Time
31 Oct 2024 08:19:12 EDT (-0400)
  objects NEAR object (Message 1 to 2 of 2)  
From: Andrej
Subject: objects NEAR object
Date: 21 Nov 2005 09:03:43
Message: <4381d3bf$1@news.povray.org>
How to place object near another object?

For example: I would like to place spheres, with random position and size, 
near central irregular shaped object.

So, many objects should just touch the central object.


Post a reply to this message

From: Jim Charter
Subject: Re: objects NEAR object
Date: 21 Nov 2005 10:31:12
Message: <4381e840$1@news.povray.org>
Andrej wrote:

 > How to place object near another object?
 >
 > For example: I would like to place spheres, with random position and 
size, near central irregular shaped object.
 >
 > So, many objects should just touch the central object.
 >
I think you can do this, in
pseudocode:

place your irregular object at the origin

   #include "shapes.inc"
   Center_Object ( IrregularObject, x+y+z )

get your random sphere position

   Position = <random X, random Y, random Z>

use the trace function to test where the location is relative to your 
object.  use the negative of the position as the direction
   set Normal to <0,0,0>
   then
   SurfacePoint =
   trace ( IrregularObject, Position, <0,0,0>-Position, Normal )

   vlength(Normal) >? 0
   if no the location is inside the object, try a new Location

   if yes

   vlength(Position - SurfacePoint) >? Radius (of the sphere you want to 
place)

   if yes, place the sphere at the Location
   if no, place the sphere at
   SurfacePoint + Normal*Radius  (so it is just touching the surface)

   you may now want to make further tests to make sure the sphere does 
not intersect the surface in other directions from the sphere's center


Post a reply to this message

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