Geometry
To filter particles in a particular volume, such as a cube, a sphere, or a cylinder, geometries can be used. This package provides a variety of different geometries for multiple dimensions, including the following:
- Hyperrectangle
- Hypersphere
- Cylinder (standing cylinder aligned with the z axis and arbitrary orientation)
CosmoParticles.AbstractCosmoGeometry
— Typeabstract type AbstractCosmoGeometry end
Abstract type for (multi-dimensional) geometry volumes, particularly for filtering with filter
.
Any subtypes of AbstractCosmoGeometry
have to implement the following methods:
The following methods are optional, but have default implementations:
CosmoParticles.geometry_enclosing_corners
— Functiongeometry_enclosing_corners(geo::AbstractCosmoGeometry)
Return the lower left and upper right corners of the enclosing box of the geometry as a tuple of vectors.
The enclosing box is not necessarily the tightest fitting box.
This is not exported.
CosmoParticles.geometry_enclosing_center
— Functiongeometry_enclosing_center(geo::AbstractCosmoGeometry)
Return the center of the enclosing box of the geometry as a vector.
This is not exported.
CosmoParticles.mask_in
— Functionmask_in(pos::AbstractMatrix{<:Number}, geo::AbstractCosmoGeometry)
Return the BitArray
mask of the positions ($\mathrm{dims} × N$) located within the geometry.
Calls mask_in!
by default.
This is not exported.
CosmoParticles.mask_in!
— Functionmask_in!(mask::BitVector, pos::AbstractMatrix{<:Number}, geo::AbstractCosmoGeometry)
Return the BitVector
mask of the positions ($\mathrm{dims} × N$) located within the geometry.
This is not exported.
CosmoParticles.CosmoHyperrectangle
— Typestruct CosmoHyperrectangle{T,N} <: AbstractCosmoGeometry where {T<:Number}
lowerleft::Vector{T}
upperright::Vector{T}
end
N
-dimensional hyperrectangle aligned with the coordinate system axes given by its lower left and upper right corners.
The dimensions of space are given by N
.
CosmoParticles.CosmoCuboid
— TypeCosmoCuboid{T} = CosmoHyperrectangle{T,3}
Alias for a 3D CosmoHyperrectangle
.
CosmoParticles.CosmoRectangle
— TypeCosmoRectangle{T} = CosmoHyperrectangle{T,2}
Alias for a 2D CosmoHyperrectangle
.
CosmoParticles.CosmoHypercube
— FunctionCosmoHypercube(center::AbstractVector{<:Number}, radius::Number)
Return a cubic CosmoCuboid
centered around center
, with equal sidelengths.
CosmoParticles.CosmoCube
— FunctionCosmoCube(center::AbstractVector{<:Number}, radius::Number)
Return a cubic CosmoCuboid
centered around center
, with equal sidelengths.
CosmoParticles.CosmoSquare
— FunctionCosmoSquare(center::AbstractVector{<:Number}, radius::Number)
Return a square CosmoRectangle
centered around center
, with equal sidelengths.
CosmoParticles.CosmoHypersphere
— Typestruct CosmoHypersphere{T,N} <: AbstractCosmoGeometry where {T<:Number}
center::Vector{T}
radius::T
end
N
-dimensional hypersphere given by its center
and radius
.
If different types are passed to the constructor, the types will be promoted without throwing an error.
CosmoParticles.CosmoHypersphere
— MethodCosmoHypersphere(N::Integer, radius::T)
Returns an N
-dimensional hypersphere around the origin.
CosmoParticles.CosmoSphere
— TypeCosmoSphere{T} = CosmoHypersphere{T,3}
Alias for a 2D CosmoHypersphere
.
CosmoParticles.CosmoSphere
— MethodCosmoSphere(radius::T)
Returns a sphere around the origin.
CosmoParticles.CosmoCircle
— TypeCosmoCircle{T} = CosmoHypersphere{T,2}
Alias for a 2D CosmoHypersphere
.
CosmoParticles.CosmoCircle
— MethodCosmoCircle(radius::T)
Returns a circle around the origin.
CosmoParticles.CosmoCylinder
— Typestruct CosmoCylinder{T} <: AbstractCosmoGeometry where {T<:Number}
startpos::Vector{T}
endpos::Vector{T}
radius::T
end
Cylinder given by its end points startpos
and endpos
and radius
.
If different types are passed to the constructor, the types will be promoted without throwing an error.
CosmoParticles.CosmoCylinder
— MethodCosmoCylinder(c::CosmoStandingCylinder)
Create a cylinder from a standing cylinder.
CosmoParticles.CosmoStandingCylinder
— Typestruct CosmoStandingCylinder{T} <: AbstractCosmoGeometry where {T<:Number}
center::Vector{T}
height::T
radius::T
end
Standing cylinder given by its center
, height
, and radius
.
Standing means that the cylinder is oriented such that its axis is aligned with the z axis. If different types are passed to the constructor, the types will be promoted without throwing an error.
CosmoParticles.CosmoStandingCylinder
— MethodCosmoStandingCylinder(c::CosmoCylinder)
Create a standing cylinder from a cylinder.
The end positions of the cylinder have to have the same x and y coordinates.
Ellipsoids
Geometries
CosmoParticles.CosmoEllipse
— Typestruct CosmoEllipse{T,U} <: AbstractCosmoGeometry where {T<:Number,U<:Real}
a::T
q::U
end
Ellipse around the origin given by the semi-major axis a
and the axis ratio q = b/a
(where b
is the semi-minor axis).
CosmoParticles.CosmoEllipse
— MethodCosmoEllipse(a::T; q::U=1, constant_area=false) where {T<:Number,U<:Real}
Returns an ellipse around the origin with semi-major axis a
and the axis ratio q
.
If constant_area=true
, the semi-major axis of the ellipse is picked such that its area is equal to that of a circle with radius a
.
The axis ratio q
has to be between 0 and 1.
CosmoParticles.CosmoEllipsoid
— Typestruct CosmoEllipsoid{T,U} <: AbstractCosmoGeometry where {T<:Number,U<:Real}
a::T
q::U
s::U
end
Ellipsoid around the origin given by the largest semi-major axis a
, and the axis ratios q = b/a
and s = c/a
(where b
and c
are the semi-minor axes with b ≥ c
).
CosmoParticles.CosmoEllipsoid
— MethodCosmoEllipsoid(a::Number; q::Real=1, s::Real=1, constant_volume=false)
Returns an ellipsoid around the origin with semi-major axis a
and the axis ratios q
and s
.
If constant_volume=true
, the semi-major axis of the ellipsoid is picked such that its volume is equal to that of a sphere with radius a
.
Both q
and s
have to be between 0 and 1, and q ≥ s
has to hold.
CosmoParticles.CosmoEllipsoid
— MethodCosmoEllipsoid(a::Number, b::Number, c::Number)
Returns an ellipsoid around the origin with semi axes a
, b
, and c
, with a ≥ b ≥ c
.
If c
is nothing
, a CosmoEllipse
is created instead.
CosmoParticles.CosmoHomoeoid2D
— Typestruct CosmoHomoeoid2D{T,U} <: AbstractCosmoGeometry where {T<:Number,U<:Real}
a1::T
a2::T
q::U
end
Homoeoid in two dimensions around the origin given by the inner and outer semi-major axes a1
and a2
, and the axis ratio q = b/a
.
CosmoParticles.CosmoHomoeoid2D
— MethodCosmoHomoeoid2D(a1::Number, a2::Number; q::Real=1, constant_area=false)
CosmoHomoeoid2D(a::Number, b::Number; a2::Number)
Returns a 2D homoeoid around the origin with semi-major axes a1 ≤ a2
and the axis ratio q
.
If constant_area=true
, the semi-major axes of the ellipse are picked such that the enclosed area is equal to that enclosed by two circles with radii a1
and a2
.
The axis ratio q
has to be between 0 and 1.
For the second method, a2
can also be smaller than a1
. It is only important that a
and b
both either correspond to the inner or outer ellipse.
CosmoParticles.CosmoHomoeoid
— Typestruct CosmoHomoeoid{T,U} <: AbstractCosmoGeometry where {T<:Number,U<:Real}
a1::T
a2::T
q::U
s::U
end
Homoeoid in three dimensions around the origin given by the inner and outer semi-major axes a1
and a2
, and the axis ratios q = b/a
and s = c/a
.
CosmoParticles.CosmoHomoeoid
— MethodCosmoHomoeoid(a1::Number, a2::Number; q::Real=1, s::Real=1, constant_volume=false)
Returns a 3D homoeoid around the origin with semi-major axes a1 ≤ a2
and the axis ratios q
and s
.
If constant_volume=true
, the semi-major axes of the ellipsoids are picked such that the enclosed volume is equal to that enclosed by two spheres with radii a1
and a2
.
The axis ratios q
and s
have to be between 0 and 1.
CosmoParticles.CosmoHomoeoid
— MethodCosmoHomoeoid(a::Number, b::Number, c::Number; a2::Number)
Returns a 3D homoeoid around the origin with semi axes a ≥ b ≥ c
and another enclosing similar ellipsoid specified by the semi-major axis a2
.
The semi-major axis a2
can be smaller or larger than a
.
If c
is nothing
, a CosmoHomoeoid2D
is created instead.
Utils
CosmoParticles.colnormell
— Functioncolnormell(a::AbstractMatrix, q[, s])
Returns a new Vector
with the columnwise elliptical norms of a
.
In the 2D case: $\sqrt{x^2 + \frac{y^2}{q^2}}$. In the 3D case: $\sqrt{x^2 + \frac{y^2}{q^2} + \frac{z^2}{s^2}}$.
See also colnormell2
.
CosmoParticles.colnormell2
— Functioncolnormell2(a::AbstractMatrix, q[, s])
Returns a new Vector
with the columnwise squared elliptical norms of a
.
In the 2D case: $x^2 + \frac{y^2}{q^2}$. In the 3D case: $x^2 + \frac{y^2}{q^2} + \frac{z^2}{s^2}$.
See also colnormell
.
CosmoParticles.triaxiality
— Functiontriaxiality(q::Real, s::Real)
triaxiality(e::Union{CosmoEllipsoid,CosmoHomoeoid})
Triaxiality from the axis ratios q
and s
.
- $0 < T < 1/3$: oblate
- $1/3 < T < 2/3$: triaxial
- $2/3 < T < 1$: prolate
CosmoParticles.ellipticity
— Functionellipticity(q::Real)
ellipticity(e::Union{CosmoEllipse,CosmoHomoeoid2D})
Ellipticity from axis ratio q
: $ϵ = 1 - q$
CosmoParticles.eccentricity
— Functioneccentricity(q::Real)
eccentricity(e::Union{CosmoEllipse,CosmoHomoeoid2D})
Eccentricity from axis ratio q
: $e = \sqrt{1 - q^2}$
Special Geometries
CosmoParticles.CosmoUnionGeometry
— Typestruct CosmoUnionGeometry <: AbstractCosmoGeometry
geos::Tuple
end
Union of multiple geometries.
This union geometry represents all of the volumes contained within the geometries.
This is not exported.
CosmoParticles.CosmoIntersectGeometry
— Typestruct CosmoIntersectGeometry <: AbstractCosmoGeometry
geos::Tuple
end
Intersect of multiple geometries.
This intersect geometry represents the volume that is shared among all of the geometries.
This is not exported.
CosmoParticles.CosmoDiffGeometry
— Typestruct CosmoDiffGeometry <: AbstractCosmoGeometry
geo::AbstractCosmoGeometry
geos::Tuple
end
Difference of a geometry with multiple geometries.
This difference geometry represents the volume of geo
, but that is not contained in any of the geometries geos
.
This is not exported.
Base.union
— MethodBase.union(geos::AbstractCosmoGeometry...)
Create a union of geometries from the passed geometries.
Examples
using CosmoParticles
using CosmoParticles: mask_in
pos::Matrix # 3×n
g1 = CosmoSphere([1, 2, 3], 4)
g2 = CosmoSphere([3, 2, 3], 4)
geo = union(g1, g2)
mask_in(pos, geo) == mask_in(pos, g1) .| mask_in(pos, g2)
Base.intersect
— MethodBase.intersect(geos::AbstractCosmoGeometry...)
Create an intersect of geometries from the passed geometries.
Examples
using CosmoParticles
using CosmoParticles: mask_in
pos::Matrix # 3×n
g1 = CosmoSphere([1, 2, 3], 4)
g2 = CosmoSphere([3, 2, 3], 4)
geo = intersect(g1, g2)
mask_in(pos, geo) == mask_in(pos, g1) .& mask_in(pos, g2)
Base.setdiff
— MethodBase.setdiff(geo::AbstractCosmoGeometry, geos::AbstractCosmoGeometry...)
Create a difference of geometries from the passed geometries.
Examples
using CosmoParticles
using CosmoParticles: mask_in
pos::Matrix # 3×n
g1 = CosmoSphere([1, 2, 3], 4)
g2 = CosmoSphere([3, 2, 3], 4)
geo = setdiff(g1, g2)
mask_in(pos, geo) == mask_in(pos, g1) .& .~mask_in(pos, g2)
CosmoParticles.Rotated
— Typestruct Rotated{G,R} <: AbstractCosmoGeometry where {G<:AbstractCosmoGeometry,R<:AbstractMatrix}
geo::G
rotmat::R
end
Rotated geometry defined by a rotation matrix.
This can be created by rotate
applied to a geometry.
This is not exported.
CosmoParticles.rotate
— Methodrotate(geo::AbstractCosmoGeometry, rotmat::AbstractMatrix{<:Real})
Returns a rotated geometry rotated by the rotation matrix.
Individual geometries may specify that this returns a different type than Rotated
.
CosmoParticles.rotation_matrix
— Functionrotation_matrix(rot::Rotated)
Returns the rotation matrix that rotates the original geometry into the rotated state.
This is not exported.
CosmoParticles.rotation_matrix_inv
— Functionrotation_matrix_inv(rot::Rotated)
Returns the rotation matrix that rotates the rotated geometry back to its original orientation.
Use this to rotate objects in the rotated frame of reference to the original frame of reference of the geometry.
This is not exported.
CosmoParticles.Translated
— Typestruct Translated{G,L} <: AbstractCosmoGeometry where {G<:AbstractCosmoGeometry,L<:AbstractVector}
geo::G
Δx::L
end
Translated geometry defined by a translation vector.
This can be created by translate
applied to a geometry.
This is not exported.
CosmoParticles.translate
— Methodtranslate(geo::AbstractCosmoGeometry, Δx::AbstractVector{<:Number})
Returns a new geometry translated by Δx
.
Individual geometries may specify that this returns a different type than Translated
.