Skip to content

Commit

Permalink
explain icosphere number of points calculation without citing BY-NC l…
Browse files Browse the repository at this point in the history
…icense
  • Loading branch information
jakobhellermann committed Jan 8, 2021
1 parent a3241b4 commit b454bfc
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions crates/bevy_render/src/mesh/shape/icosphere.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,36 @@ impl Default for Icosphere {
impl From<Icosphere> for Mesh {
fn from(sphere: Icosphere) -> Self {
if sphere.subdivisions >= 80 {
// https://oeis.org/A005901
let subdivisions = sphere.subdivisions + 1;
let number_of_resulting_points = (subdivisions * subdivisions * 10) + 2;
/*
Number of triangles:
N = 20
Number of edges:
E = 30
Number of vertices:
V = 12
Number of points within a triangle (triangular numbers):
inner(s) = (s^2 + s) / 2
Number of points on an edge:
edges(s) = s
Add up all vertices on the surface:
vertices(s) = edges(s) * E + inner(s - 1) * N + V
Expand and simplify. Notice that the triangular number formula has roots at -1, and 0, so translating it one to the right fixes it.
subdivisions(s) = 30s + 20((s^2 - 2s + 1 + s - 1) / 2) + 12
subdivisions(s) = 30s + 10s^2 - 10s + 12
subdivisions(s) = 10(s^2 + 2s) + 12
Factor an (s + 1) term to simplify in terms of calculation
subdivisions(s) = 10(s + 1)^2 + 12 - 10
resulting_vertices(s) = 10(s + 1)^2 + 2
*/
let temp = sphere.subdivisions + 1;
let number_of_resulting_points = temp * temp * 10 + 2;

panic!(
"Cannot create an icosphere of {} subdivisions due to there being too many vertices being generated: {}. (Limited to 65535 vertices or 79 subdivisions)",
Expand Down

0 comments on commit b454bfc

Please sign in to comment.