All Topics
All Topics
Technology
Technology
Design
Design
Programming
Programming
Science
Science
News
News
Gaming
Gaming
Entertainment
Entertainment
Business
Business
Finance
Finance
Sports
Sports
Health
Health
Food
Food
Travel
Travel
Art
Art
Music
Music
Books
Books
Education
Education
Politics
Politics
Personal
Personal
No algorithm. No AI slop. No ads. Just RSS. Pro-human. Indie writers. Real journalism. Open web. Chronological. Hand toasted.

Methods for Generating Random Points Inside a Triangle

By

ibobev

8mo ago· 2 min readen

Summary

This article explains two methods for generating random points inside a triangle: barycentric coordinates (which produces non-uniform distribution) and an accept-reject method (which produces uniform distribution). The barycentric method involves generating three random numbers, normalizing them to sum to 1, and using them as weights for the triangle vertices. The accept-reject method involves drawing a bounding rectangle around the triangle, generating random points within it, and discarding those that fall outside the triangle.

Key quotes

· 3 pulled
Generate random numbers α, β, and γ from the interval [0, 1]. Normalize the points to have sum 1 by dividing each by their sum.
Return αA + βB + γC. This generates points inside the triangle, but not uniformly.
Draw a rectangle around the triangle, generate points in the square, and throw them away if they land outside the triangle.
Snippet from the RSS feed
How to uniformly sample points from a triangle. One method that seems plausible but isn't uniform, and a clever method that is uniform.

You might also wanna read