Random
Base.rand
— Methodrand([rng], G, crs=Cartesian3D)
Generate a random geometry of type G
with CRS crs
, optionally passing a random number generator rng
.
Examples
rand(Point)
rand(Triangle)
rand(Point, crs=Cartesian2D)
rand(Triangle, crs=LatLon)
Base.rand
— Methodrand([rng], G, n, crs=Cartesian3D)
Generate a vector of n
random geometries of type G
with CRS crs
, optionally passing a random number generator rng
.
Examples
rand(Point, 10)
rand(Triangle, 10)
rand(Point, 10, crs=Cartesian2D)
rand(Triangle, 10, crs=LatLon)
Random geometries can be generated using the rand
function:
rand(Point)
Point with Cartesian{NoDatum} coordinates
├─ x: 0.6156326255217701 m
├─ y: 0.7200970045158124 m
└─ z: 0.7544186956845172 m
By default, the rand
function uses the Cartesian3D
CRS (Coordinate Reference System). It's possible to change the CRS using the crs
keyword argument:
rand(Point, crs=Cartesian2D)
Point with Cartesian{NoDatum} coordinates
├─ x: 0.7771093429706265 m
└─ y: 0.44881185035978033 m
A vector of geometries can be generated by passing the number of elements as the second argument:
rand(Segment, 5, crs=LatLon)
5-element Vector{Segment{🌐, CoordRefSystems.GeodeticLatLon{CoordRefSystems.WGS84Latest, Unitful.Quantity{Float64, NoDims, Unitful.FreeUnits{(°,), NoDims, nothing}}}}}:
Segment((lat: 46.9536°, lon: 163.724°), (lat: 18.8556°, lon: 75.8339°))
Segment((lat: 84.216°, lon: 144.823°), (lat: 87.1446°, lon: -128.433°))
Segment((lat: 31.0229°, lon: 145.702°), (lat: -87.0076°, lon: -162.32°))
Segment((lat: -56.2711°, lon: 54.0932°), (lat: 68.7513°, lon: 156.283°))
Segment((lat: 19.7866°, lon: -126.734°), (lat: -9.2372°, lon: -13.8257°))
For reproducibility purposes, a random number generator can be passed as the first argument in both methods:
rng = MersenneTwister(123)
rand(rng, Triangle)
Triangle
├─ Point(x: 0.37453777969575874 m, y: 0.8735343642013971 m, z: 0.29012488666251546 m)
├─ Point(x: 0.3368408330598551 m, y: 0.6622706870716968 m, z: 0.7763361853035142 m)
└─ Point(x: 0.5034055294549571 m, y: 0.7501773674527126 m, z: 0.9103373216185842 m)
rand(rng, Triangle, 5)
5-element Vector{Triangle{𝔼{3}, CoordRefSystems.Cartesian3D{CoordRefSystems.NoDatum, Unitful.Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}}}}:
Triangle((x: 0.464067 m, y: 0.695031 m, z: 0.398404 m), (x: 0.381605 m, y: 0.816696 m, z: 0.904999 m), (x: 0.32071 m, y: 0.606174 m, z: 0.610766 m))
Triangle((x: 0.0877252 m, y: 0.92557 m, z: 0.597156 m), (x: 0.74611 m, y: 0.891596 m, z: 0.0626721 m), (x: 0.070898 m, y: 0.0485191 m, z: 0.652385 m))
Triangle((x: 0.580893 m, y: 0.339631 m, z: 0.644323 m), (x: 0.580265 m, y: 0.226512 m, z: 0.289129 m), (x: 0.630659 m, y: 0.47637 m, z: 0.282868 m))
Triangle((x: 0.886623 m, y: 0.511879 m, z: 0.503287 m), (x: 0.193622 m, y: 0.470371 m, z: 0.0511627 m), (x: 0.388379 m, y: 0.739729 m, z: 0.925322 m))
Triangle((x: 0.397732 m, y: 0.47886 m, z: 0.293984 m), (x: 0.176495 m, y: 0.999095 m, z: 0.822975 m), (x: 0.500431 m, y: 0.736043 m, z: 0.149681 m))