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.1568096082717335 m
├─ y: 0.838250678806519 m
└─ z: 0.6421535531689235 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.9602127121959654 m
└─ y: 0.10150133883003254 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: 84.8805°, lon: 108.662°), (lat: -84.0005°, lon: -52.3348°))
Segment((lat: -2.03609°, lon: 27.1851°), (lat: 53.5334°, lon: -118.959°))
Segment((lat: 19.2164°, lon: -138.835°), (lat: -30.2052°, lon: 123.074°))
Segment((lat: 36.1398°, lon: -139.412°), (lat: -54.9851°, lon: 8.77851°))
Segment((lat: -16.9209°, lon: -127.955°), (lat: 80.1473°, lon: -139.576°))
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))