Reduce Radius when..

Hello,

i’m start with a radius of 1 in the middle of a sphere, i create rings arround it, now i want to reduce the radius when the position goes to the top/bottom of the sphere. Is there a mathematical function for this?

Thank you :slight_smile:

Can you provide a bit more detailed description? or even picture if that is not the problem.

I want to calculate each radian Till The Top of The spüre, starting from The middle.

I assume you ask how to calculate circle of latitude. Well, I guess it should be simple, it’s just cosinus
(or sinus if you count from the pole). Let me show you this on my professional drawing:
8179562--1065215--upload_2022-6-3_22-36-59.png
You know the radius and length of equator (in this case 1), so what you need is the red angle.
Let say the red point is on 30 deg (from equator), so it will be cos(30deg) = 0.86 and this value is percent of sphere radius, so radius of blue circle is 1 * 0.86.

If you want to know the angle from the height (gray line) you can use arccosine() first.

3 Likes

This is just basic trigonometry. Did you take any of that at school? Say you have a sphere centered at 0,0,0 your radius is 1 at the center (like you said). How far up the y axis you go is your “opposite” and the radius at that height will be your “adjacent”. So assuming you already have a y value in mind you can get an angle using theta = arcsin(y), then cos(theta) will be your radius at y.

Alternately you can use the good-old pythagorian theorem: Pythagorean theorem - Wikipedia
In this article, they present the theorem in terms of a,b and c. In this case “c” will always be 1 since that is the radius of the sphere. “b” will be how far up the y axis you want to go, and therefore “a” will be the value you are looking for at that point.

I know when I was in high school trigonometry seemed like a whole lot of gobbledygook, but it’s fundamental to 3D games (and a lot of other things).

1 Like

Thank you all. Thats exactly i’m searching for, i forgot it its so long ago from school xD

Acos does not return a angle when i’m input a height between 0 and 1 (because 0 is equator and 1 is top)?

If i’m doing Mathf.Cos(30) it puts out 0.15…

Trigonometric functions in math always use radians and not degrees. Radians is the most natural way of describing angles. Unfortunately the values are not human friendly as 360° is 2*PI. You can use the factors Mathf.Deg2Rad and Mathf.Rad2Deg respectively to convert from degrees to radians and vice versa. Just multiply the value by those constants.

Calculators for humans usually work in degrees. Though scientific calculators can usually switched to radians. Most scientific calculators also have another angle unit called “Gradian” (GRAD) which is an old angle unit that sets a full circle to 400 instead of 360 (or 2PI). Though this is rarely used anywhere ^^.

The reason why radian is “the” actual angle unit is because of how the trig functions are actually defined. See wikipedia and the series expansion. For most people the innerworkings of sin / cos / tan are black magic. However it’s actually just plain math. Though since it’s an infinite series you can only get an approximation for arbitrary angles.

2 Likes

Here’s how I make a sphere procedurally:

Look specifically on Line 65 for the big hairy expression generating a point based on latitude and longitude.

The full source is obviously above and also at these locations:

https://bitbucket.org/kurtdekker/makegeo

https://github.com/kurtdekker/makegeo

I’m got it working like 80%.
The radius is shrinking too fast, it looks like a sphere but it doesn’t match the sphere from Unity.

Spawn a standard unity sphere, than spawn little spheres arround them using this:

    float GetRadianFromAngle(float angle)
    {
        float radian = Mathf.Cos(Mathf.Deg2Rad * angle);
        if (angle == 90)
        {
            radian = 0;
        }
        Debug.Log("Angle/Radian: " + angle + " " + radian);
        return radian;
    }

It will never match the sphere from Unity.

The Unity sphere appears to be made by mostly quads and optimized for triplanar viewing.

The example code above in MakeGeo is simply a polar sphere.

Compare:

8202228--1070154--topology.png

I dont use the mesh, its only in world space with objects, so the sphere have a shape of the same sphere ignoring the uvs and vertices. but the mathematical calculations is wrong, it does not fit the sphere.

I didn’t take trig at all from school and had to teach myself. Not everyone is in a great place in the world. Just be mindful, that’s all.

3 Likes

Sorry but it’s hard to follow what you actually want to do and what doesn’t work out the way you want. Keep in mind that the default sphere of Unity has a radius of “0.5”. The sphere has a diameter of “1.0”

That doesn’t make much sense. if it looks like a sphere, it is a sphere. It’s not really clear what you actually do with that new / reduced “radius”. If you want to do any conversion into cartesian coordinates you almost always need both sine and cosine to actually represent a sphere. Those are the two relevant components.