home
The following code is provided as is with no warranties
express or implied or statutory or whatever, standard disclaimers apply, use
at your own risk, yatta, yatta, yatta. If you find any problems,
please make a comment on
this page.
UniformPointCloud2D generates a cloud of random 2D
points given the number of points to generate (n) and the maximum radius
(radius).
GaussianPointCloud2D generates a cloud of random 2D points given the
number of points to generate (n) and the size of one radial standard
deviation (radius).
PlotPoints2D plots the points generated given the points in matrix
form (m where x = first row, y=second row) and the radius of the plot area
(radius).
PlotAxes2D plots two 2D column vectors when given a 2 x 2 matrix (m)
and the radius of the plot area (radius).
Rot2D rotates points given a rotation angle in degrees (d).
Scale2D scales points given x and y scaling factors (sx, sy).
GaussianPointCloud generates a cloud of random m-dimensional points given the number of dimensions (m), the number of points generate (n) and the size of one radial standard deviation (radius).
UniformPointCloud generates a cloud of random
m-dimensional points given the number of dimensions (m), the number of points to generate (n) and the maximum radius
(radius).
function [m] = UniformPointCloud2D(n,radius)
// create scaling matrix from uniform distribution
// scaled by radius
radii = diag(rand(1, n, 'uniform')*radius);
// vector of random angles in radians [0,2*pi]
theta = rand(1, n)*2*%pi;
// build matrix from scaled cos(theta) and sin(theta)
m = [radii*cos(theta)' radii*sin(theta)']'
endfunction
function [m] = GaussianPointCloud2D(n,radius)
// create scaling matrix from normal distribution
// scaled by radius
radii = diag(rand(1, n, 'normal')*radius);
// vector of random angles in radians [0,2*pi]
theta = rand(1, n)*2*%pi;
// build matrix from scaled cos(theta) and sin(theta)
m = [radii*cos(theta)' radii*sin(theta)']'
endfunction
function PlotPoints2D(m,radius)
// plot (x = first row, y = second row)
plot2d(m(1,:), m(2,:), style=-9, rect=[-radius -radius radius radius])
endfunction
function PlotAxes2D(m,radius)
// plot first 2D column vector
a = [0 m(1,1); 0 m(2,1)];
plot2d4(a(1,:), a(2,:), rect=[-radius -radius radius radius],
style=2);
// plot second 2D column
vector
a = [0 m(1,2); 0 m(2,2)];
plot2d4(a(1,:), a(2,:), rect=[-radius -radius radius radius],
style=2);
endfunction
function [m] = Rot2D(d)
// radians from degrees
r = d * %pi / 180.0
// build 2D rotation matrix
m = [cos(r) sin(r); -sin(r) cos(r)]
endfunction
function [m] = Scale2D(sx, sy)
// build 2D scaling matrix
m = [sx 0; 0 sy]
endfunction
function [m] = UniformPointCloud(m,n,radius)
// random m x n matrix
p = rand(m, n, 'uniform')-0.5;
// scale column vectors to unit length
// (warning: remotely possible divide by zero)
s = inv(diag(sqrt(diag(p'*p))));
// scale column vectors to random length
s = s*diag(rand(1, n, 'uniform')*radius);
// scale
m = p*s;
endfunction
function [m] = GaussianPointCloud(m,n,radius)
// random m x n matrix
p = rand(m, n, 'uniform')-0.5;
// scale column vectors to unit length
// (warning: remotely possible divide by zero)
s = inv(diag(sqrt(diag(p'*p))));
// scale column vectors to random length
s = s*diag(rand(1, n, 'normal')*radius);
// scale
m = p*s;
endfunction