-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
outsource intersection to set modules
- Loading branch information
Showing
10 changed files
with
92 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
""" | ||
intersection(L1::Line2D, L2::Line2D) | ||
Compute the intersection of two two-dimensional lines. | ||
### Input | ||
- `L1` -- line | ||
- `L2` -- line | ||
### Output | ||
Three outcomes are possible: | ||
- If the lines are identical, the result is the first line. | ||
- If the lines are parallel and not identical, the result is the empty set. | ||
- Otherwise the result is the set with the unique intersection point. | ||
### Algorithm | ||
We first check whether the lines are parallel. | ||
If not, we use [Cramer's rule](https://en.wikipedia.org/wiki/Cramer%27s_rule) | ||
to compute the intersection point. | ||
### Examples | ||
The line ``y = x`` intersected with the line ``y = -x + 1`` respectively with | ||
itself: | ||
```jldoctest | ||
julia> intersection(Line2D([-1.0, 1], 0.0), Line2D([1.0, 1], 1.0)) | ||
Singleton{Float64, Vector{Float64}}([0.5, 0.5]) | ||
julia> intersection(Line2D([1.0, 1], 1.0), Line2D([1.0, 1], 1.0)) | ||
Line2D{Float64, Vector{Float64}}([1.0, 1.0], 1.0) | ||
``` | ||
""" | ||
function intersection(L1::Line2D, L2::Line2D) | ||
return _intersection_line2d(L1, L2) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
intersection(U::Universe, ::Universe) = U |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
""" | ||
intersection(P1::VPolygon, P2::VPolygon; apply_convex_hull::Bool=true) | ||
Compute the intersection of two polygons in vertex representation. | ||
### Input | ||
- `P1` -- polygon in vertex representation | ||
- `P2` -- polygon in vertex representation | ||
- `apply_convex_hull` -- (default, optional: `true`) if `false`, skip the | ||
computation of the convex hull of the resulting polygon | ||
### Output | ||
A `VPolygon`, or an `EmptySet` if the intersection is empty. | ||
### Algorithm | ||
This function applies the [Sutherland–Hodgman polygon clipping | ||
algorithm](https://en.wikipedia.org/wiki/Sutherland%E2%80%93Hodgman_algorithm). | ||
The implementation is based on the one found in | ||
[rosetta code](http://www.rosettacode.org/wiki/Sutherland-Hodgman_polygon_clipping#Julia). | ||
""" | ||
function intersection(P1::VPolygon, P2::VPolygon; apply_convex_hull::Bool=true) | ||
v1 = vertices_list(P1) | ||
v2 = vertices_list(P2) | ||
v12 = _intersection_vrep_2d(v1, v2) | ||
|
||
if isempty(v12) | ||
require(@__MODULE__, :LazySets; fun_name="intersection") | ||
|
||
N = promote_type(eltype(P1), eltype(P2)) | ||
return EmptySet{N}(2) | ||
else | ||
return VPolygon(v12; apply_convex_hull=apply_convex_hull) | ||
end | ||
end |