Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
fracture-flow
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
benchmarks
fracture-flow
Commits
9cdf724c
Commit
9cdf724c
authored
8 years ago
by
Ivar Stefansson
Browse files
Options
Downloads
Patches
Plain Diff
Replace intersection_between_inclusive.m
parent
c23056ed
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/intersection_between_inclusive.m
+56
-59
56 additions, 59 deletions
scripts/intersection_between_inclusive.m
with
56 additions
and
59 deletions
scripts/intersection_between_inclusive.m
+
56
−
59
View file @
9cdf724c
function
[
intersection
]
=
intersection_between_inclusive
(
k
,
vk
,
l
,
vl
,
between
)
%UNTITLED2 Calculates intersections of two lines specified by two sets of
%points. If between is true, an empty value is returned if the intersection
%is outside the endpoints of either one of the lines
% lines in format [x1, y1; x2, y2]
% [11, 12; 21, 22]
% line k = ax + b, l = cx + d
% vk = true iff k vertical
if
vk
c
=
(
l
(
2
,
2
)
-
l
(
1
,
2
))
/
(
l
(
2
,
1
)
-
l
(
1
,
1
));
d
=
l
(
1
,
2
)
-
c
*
l
(
1
,
1
);
y
=
c
*
k
(
1
)
+
d
;
if
isnan
(
y
)
if
vl
intersection
=
[];
else
error
(
'non-parallel lines did not intersect'
);
end
elseif
between
&&
(
y
>
max
(
k
(
3
:
4
))
||
y
<
min
(
k
(
3
:
4
))
||
...
y
>
max
(
l
(
3
:
4
))
||
y
<
min
(
l
(
3
:
4
)))
intersection
=
[];
else
intersection
=
[
k
(
1
),
y
];
end
elseif
vl
a
=
(
k
(
2
,
2
)
-
k
(
1
,
2
))
/
(
k
(
2
,
1
)
-
k
(
1
,
1
));
b
=
k
(
1
,
2
)
-
a
*
k
(
1
,
1
);
x
=
l
(
1
);
y
=
a
*
x
+
b
;
if
isnan
(
y
)
error
(
'non-parallel lines did not intersect'
);
elseif
between
&&
(
y
>
max
(
l
(
3
:
4
))
||
y
<
(
min
(
l
(
3
:
4
)))
||
...
y
>
max
(
k
(
3
:
4
))
||
y
<
(
min
(
k
(
3
:
4
))))
intersection
=
[];
else
intersection
=
[
x
,
y
];
end
else
a
=
(
k
(
2
,
2
)
-
k
(
1
,
2
))
/
(
k
(
2
,
1
)
-
k
(
1
,
1
));
c
=
(
l
(
2
,
2
)
-
l
(
1
,
2
))
/
(
l
(
2
,
1
)
-
l
(
1
,
1
));
b
=
k
(
1
,
2
)
-
a
*
k
(
1
,
1
);
d
=
l
(
1
,
2
)
-
c
*
l
(
1
,
1
);
x
=
(
d
-
b
)/(
a
-
c
);
%y = a * x + b;
if
isnan
(
x
)
intersection
=
[];
elseif
between
&&
(
x
>
max
(
l
(
1
:
2
))
||
x
<
(
min
(
l
(
1
:
2
)))
||
...
x
>
max
(
k
(
1
:
2
))
||
x
<
(
min
(
k
(
1
:
2
))))
intersection
=
[];
else
intersection
=
[
x
,
a
*
x
+
b
];
end
end
end
function
[
intersection
]
=
intersection_between_inclusive
(
k
,
kIsVertical
,
l
,
lIsVertical
,
between
)
%intersection_between_inclusive Calculates intersections of two lines.
% The lines are specified by two sets of points. If between is true, an empty value is returned if the intersection
%is outside the endpoints of either one of the lines
% lines in format [x1, y1; x2, y2]
% [11, 12; 21, 22]
% line k = ax + b, l = cx + d
% vk = true iff k vertical
if
kIsVertical
c
=
(
l
(
2
,
2
)
-
l
(
1
,
2
))
/
(
l
(
2
,
1
)
-
l
(
1
,
1
));
d
=
l
(
1
,
2
)
-
c
*
l
(
1
,
1
);
y
=
c
*
k
(
1
)
+
d
;
if
isnan
(
y
)
if
lIsVertical
intersection
=
[];
else
error
(
'non-parallel lines did not intersect'
);
end
elseif
between
&&
(
y
>
max
(
k
(
3
:
4
))
||
y
<
min
(
k
(
3
:
4
))
||
...
y
>
max
(
l
(
3
:
4
))
||
y
<
min
(
l
(
3
:
4
)))
intersection
=
[];
else
intersection
=
[
k
(
1
),
y
];
end
elseif
lIsVertical
a
=
(
k
(
2
,
2
)
-
k
(
1
,
2
))
/
(
k
(
2
,
1
)
-
k
(
1
,
1
));
b
=
k
(
1
,
2
)
-
a
*
k
(
1
,
1
);
x
=
l
(
1
);
y
=
a
*
x
+
b
;
if
between
&&
(
y
>
max
(
l
(
3
:
4
))
||
y
<
min
(
l
(
3
:
4
))
||
...
y
>
max
(
k
(
3
:
4
))
||
y
<
min
(
k
(
3
:
4
)))
intersection
=
[];
else
intersection
=
[
x
,
y
];
end
else
a
=
(
k
(
2
,
2
)
-
k
(
1
,
2
))
/
(
k
(
2
,
1
)
-
k
(
1
,
1
));
c
=
(
l
(
2
,
2
)
-
l
(
1
,
2
))
/
(
l
(
2
,
1
)
-
l
(
1
,
1
));
b
=
k
(
1
,
2
)
-
a
*
k
(
1
,
1
);
d
=
l
(
1
,
2
)
-
c
*
l
(
1
,
1
);
x
=
(
d
-
b
)/(
a
-
c
);
if
between
&&
(
x
>
max
(
l
(
1
:
2
))
||
x
<
min
(
l
(
1
:
2
))
||
...
x
>
max
(
k
(
1
:
2
))
||
x
<
min
(
k
(
1
:
2
)))
intersection
=
[];
else
intersection
=
[
x
,
a
*
x
+
b
];
end
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment