[Closed] How to get an XYZ coordinate on a surface randomly
Are there any functions for calculating a random point on a surface? Or for calculating a random point in the area of the projection to the horizontal plane of a surface? If there are not,another thing I want to know is how to get the width ,length and the height of an object.Thanks for reading,thanks for answering.Excuse for my rough english.
Get the surface length then surface width, use Random function to get a random point on length and width then do a ray test using those co-ordinates to find the Z_point on the surface.
Look in the help file for “how to drop objects to a surface”
And as I’ve been modelling all day and need to stretch my mind a little…
--set our surface object as the Plane
theobj = $Plane01
--get the ranges of the object
a = theobj.min
b = theobj.max
--get random points between min and max for x and y
x_rnd = random a.x b.x
y_rnd = random a.y b.y
--use the intersect ray method to find the z point for the object at that point.
testRay = ray [x_rnd, y_rnd, 100000] [0,0,-1]
nodeMaxZ = theobj.max.z
testRay.pos.z = nodeMaxZ + 0.0001 * abs nodeMaxZ
b_pos = intersectRay theobj testRay
--if our new location is good create a box
--create a box at our new position
If b_pos != undefined then Box pos:b_pos.pos
If you want to distribute a whole bunch of points over an object’s surface, your best option is probably Particle Flow. It’s distribution algorithm is pretty fast and also more or less uniform (unlike the legacy parray system).
So basically the script would create a simple pflow system containing a Position Object. Then simply read in the points and remove the pflow system again.
This can also be done with maxscript only, but this is going to be a lot slower (especially for dense meshes). In pseudo code, I guess the script would look like this:
collect face areas for entire mesh
for loop -> number of points to be created
(
pick a face index using a weighted random function (face areas determine weight)
create random barycentric coordinates
convert these coords to world position inside triangle
)
The first part (collecting face areas) is probably going to be the slowest part, generating weighted random numbers can be pretty fast.
Hope this helps,
Martijn