-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eb8bc70
commit 39dc68c
Showing
6 changed files
with
112 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,20 @@ | ||
package geom | ||
|
||
|
||
/* | ||
A line that goes through Intersection and has a normal Normal. | ||
*/ | ||
type Line struct { | ||
Intersection Coord | ||
Normal Coord | ||
} | ||
|
||
func LineIntersection(l1, l2 Line) (p Coord) { | ||
b1 := l1.Normal.Unit() | ||
b1.RotateRight() | ||
unum := (l2.Normal.X*l2.Intersection.X l2.Normal.Y*l2.Intersection.Y) | ||
uden := (l2.Normal.X*b1.X l2.Normal.Y*b1.Y) | ||
u := unum / uden | ||
p = l1.Intersection.Plus(b1.Times(u)) | ||
return | ||
} |
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,34 @@ | ||
package geom | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
type LineIntersectionTest struct { | ||
l1, l2 Line | ||
p Coord | ||
} | ||
|
||
var itests = []LineIntersectionTest { | ||
{ | ||
Line{ | ||
Intersection: Coord{0, 0}, | ||
Normal: Coord{0, 1}, | ||
}, | ||
Line{ | ||
Intersection: Coord{1, 1}, | ||
Normal: Coord{1, 0}, | ||
}, | ||
Coord{0, 1}, | ||
}, | ||
} | ||
|
||
func TestIntersect(t *testing.T) { | ||
for _, test := range itests { | ||
p := LineIntersection(test.l1, test.l2) | ||
if p != test.p { | ||
t.Error(fmt.Sprintf("should be %v, was %v", test.p, p)) | ||
} | ||
} | ||
} |
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