## How to generate random points within 3d pyramid

### Musa Mustapha (view profile)

on 12 Jun 2019
Latest activity Commented on by Jeremiah Abimbola

### Jeremiah Abimbola (view profile)

on 20 Jun 2019
giving the parameters as
E0= (0,0,1); E1= (1,1,0); E2=(-1,1,0); E3=(-1,-1,0); E4=(1,-1,0)

Show 1 older comment
Musa Mustapha

### Musa Mustapha (view profile)

on 13 Jun 2019
yes i need uniform distribution of random points within the pyramid, while the orientation of the shape remains the same.
i tried this
% Creating Pyramid using Random Function
clear;
clc;
E0= [0,0,1];
E1= [1,1,0];
E2= [-1,1,0];
E3= [-1,-1,0];
E4= [1,-1,0];
V1=E4-E1;
V2=E2-E1;
x_y_len=sqrt(V1.^2+V2.^2);
%the height of the pyramid
H=sqrt(sum(abs(E0-(0.5.*x_y_len)).^2));
%the Side of Pyramid
L=(sum(x_y_len)./2)/2;
A=rand(3,1000)
h= H.*A(1,1:end);
H= H* ones(size(h));
L= L* ones(size(h));
x= (L/H).*(H-h);
X= -x/2 + x.*A(2,1:end);
Y= -x/2 + x.*A(3,1:end);
plot3(X,Y,h,'.');
grid on;
the random points doest not seem to be uniform, and i failed to maintain the orientation based on the givig cordinates. thank you
Jan

### Jan (view profile)

on 13 Jun 2019
@Musa: I've used the buttons on top of the edit field to format your comment. This improves the readability.
Does you comment mean, that you need uniformly distributed points? How many?
Is a rejection method sufficient for your case? This means: Determine random point in the cuboid surrounding the pyramid and reject all points outside the pyramid.
Jan

### Jan (view profile)

on 14 Jun 2019
The third time I'm asking this: Would a rejection method satisfy your needs?

on 12 Jun 2019
Edited by Jan

### Jan (view profile)

on 12 Jun 2019

#### 1 Comment

Jeremiah Abimbola

### Jeremiah Abimbola (view profile)

on 20 Jun 2019
I also have this challenge, going through the post from the link you shared was not explanatory me, moreso, that was 2D, mine is in a 3D space.