|
|
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
|
|
|
|
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
|
|