Skip to content

Move SphericalCoordinate here and use for eltype of spheres? #183

Open

Description

@dlfivefifty

Using SVector{3,T} for the eltype of UnitSphere is problematic since almost no floating point numbers are in it!

Here I have SphericalCoordinate where norm is hard coded to be 1:

https://github.com/JuliaApproximation/HarmonicOrthogonalPolynomials.jl/blob/13b134b6cddf086783cf260a691dbb6bc5f13fbd/src/coordinates.jl#L42

I think this would be a better default choice

Activity

  1. daanhb commented on Jun 17, 2026

    @daanhb
    Member

    It might be handy to have SphericalCoordinate in this package, but I never saw the domaineltype of sphere being SVector{3,T} as problematic. It is a valid description of the types of elements of the domain, which lives in 3D, just like 2*Unitsphere(). On the other hand, it feels superfluous to use SphericalCoordinate, since the element encodes the domain. You can already use FullSpace{T}() to represent the domain itself.

  2. dlfivefifty commented on Jun 17, 2026

    @dlfivefifty
    MemberAuthor

    SphericalCoordinate <: StaticVector{3} unlike FullSpace

    The difference is every spherical coordinate is on the sphere whereas very few of SVector{3} are

  3. daanhb commented on Jun 17, 2026

    @daanhb
    Member

    I agree it would be convenient to have in order to actually represent points on the unit sphere. I'm just not convinced that it should be the default element type of the unit sphere, since there are many other lower dimensional subsets of spaces with the same issue. What would be the element type of 2*UnitSphere()? It feels a bit random to treat this one case.

    Then again, I did not think it through. Would it be a breaking change or not?

    Also, seems we already have DomainPoint and, more specifically, SpherePoint:

    struct EuclideanSpherePoint{T} <: SpherePoint{T}

    Yet these types are not <: StaticVector{3}.

  4. dlfivefifty commented on Jun 17, 2026

    @dlfivefifty
    MemberAuthor

    Here is the actual issue I'm facing:

    julia> 𝐱 = SphericalCoordinate(-0.34101831299283725, -0.06854887148495051)
    3-element SphericalCoordinate{Float64} with indices SOneTo(3):
     -0.3336614716881377
      0.022908009768077293
      0.9424145825481329
    
    julia> norm(𝐱)
    1.0
    
    julia> 𝐱 in UnitSphere()
    true
    
    julia> convert(eltype(UnitSphere()), 𝐱) in UnitSphere()
    false

    What would be the element type of 2*UnitSphere()?

    I probably mean make it SphericalCoordinate(r, θ, φ), i.e., the unit sphere is when r == 1

  5. dlfivefifty commented on Jun 17, 2026

    @dlfivefifty
    MemberAuthor

    Though I'm not sure how to make a 4D or 5D spherical coordinate ....

    In any case I've managed to work around it in HarmonicOrthogonalPolynomials.jl

  6. daanhb commented on Jun 18, 2026

    @daanhb
    Member

    The DomainSets way, if there is such a thing, for generating points on a domain would be to generate them in a parameter domain (parameterdomain) and map them. In this case, the result being of type SVector{3,Float64}, these points would still fail the in test, at least without a tolerance.

    There is no parameter domain for a UnitSphere, but there is one for UnitCircle:

    julia> d = UnitCircle()
    UnitCircle()
    
    julia> parameterdomain(d)
    0.0 .. 1.0 (Unit)
    
    julia> m = mapfrom_parameterdomain(d)
    FunctionMaps.UnitCircleMap{Float64}()
    
    julia> m(0.4)
    2-element StaticArraysCore.SVector{2, Float64} with indices SOneTo(2):
     -0.8090169943749473
      0.5877852522924732

    Ideally, the maps go into FunctionMaps.jl or they are borrowed from an existing package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions