JuliaGeometry/Meshes.jl

Parameterization of a Torus with `minor > major`

Closed this issue · 8 comments

I stumbled onto this while testing a new surface integral function:

  • A Torus can be constructed whose minor radii is greater than its major radii. Based on a quick reading of the Wikipedia page (IANA-geometer), it sounds like this is valid but sort of a special case.
  • For such a Torus, the current parameterization code will error. Line 55 essentially takes sqrt(t.major^2 - t.minor^2), which throws a DomainError since the argument is negative but also <:Real.

function (t::Torus{T})(u, v) where {T}
if (u < 0 || u > 1) || (v < 0 || v > 1)
throw(DomainError((u, v), "t(u, v) is not defined for u, v outside [0, 1]²."))
end
c, n⃗ = t.center, t.normal
R, r = t.major, t.minor
Q = rotation_between(Vec{3,T}(0, 0, 1), n⃗)
kxy = R^2 - r^2
kz = kxy * r
uₛ = T(π) * (2 * u - 1)
vₛ = T(π) * (2 * v - 1)
k = R - r * cos(vₛ)
x = kxy * cos(uₛ) / k
y = kxy * sin(uₛ) / k
z = kz * sin(vₛ) / k
c + Q * Vec{3,T}(x, y, z)
end

I don’t know enough about how the parameterization here is derived to know whether the absolute value of the interior term could be taken first, or if parameterizing Torus with this property is a harder problem. It’s also non-obvious to me whether this type of Torus was even intended to be supported.

@stla could you please take a look in this issue? Do I remember correctly that you added the Torus primitive last year?

stla commented

Yes, that's me. In fact, I implemented a non-usual parameterization of the torus, valid only for major > minor. I thought it was interesting because it is a conformal parameterization, but actually this is useless.

What do you suggest in this case @stla? Should we adopt a different parametrization?

stla commented

Yes, we should adopt the classical parameterization (certainly given on Wikipedia).

stla commented

Here. I could do the modifications but not so soon.

This seems like it should be easy enough to re-implement. I’ll make an attempt at a PR for this.

Fixed on master.