Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use minor and major radii for Torus primitive shape #10643

Merged
merged 12 commits into from
Nov 21, 2023

Conversation

Jondolf
Copy link
Contributor

@Jondolf Jondolf commented Nov 19, 2023

Objective

First, some terminology:

  • Minor radius: The radius of the tube of a torus, i.e. the "half-thickness"
  • Major radius: The distance from the center of the tube to the center of the torus
  • Inner radius: The radius of the hole (if it exists), major_radius - minor_radius
  • Outer radius: The radius of the overall shape, major_radius + minor_radius
  • Ring torus: The familiar donut shape with a hole in the center, major_radius > minor_radius
  • Horn torus: A torus that doesn't have a hole but also isn't self-intersecting, major_radius == minor_radius
  • Spindle torus: A self-intersecting torus, major_radius < minor_radius

Different tori from Wikipedia, where R is the major radius and r is the minor radius:

kuva

Currently, Bevy's torus is represented by a radius and ring_radius. I believe these correspond to the outer radius and minor radius, but they are rather confusing and inconsistent names, and they make the assumption that the torus always has a ring.

I also couldn't find any other big engines using this representation; Godot and Unity ProBuilder use the inner and outer radii, while Unreal uses the minor and major radii. Blender supports both, but defaults to minor/major.

Bevy's Torus primitive should have an efficient, consistent, clear and flexible representation, and the current radius and ring_radius properties are not ideal for that.

Solution

Change Torus to be represented by a minor_radius and major_radius.

  • Mathematically correct and consistent
  • Flexible, not restricted to ring tori
  • Computations and conversions are efficient
    • inner_radius = major_radius - minor_radius
    • outer_radius = major_radius + minor_radius
    • Mathematical formulae for things like area and volume rely on the minor and major radii, no conversion needed

Perhaps the primary issue with this representation is that "minor radius" and "major radius" are rather mathematical, and an inner/outer radius can be more intuitive in some cases. However, this can be mitigated with constructors and helpers.

@Jondolf Jondolf added C-Enhancement A new feature A-Math Fundamental domain-agnostic mathematical operations labels Nov 19, 2023
@Jondolf Jondolf changed the title Use minor and major radii for Torus shape representation Use minor and major radii for Torus primitive shape representation Nov 19, 2023
@Jondolf Jondolf changed the title Use minor and major radii for Torus primitive shape representation Use minor and major radii for Torus primitive shape Nov 19, 2023
@alice-i-cecile alice-i-cecile added C-Docs An addition or correction to our documentation C-Usability A simple quality-of-life change that makes Bevy easier to use and removed C-Enhancement A new feature labels Nov 19, 2023
@alice-i-cecile alice-i-cecile added this to the 0.13 milestone Nov 19, 2023
crates/bevy_math/src/primitives/dim3.rs Outdated Show resolved Hide resolved
crates/bevy_math/src/primitives/dim3.rs Show resolved Hide resolved
crates/bevy_math/src/primitives/dim3.rs Outdated Show resolved Hide resolved
@alice-i-cecile
Copy link
Member

@NiseVoid, could I get your review?

crates/bevy_math/src/primitives/dim3.rs Outdated Show resolved Hide resolved
crates/bevy_math/src/primitives/dim3.rs Outdated Show resolved Hide resolved
@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Nov 20, 2023
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Nov 21, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 21, 2023
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Nov 21, 2023
Merged via the queue into bevyengine:main with commit 897b13b Nov 21, 2023
21 checks passed
@Jondolf Jondolf deleted the torus-representation branch November 21, 2023 02:14
rdrpenguin04 pushed a commit to rdrpenguin04/bevy that referenced this pull request Jan 9, 2024
# Objective

First, some terminology:

- **Minor radius**: The radius of the tube of a torus, i.e. the
"half-thickness"
- **Major radius**: The distance from the center of the tube to the
center of the torus
- **Inner radius**: The radius of the hole (if it exists), `major_radius
- minor_radius`
- **Outer radius**: The radius of the overall shape, `major_radius +
minor_radius`
- **Ring torus**: The familiar donut shape with a hole in the center,
`major_radius > minor_radius`
- **Horn torus**: A torus that doesn't have a hole but also isn't
self-intersecting, `major_radius == minor_radius`
- **Spindle torus**: A self-intersecting torus, `major_radius <
minor_radius`

Different tori from [Wikipedia](https://en.wikipedia.org/wiki/Torus),
where *R* is the major radius and *r* is the minor radius:


![kuva](https://github.com/bevyengine/bevy/assets/57632562/53ead786-2402-43a7-ae8a-5720e6e54dcc)

Currently, Bevy's torus is represented by a `radius` and `ring_radius`.
I believe these correspond to the outer radius and minor radius, but
they are rather confusing and inconsistent names, and they make the
assumption that the torus always has a ring.

I also couldn't find any other big engines using this representation;
[Godot](https://docs.godotengine.org/en/stable/classes/class_torusmesh.html)
and [Unity
ProBuilder](https://docs.unity3d.com/Packages/com.unity.probuilder@4.0/manual/Torus.html)
use the inner and outer radii, while
[Unreal](https://docs.unrealengine.com/5.3/en-US/BlueprintAPI/GeometryScript/Primitives/AppendTorus/)
uses the minor and major radii.
[Blender](https://docs.blender.org/manual/en/latest/modeling/meshes/primitives.html#torus)
supports both, but defaults to minor/major.

Bevy's `Torus` primitive should have an efficient, consistent, clear and
flexible representation, and the current `radius` and `ring_radius`
properties are not ideal for that.

## Solution

Change `Torus` to be represented by a `minor_radius` and `major_radius`.

- Mathematically correct and consistent
- Flexible, not restricted to ring tori
- Computations and conversions are efficient
  - `inner_radius = major_radius - minor_radius`
  - `outer_radius = major_radius + minor_radius`
- Mathematical formulae for things like area and volume rely on the
minor and major radii, no conversion needed

Perhaps the primary issue with this representation is that "minor
radius" and "major radius" are rather mathematical, and an inner/outer
radius can be more intuitive in some cases. However, this can be
mitigated with constructors and helpers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Math Fundamental domain-agnostic mathematical operations C-Docs An addition or correction to our documentation C-Usability A simple quality-of-life change that makes Bevy easier to use S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants