lundi 24 juin 2019

How generate random points within cylinder

how to generate uniformly distributed points within cylinders giving these parameters, Center point denoted as C, C1 is bottom and C2 is Top and R is Radius. C1=[5.697592e-01, 3.159923e-01, 1.037074e+00];C2=[4.211637e-01, 5.624242e-01, 7.937364e-02];R=5.000000e-01;

%the cordinate 
        C1=[5.697592e-01, 3.159923e-01, 1.037074e+00];
        C2=[4.211637e-01, 5.624242e-01, 7.937364e-02];
        N=600;
        CylinderX = rand(1,N);
        CylinderY = rand(1,N);
        CylinderZ = rand(1,N);
        CylinderHeight = norm(C1 - C2);

        for i = 1 : N
            A = [0 0 0 1];
            x = rand;
            y = rand;
            Px = sqrt(x)*R*cos(2*pi*y);
            Py = sqrt(x)*R*sin(2*pi*y);
            Pz = CylinderHeight * rand;
            %I need the coordinate transformation  logic here

            CylinderX(i) = A(1);
            CylinderY(i) = A(2);
            CylinderZ(i) = A(3);
        end
        plot3(CylinderX , CylinderY , CylinderZ ,'G.');hold on;




Aucun commentaire:

Enregistrer un commentaire