bevy/crates
Joona Aalto 897b13bf9d
Use minor and major radii for Torus primitive shape (#10643)
# 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.
2023-11-21 01:49:35 +00:00
..
bevy_a11y Add [lints] table, fix adding #![allow(clippy::type_complexity)] everywhere (#10011) 2023-11-18 20:58:48 +00:00
bevy_animation Standardize toml format with taplo (#10594) 2023-11-21 01:04:14 +00:00
bevy_app Standardize toml format with taplo (#10594) 2023-11-21 01:04:14 +00:00
bevy_asset Ensure consistency between Un/Typed AssetId and Handle (#10628) 2023-11-21 01:13:36 +00:00
bevy_audio Standardize toml format with taplo (#10594) 2023-11-21 01:04:14 +00:00
bevy_core Standardize toml format with taplo (#10594) 2023-11-21 01:04:14 +00:00
bevy_core_pipeline Standardize toml format with taplo (#10594) 2023-11-21 01:04:14 +00:00
bevy_derive Add [lints] table, fix adding #![allow(clippy::type_complexity)] everywhere (#10011) 2023-11-18 20:58:48 +00:00
bevy_diagnostic Standardize toml format with taplo (#10594) 2023-11-21 01:04:14 +00:00
bevy_dylib Add [lints] table, fix adding #![allow(clippy::type_complexity)] everywhere (#10011) 2023-11-18 20:58:48 +00:00
bevy_dynamic_plugin Add [lints] table, fix adding #![allow(clippy::type_complexity)] everywhere (#10011) 2023-11-18 20:58:48 +00:00
bevy_ecs Make impl block for RemovedSystem generic (#10651) 2023-11-21 01:27:29 +00:00
bevy_ecs_compile_fail_tests Add [lints] table, fix adding #![allow(clippy::type_complexity)] everywhere (#10011) 2023-11-18 20:58:48 +00:00
bevy_encase_derive Add [lints] table, fix adding #![allow(clippy::type_complexity)] everywhere (#10011) 2023-11-18 20:58:48 +00:00
bevy_gilrs Add [lints] table, fix adding #![allow(clippy::type_complexity)] everywhere (#10011) 2023-11-18 20:58:48 +00:00
bevy_gizmos Move Circle Gizmos to Their Own File (#10631) 2023-11-20 09:47:50 +00:00
bevy_gltf Standardize toml format with taplo (#10594) 2023-11-21 01:04:14 +00:00
bevy_hierarchy bevy_hierarchy: add some docs (#10598) 2023-11-21 01:11:20 +00:00
bevy_input Standardize toml format with taplo (#10594) 2023-11-21 01:04:14 +00:00
bevy_internal Standardize toml format with taplo (#10594) 2023-11-21 01:04:14 +00:00
bevy_log Standardize toml format with taplo (#10594) 2023-11-21 01:04:14 +00:00
bevy_macro_utils Allow #[derive(Bundle)] on tuple structs (take 3) (#10561) 2023-11-21 01:09:16 +00:00
bevy_macros_compile_fail_tests Standardize toml format with taplo (#10594) 2023-11-21 01:04:14 +00:00
bevy_math Use minor and major radii for Torus primitive shape (#10643) 2023-11-21 01:49:35 +00:00
bevy_mikktspace Standardize toml format with taplo (#10594) 2023-11-21 01:04:14 +00:00
bevy_pbr Standardize toml format with taplo (#10594) 2023-11-21 01:04:14 +00:00
bevy_ptr Add [lints] table, fix adding #![allow(clippy::type_complexity)] everywhere (#10011) 2023-11-18 20:58:48 +00:00
bevy_reflect Standardize toml format with taplo (#10594) 2023-11-21 01:04:14 +00:00
bevy_reflect_compile_fail_tests Improve TypeUuid's derive macro error messages (#9315) 2023-10-02 12:42:01 +00:00
bevy_render Standardize toml format with taplo (#10594) 2023-11-21 01:04:14 +00:00
bevy_scene Standardize toml format with taplo (#10594) 2023-11-21 01:04:14 +00:00
bevy_sprite Standardize toml format with taplo (#10594) 2023-11-21 01:04:14 +00:00
bevy_tasks Add [lints] table, fix adding #![allow(clippy::type_complexity)] everywhere (#10011) 2023-11-18 20:58:48 +00:00
bevy_text Standardize toml format with taplo (#10594) 2023-11-21 01:04:14 +00:00
bevy_time Standardize toml format with taplo (#10594) 2023-11-21 01:04:14 +00:00
bevy_transform Standardize toml format with taplo (#10594) 2023-11-21 01:04:14 +00:00
bevy_ui Standardize toml format with taplo (#10594) 2023-11-21 01:04:14 +00:00
bevy_utils Add [lints] table, fix adding #![allow(clippy::type_complexity)] everywhere (#10011) 2023-11-18 20:58:48 +00:00
bevy_window Standardize toml format with taplo (#10594) 2023-11-21 01:04:14 +00:00
bevy_winit Standardize toml format with taplo (#10594) 2023-11-21 01:04:14 +00:00