Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
53f83f79
Commit
53f83f79
authored
Sep 23, 2015
by
Viktor Lidholt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds method for calculating intersection between two lines
parent
130a5cb6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
0 deletions
+25
-0
util.dart
packages/flutter_sprites/lib/util.dart
+25
-0
No files found.
packages/flutter_sprites/lib/util.dart
View file @
53f83f79
...
...
@@ -105,4 +105,29 @@ class GameMath {
static
Point
filterPoint
(
Point
a
,
Point
b
,
double
filterFactor
)
{
return
new
Point
(
filter
(
a
.
x
,
b
.
x
,
filterFactor
),
filter
(
a
.
y
,
b
.
y
,
filterFactor
));
}
static
Point
lineIntersection
(
Point
p
,
Point
p2
,
Point
q
,
Point
q2
)
{
double
epsilon
=
1
e
-
10
;
Vector2
r
=
new
Vector2
(
p2
.
x
-
p
.
x
,
p2
.
y
-
p
.
y
);
Vector2
s
=
new
Vector2
(
q2
.
x
-
q
.
x
,
q2
.
y
-
q
.
y
);
Vector2
qp
=
new
Vector2
(
q
.
x
-
p
.
x
,
q
.
y
-
p
.
y
);
double
rxs
=
cross2
(
r
,
s
);
if
(
rxs
.
abs
()
<
epsilon
)
{
// The lines are linear or collinear
return
null
;
}
double
t
=
cross2
(
qp
,
s
)
/
rxs
;
double
u
=
cross2
(
qp
,
r
)
/
rxs
;
if
((
0.0
<=
t
&&
t
<=
1.0
)
&&
(
0.0
<=
u
&&
u
<=
1.0
))
{
return
new
Point
(
p
.
x
+
t
*
r
.
x
,
p
.
y
+
t
*
r
.
y
);
}
// No intersection between the lines
return
null
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment