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 more efficient parametric transformation for Tetrahedron #159

Merged
merged 6 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions src/specializations/Tetrahedron.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,26 @@

# Map argument domain from [0, 1]³ to Barycentric domain for (::Tetrahedron)(t1, t2, t3)
mikeingold marked this conversation as resolved.
Show resolved Hide resolved
function _parametric(tetrahedron::Meshes.Tetrahedron)
function f(t1, t2, t3)
if any(Iterators.map(n -> (n < 0) || (n > 1), (t1, t2, t3)))
msg = "tetrahedron(t1, t2, t3) is not defined for (t1, t2, t3) outside [0, 1]³."
throw(DomainError((t1, t2, t3), msg))
function f(t₁, t₂, t₃)
if any(Iterators.map(n -> (n < 0) || (n > 1), (t₁, t₂, t₃)))
msg = "tetrahedron(t₁, t₂, t₃) is not defined for (t₁, t₂, t₃) outside [0, 1]³."
throw(DomainError((t₁, t₂, t₃), msg))
end

# Take a triangular cross-section at t3
a = tetrahedron(t3, 0, 0)
b = tetrahedron(0, t3, 0)
c = tetrahedron(0, 0, t3)
cross_section = _parametric(Meshes.Triangle(a, b, c))

return cross_section(t1, t2)
"""

Check warning on line 37 in src/specializations/Tetrahedron.jl

View check run for this annotation

Codecov / codecov/patch

src/specializations/Tetrahedron.jl#L37

Added line #L37 was not covered by tests
# Algorithm:
- Form a barycentric tetrahedron bounded by the points [0, 0, 0], [1, 0, 0],
[0, 1, 0], and [0, 0, 1].
- Use t₃ to take a triangular cross-section of the tetrahedron at points
[t₃, 0, 0], [0, t₃, 0], and [0, 0, t₃].
- Use t₂ to take a line segment cross-section of the triangle between
points [t₂t₃, 0, t₃ - t₂t₃] and [0, t₂t₃, t₃ - t₂t₃].
- Use t₁ to select a point along this line segment, i.e. ā + t₁(b̄ - ā).
"""
u₁ = (t₂ * t₃) - (t₁ * t₂ * t₃)
u₂ = t₁ * t₂ * t₃
u₃ = t₃ - (t₂ * t₃)
return tetrahedron(u₁, u₂, u₃)
end
return f
end
20 changes: 14 additions & 6 deletions src/specializations/Triangle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,22 @@

# Map argument domain from [0, 1]² to Barycentric domain for (::Triangle)(t1, t2)
mikeingold marked this conversation as resolved.
Show resolved Hide resolved
function _parametric(triangle::Meshes.Triangle)
function f(t1, t2)
if any(Iterators.map(n -> (n < 0) || (n > 1), (t1, t2)))
msg = "triangle(t1, t2) is not defined for (t1, t2) outside [0, 1]²."
throw(DomainError((t1, t2), msg))
function f(t₁, t₂)
if any(Iterators.map(n -> (n < 0) || (n > 1), (t₁, t₂)))
msg = "triangle(t₁, t₂) is not defined for (t₁, t₂) outside [0, 1]²."
throw(DomainError((t₁, t₂), msg))
end

t1t2 = t1 * t2
return triangle(t1t2, t2 - t1t2)
"""

Check warning on line 37 in src/specializations/Triangle.jl

View check run for this annotation

Codecov / codecov/patch

src/specializations/Triangle.jl#L37

Added line #L37 was not covered by tests
# Algorithm:
- Form a barycentric triangle bounded by the points [0, 0], [1, 0], and [0, 1].
- Use t₂ to take a line segment cross-section of the triangle between points
[0, t₂] and [t₂, 0].
- Use t₁ to select a point along this line segment, i.e. ā + t₁(b̄ - ā).
"""
u₁ = t₁ * t₂
u₂ = t₂ - (t₁ * t₂)
return triangle(u₁, u₂)
end
return f
end
Loading