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.15849488517632992 m
├─ y: 0.2872741904823888 m
└─ z: 0.5588203268918072 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.2554401445925971 m
└─ y: 0.9893154763113132 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: -38.2463°, lon: -108.439°), (lat: 3.98621°, lon: 157.581°))
Segment((lat: 23.157°, lon: 45.201°), (lat: -38.9561°, lon: -105.444°))
Segment((lat: -35.1414°, lon: -11.5141°), (lat: 60.3203°, lon: 153.561°))
Segment((lat: -81.6566°, lon: 91.6675°), (lat: -12.2663°, lon: -120.848°))
Segment((lat: 73.0086°, lon: -78.1385°), (lat: -62.4734°, lon: -122.461°))
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))