WIP line tests
This commit is contained in:
parent
997f23dfb5
commit
8cd352b7a3
14
geometry.go
14
geometry.go
|
@ -222,17 +222,10 @@ func (l Line) Closest(v Vec) Vec {
|
||||||
m, b := l.Formula()
|
m, b := l.Formula()
|
||||||
perpendicularM := -1 / m
|
perpendicularM := -1 / m
|
||||||
perpendicularB := v.Y - (perpendicularM * v.X)
|
perpendicularB := v.Y - (perpendicularM * v.X)
|
||||||
fmt.Println(m)
|
|
||||||
fmt.Println(b)
|
|
||||||
fmt.Println(perpendicularM)
|
|
||||||
fmt.Println(perpendicularB)
|
|
||||||
|
|
||||||
// Coordinates of intersect (of infinite lines)
|
// Coordinates of intersect (of infinite lines)
|
||||||
x := (perpendicularB - b) / (m - perpendicularM)
|
x := (perpendicularB - b) / (m - perpendicularM)
|
||||||
y := m*x - b
|
y := m*x + b
|
||||||
|
|
||||||
fmt.Println(x)
|
|
||||||
fmt.Println(y)
|
|
||||||
|
|
||||||
return V(x, y)
|
return V(x, y)
|
||||||
}
|
}
|
||||||
|
@ -253,11 +246,9 @@ func (l Line) Formula() (m, b float64) {
|
||||||
// Intersect will return the point of intersection for the two line segments. If the line segments do not intersect,
|
// Intersect will return the point of intersection for the two line segments. If the line segments do not intersect,
|
||||||
// this function will return the zero-vector and `false`.
|
// this function will return the zero-vector and `false`.
|
||||||
func (l Line) Intersect(k Line) (Vec, bool) {
|
func (l Line) Intersect(k Line) (Vec, bool) {
|
||||||
fmt.Printf("%v, %v\n", l, k)
|
|
||||||
// Check if the lines are parallel
|
// Check if the lines are parallel
|
||||||
lDir := l.A.To(l.B)
|
lDir := l.A.To(l.B)
|
||||||
kDir := k.A.To(k.B)
|
kDir := k.A.To(k.B)
|
||||||
fmt.Printf("%v, %v\n", lDir, kDir)
|
|
||||||
if lDir.X == kDir.X && lDir.Y == kDir.Y {
|
if lDir.X == kDir.X && lDir.Y == kDir.Y {
|
||||||
fmt.Println("p")
|
fmt.Println("p")
|
||||||
return ZV, false
|
return ZV, false
|
||||||
|
@ -268,13 +259,10 @@ func (l Line) Intersect(k Line) (Vec, bool) {
|
||||||
// segments
|
// segments
|
||||||
lm, lb := l.Formula()
|
lm, lb := l.Formula()
|
||||||
km, kb := k.Formula()
|
km, kb := k.Formula()
|
||||||
fmt.Printf("%.2f, %.2f -- %.2f, %.2f\n", lm, lb, km, kb)
|
|
||||||
|
|
||||||
// Coordinates of intersect
|
// Coordinates of intersect
|
||||||
x := (kb - lb) / (lm - km)
|
x := (kb - lb) / (lm - km)
|
||||||
y := lm*x + lb
|
y := lm*x + lb
|
||||||
fmt.Printf("(%.2f, %.2f)\n", x, y)
|
|
||||||
fmt.Printf("%t %t\n", l.Contains(V(x, y)), k.Contains(V(x, y)))
|
|
||||||
|
|
||||||
if l.Contains(V(x, y)) && k.Contains(V(x, y)) {
|
if l.Contains(V(x, y)) && k.Contains(V(x, y)) {
|
||||||
// The intersect point is on both line segments, they intersect.
|
// The intersect point is on both line segments, they intersect.
|
||||||
|
|
Loading…
Reference in New Issue