-2

Quick question, if I've a formula for a mathematical 3D volume, is it possible to calculate a random cartesian coordinate (XYZ) point within the volume?

And if possible, could the one to answer please provide what kind of formula I need to use? Currently I'm looking at signed distance functions but as far as I can see you can only calculate for a given cartesian coordinate if its in the volume.

Lolslayer
  • 63
  • 8
  • 1
    What do you mean by "quick question" ? –  May 25 '18 at 10:03
  • What kind of shape? It is possible for sphere and some other figures. In general case you can consider exclusion approach (check whether point is inside) – MBo May 25 '18 at 10:05
  • Well, the problem is that if I will use this system, I might need to create around 100 points within the volume in a single frame. So if I need to use the exclusion approach it will give a noticable performance dip. – Lolslayer May 25 '18 at 10:30
  • A noticeable performance dip compared to what? – Beta May 26 '18 at 01:47

1 Answers1

0

An easy strategy is to use a bounding volume (box/sphere or ad-hoc) and use the rejection technique: draw a point at random in the bounding volume, until it falls inside the true volume. If the volume is reasonably compact, and the bounding volume is tight, you will need less than two drawings on average.

To get drawings only inside, you need use a parametric representation of the volume, which depends on the particular implicit equation, and the expression of the ranges of the parameters. But obtaining uniform distributions can be challenging.

For instance, points inside a torus are obtained by

X = (R + t cos u) cos v
Y = (R + t cos u) sin v
Z = t sin u

where u and v are random in 0..2π and t random in 0..r.

  • Thanks, I'll give this a proper look, it might be a huge step in the right direction. I only hope to be able to find a list of different shapes (currently looking for a volumetric spiral for example) – Lolslayer May 25 '18 at 10:41