|
![](/i/fill.gif) |
In article <357BD7B4.6FDE6EC0@no13.net>,
Nathan O'Brien <no1### [at] no13 net> writes:
>Hi all.
>
>I'm looking for a way to distribute spheres randomly on the surface of a
>triangle so that no sphere centre lies outside the confines of the
>triangle. The triangle may be any 3 points. The next bit is that I would
>like to do this using only POV 3.0 code. Any help is greatly
>appreciated.
This snippet of code should do it. Because of a bug in POV, I can't use
the .v property of 2D - vectors so the code is a bit longer then
should be needed. Let me know how this works.
#declare P1x = 0 //First corner of the triangle
#declare P1y = 0
#declare P2x = 1 //Second corner of the triangle
#declare P2y = 0
#declare P3x = 0 //Third corner of the triangle
#declare P3y = 1
#declare E1x = P2x-P1x
#declare E1y = P2y-P1y
#declare E2x = P3x-P2x
#declare E2y = P3y-P2y
#declare E3x = P1x-P3x
#declare E3y = P1y-P3y
#declare n = 0
#while (n < 1) //change 1 to how many spheres you want...
#declare Pxx = 0.25 // add random function for spheres center, x
#declare Pxy = 0.25 // add random function for spheres center, y
#declare ydec1 = -1*E1y*(Pxx-P1x)+ E1x*(Pxy-P1y)
#declare ydec2 = -1*E2y*(Pxx-P2x)+ E2x*(Pxy-P2y)
#declare ydec3 = -1*E3y*(Pxx-P3x)+ E3x*(Pxy-P3y)
#if(((ydec1 >= 0) + (ydec2 >= 0) + (ydec3 >= 0)) = 3)
//sphere definition here
#debug "Within bounds\n"
#else
#debug "Not within bounds\n"
#end
#declare n = n + 1
#end
Best of luck :)
/Michael
Post a reply to this message
|
![](/i/fill.gif) |