Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1367631 Posts in 64148 Topics- by 56064 Members - Latest Member: Shape

October 13, 2019, 10:59:54 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Uniform random point on a 3D triangle
Pages: [1]
Print
Author Topic: Uniform random point on a 3D triangle  (Read 213 times)
NovaSilisko
Level 2
**


Real life space alien (not fake)


View Profile
« on: April 18, 2019, 11:09:42 PM »

So, I'll try and boil this down to be as simple as possible. I am trying to place random points upon a uniform set of triangles in 3D space. Specifically on the triangles; per-vertex isn't good enough for what I need.

So far, my attempts have resulted in a considerable bias toward the center of the triangle, and I am wondering what other methods there are that might work better.

This is the best I've gotten so far. The triangle's points are A, B, and C, the random values (0 to 1) are R1, R2, and R3.

P = (R1 * A + R2 * B + R3 * C) / (R1 + R2 + R3)

Which looks like this:



So... yeah. I've been sniffing around but I haven't found anything thus far that does what I need Shrug

...It's also entirely possible I've screwed up some of my randomization, so I need to look into that angle soon as well. That would be just my luck. Facepalm <- tests complete, it's definitely the scattering algorithm, not the randomization
« Last Edit: April 18, 2019, 11:27:21 PM by NovaSilisko » Logged

BorisTheBrave
Level 10
*****


View Profile WWW
« Reply #1 on: April 19, 2019, 12:06:15 AM »

Here's my code for doing it:

https://github.com/BorisTheBrave/blue-noise-particles/blob/master/blue_noise_particles.py#L190

Edit: This way looks neat, too: https://math.stackexchange.com/questions/18686/uniform-random-point-in-triangle
« Last Edit: April 19, 2019, 12:16:23 AM by BorisTheBrave » Logged
NovaSilisko
Level 2
**


Real life space alien (not fake)


View Profile
« Reply #2 on: April 19, 2019, 12:16:52 AM »

Oh man, thanks. Barycentric coordinates, that was exactly the seed I needed to find this: https://adamswaab.wordpress.com/2009/12/11/random-point-in-a-triangle-barycentric-coordinates/

Which looks like:



Now it's perfect!
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic