POV-Ray : Newsgroups : povray.binaries.images : Moving objects next to each other : Moving objects next to each other Server Time
23 Feb 2025 03:44:49 EST (-0500)
  Moving objects next to each other  
From: Chris R
Date: 20 Feb 2025 10:10:00
Message: <web.67b744fcda38f6a0cd9f14085cc1b6e@news.povray.org>
In the Chess game scene I posted earlier, there are clusters of chess pieces
that have been removed from the board already.  I created some macros to
randomly place them in a clump such that they don't overlap.

I have now generalized those macros and made them more robust in the face
objects that may have concave areas and then replaced the code in my chess scene
with those macros.

As usual, the code can be found in my GitHub repository:
https://github.com/carath63/povlibrary

The new library is in library/libcollide.inc and the sample scene that generated
the image below is in Examples/collision_test.pov.

The basic idea is that you start a cluster with a single object, and then slide
additional objects towards the cluster until the edge of the cluster abuts the
edge of the object.

To do this, I created a representation of the objects to be slid into the
cluster as a matrix of radius values in the XZ plane from the center of the
object, and at various Y offsets from the center.

There is then code that takes this radius mapping, a point on the Y=0 plane, a
minimum gap between the piece and the cluster, a tolerance, and the cluster
object.  For each Y offset of the object, it shoots a ray from the starting XZ
plane point at the given Y offset to the center XZ point of the cluster at the
same height.  It then finds the best offset of the object to the cluster such
that the radius doesn't overlap the cluster at any of the heights based on the
radius of the object at the angle where it approaches the cluster.

Since the cluster may have concave areas, there is additional code that then
shoots rays from the proposed resting point of the object in a 360 degree arc
and compares the distances to any part of the cluster it hits with the radius of
the object in that same arc, again across all heights.

You can set the radial and vertical resolutions based on how complex the objects
are.  For example if you had a simple cylinder with fixed radius, the radial
resolution doesn't matter because its the same in all directions, and the height
doesn't matter.

In the sample scene I have trees with various trunk and cone heights and radius,
rocks with various oblong radii, and bushes that are moon-shaped objects to
force some concave objects.  You can see how rocks are able to slide under the
branches of trees and stop at the trunk, and bushes can curve around trunks of
trees and rocks.

This may not be new, and it doesn't handle cases where you might want a 3D clump
and shoot objects from any point in 3D space, rather than in an XZ plane
orientation.  That's for another day.

Enjoy!

-- Chris R


Post a reply to this message


Attachments:
Download 'collision_test.png' (58 KB)

Preview of image 'collision_test.png'
collision_test.png


 

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