(original) (raw)

function p = triangle_reference_sample ( n ) %*****************************************************************************80 % %% triangle_reference_sample() returns random points in the reference triangle. % % Licensing: % % This code is distributed under the MIT license. % % Modified: % % 29 July 2023 % % Author: % % John Burkardt % % Input: % % integer N, the number of points to generate. % % Output: % % real P(N,2), random points in the triangle. % alpha = rand ( n, 1 ); % % Interpret R as a percentage of the triangle's area. % % Imagine a line L, parallel to side 1, so that the area between % vertex 1 and line L is R percent of the full triangle's area. % % The line L will intersect sides 2 and 3 at a fraction % ALPHA = SQRT ( R ) of the distance from vertex 1 to vertices 2 and 3. % alpha = sqrt ( alpha ); beta = rand ( n, 1 ); p = zeros ( n, 2 ); p(1:n,1) = ( 1.0 - beta(1:n) ) .* alpha(1:n); p(1:n,2) = beta(1:n) .* alpha(1:n); return end