The formula above did not work for me. Consider b = 0, the formula should be reduced to a circle, when in fact in the accepted answer it comes down to a sphere.
From my calculation you should check the sign of expression
(x ^ 2 + y ^ 2 + r ^ 2 + a ^ 2-b ^ 2) ^ 2-4a ^ 2 (x ^ 2 + y ^ 2)
where is the point {x, y, z}, and the small radius of the torus is b, and the main radius is a.
edit: equivalent, and closer to the original accepted answer the expression will be
(x ^ 2 + y ^ 2 + r ^ 2- (a ^ 2 + B ^ 2)) ^ 2-4a ^ 2 (b ^ 2-g ^ 2)
source share