Skip to content

Commit

Permalink
Fix Triangle2d/Triangle3d interior sampling to correctly follow t…
Browse files Browse the repository at this point in the history
…riangle (#12766)

# Objective

When I wrote #12747 I neglected to translate random samples from
triangles back to the point where they originated, so they would be
sampled near the origin instead of at the actual triangle location.

## Solution

Translate by the first vertex location so that the samples follow the
actual triangle.
  • Loading branch information
mweatherley authored Mar 29, 2024
1 parent 741803d commit bcdb20d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crates/bevy_math/src/shape_sampling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ fn sample_triangle_interior<P: NormedVectorSpace, R: Rng + ?Sized>(
if u + v > 1. {
let u1 = 1. - v;
let v1 = 1. - u;
ab * u1 + ac * v1
a + (ab * u1 + ac * v1)
} else {
ab * u + ac * v
a + (ab * u + ac * v)
}
}

Expand Down

0 comments on commit bcdb20d

Please sign in to comment.