Решение на Пресичания от Исмаил Алиджиков

Обратно към всички решения

Към профила на Исмаил Алиджиков

Резултати

  • 9 точки от тестове
  • 0 бонус точки
  • 9 точки общо
  • 18 успешни тест(а)
  • 2 неуспешни тест(а)

Код

package main
import (
"math"
"github.com/fmi/go-homework/geom"
)
const EPSILON float64 = 0.00000001
type Triangle struct {
A, B, C geom.Vector
}
func NewTriangle(a, b, c geom.Vector) Triangle {
return Triangle{
A: a,
B: b,
C: c,
}
}
func (t Triangle) Intersect(ray geom.Ray) bool {
u := subtract(t.B, t.A)
v := subtract(t.C, t.A)
n := crossProduct(u, v)
direction := subtract(ray.Direction, ray.Origin)
b := dot(n, direction)
if math.Abs(b) < EPSILON {
return false
}
w0 := subtract(ray.Origin, t.A)
a := dot(n, w0) * -1
r := a / b
if r < 0.0 {
return false
}
// Intersection point
i := add(ray.Origin, scalarProduct(r, direction))
uu := dot(u, u)
uv := dot(u, v)
vv := dot(v, v)
w := subtract(i, t.A)
wu := dot(w, u)
wv := dot(w, v)
d := uv*uv - uu*vv
s := (uv*wv - vv*wu) / d
if s < 0.0 || s > 1.0 {
return false
}
p := (uv*wu - uu*wv) / d
if p < 0.0 || (s+p) > 1.0 {
return false
}
return true
}
type Quad struct {
A, B, C, D geom.Vector
}
func NewQuad(a, b, c, d geom.Vector) Quad {
return Quad{
A: a,
B: b,
C: c,
D: d,
}
}
func (q Quad) Intersect(ray geom.Ray) bool {
var left, right Triangle
if approximateSurface(q.A, q.C, q.B)*approximateSurface(q.A, q.C, q.D) < 0.0 {
left = NewTriangle(q.A, q.B, q.C)
right = NewTriangle(q.A, q.D, q.C)
} else {
left = NewTriangle(q.B, q.D, q.C)
right = NewTriangle(q.B, q.D, q.A)
}
return left.Intersect(ray) || right.Intersect(ray)
}
type Sphere struct {
Origin geom.Vector
R float64
}
func NewSphere(origin geom.Vector, r float64) Sphere {
return Sphere{
Origin: origin,
R: r,
}
}
func (s Sphere) Intersect(ray geom.Ray) bool {
v := subtract(ray.Origin, s.Origin)
b := 2 * dot(v, ray.Direction)
c := dot(v, v) - s.R*s.R
discriminant := b*b - 4*c
if discriminant < 0 {
return false
}
tMinus := (-b - math.Sqrt(discriminant)) / 2.0
tPlus := (-b + math.Sqrt(discriminant)) / 2.0
if tMinus < 0 && tPlus < 0 {
return false
}
return true
}
func add(v, p geom.Vector) geom.Vector {
return geom.NewVector(v.X+p.X, v.Y+p.Y, v.Z+p.Z)
}
func subtract(v, p geom.Vector) geom.Vector {
return geom.NewVector(v.X-p.X, v.Y-p.Y, v.Z-p.Z)
}
func scalarProduct(s float64, v geom.Vector) geom.Vector {
return geom.NewVector(s*v.X, s*v.Y, s*v.Z)
}
func crossProduct(v, p geom.Vector) geom.Vector {
x := v.Y*p.Z - v.Z*p.Y
y := v.Z*p.X - v.X*p.Z
z := v.X*p.Y - v.Y*p.X
return geom.NewVector(x, y, z)
}
func dot(v, p geom.Vector) float64 {
return v.X*p.X + v.Y*p.Y + v.Z*p.Z
}
func approximateSurface(a, b, c geom.Vector) float64 {
return approximateVector(a, b) + approximateVector(b, c) + approximateVector(c, a)
}
func approximateVector(a, b geom.Vector) float64 {
return (a.X - b.X) * (a.Y + b.Y) / 2.0
}

Лог от изпълнението

PASS
ok  	_/tmp/d20181122-57-1whm7zl	0.002s
PASS
ok  	_/tmp/d20181122-57-1whm7zl	0.002s
PASS
ok  	_/tmp/d20181122-57-1whm7zl	0.002s
PASS
ok  	_/tmp/d20181122-57-1whm7zl	0.002s
PASS
ok  	_/tmp/d20181122-57-1whm7zl	0.002s
PASS
ok  	_/tmp/d20181122-57-1whm7zl	0.002s
PASS
ok  	_/tmp/d20181122-57-1whm7zl	0.002s
PASS
ok  	_/tmp/d20181122-57-1whm7zl	0.002s
PASS
ok  	_/tmp/d20181122-57-1whm7zl	0.002s
PASS
ok  	_/tmp/d20181122-57-1whm7zl	0.002s
PASS
ok  	_/tmp/d20181122-57-1whm7zl	0.002s
PASS
ok  	_/tmp/d20181122-57-1whm7zl	0.002s
PASS
ok  	_/tmp/d20181122-57-1whm7zl	0.002s
PASS
ok  	_/tmp/d20181122-57-1whm7zl	0.002s
--- FAIL: TestQuadThirdIrregularHit (0.00s)
    solution_test.go:206: Expected intersection to be true but it was not
FAIL
exit status 1
FAIL	_/tmp/d20181122-57-1whm7zl	0.002s
PASS
ok  	_/tmp/d20181122-57-1whm7zl	0.002s
PASS
ok  	_/tmp/d20181122-57-1whm7zl	0.002s
PASS
ok  	_/tmp/d20181122-57-1whm7zl	0.002s
PASS
ok  	_/tmp/d20181122-57-1whm7zl	0.002s
--- FAIL: TestSphereNearMiss (0.00s)
    solution_test.go:206: Expected intersection to be false but it was not
FAIL
exit status 1
FAIL	_/tmp/d20181122-57-1whm7zl	0.002s

История (5 версии и 1 коментар)

Исмаил обнови решението на 18.11.2018 20:35 (преди 9 месеца)

+package main
+
+import (
+ "math"
+
+ "github.com/fmi/go-homework/geom"
+)
+
+const EPSILON float64 = 0.00000001
+
+func add(v, p geom.Vector) geom.Vector {
+ return geom.NewVector(v.X+p.X, v.Y+p.Y, v.Z+p.Z)
+}
+
+func subtract(v, p geom.Vector) geom.Vector {
+ return geom.NewVector(v.X-p.X, v.Y-p.Y, v.Z-p.Z)
+}
+
+func scalarProduct(s float64, v geom.Vector) geom.Vector {
+ return geom.NewVector(s*v.X, s*v.Y, s*v.Z)
+}
+
+func crossProduct(v, p geom.Vector) geom.Vector {
+ x := v.Y*p.Z - v.Z*p.Y
+ y := v.Z*p.X - v.X*p.Z
+ z := v.X*p.Y - v.Y*p.X
+
+ return geom.NewVector(x, y, z)
+}
+
+func dot(v, p geom.Vector) float64 {
+ return v.X*p.X + v.Y*p.Y + v.Z*p.Z
+}
+
+type Triangle struct {
+ a, b, c geom.Vector
+}
+
+type Quad struct {
+ a, b, c, d geom.Vector
+}
+
+type Sphere struct {
+ origin geom.Vector
+ r float64
+}
+
+func (t Triangle) Intersect(ray geom.Ray) bool {
+ u := subtract(t.b, t.a)
+ v := subtract(t.c, t.a)
+
+ n := crossProduct(u, v)
+
+ direction := subtract(ray.Direction, ray.Origin)
+ b := dot(n, direction)
+
+ if math.Abs(b) < EPSILON {
+ return false
+ }
+
+ w0 := subtract(ray.Origin, t.a)
+ a := dot(n, w0) * -1
+ r := a / b
+ if r < 0.0 {
+ return false
+ }
+
+ // Intersection point
+ i := add(ray.Origin, scalarProduct(r, direction))
+
+ uu := dot(u, u)
+ uv := dot(u, v)
+ vv := dot(v, v)
+ w := subtract(i, t.a)
+ wu := dot(w, u)
+ wv := dot(w, v)
+ d := uv*uv - uu*vv
+
+ s := (uv*wv - vv*wu) / d
+ if s < 0.0 || s > 1.0 {
+ return false
+ }
+
+ p := (uv*wu - uu*wv) / d
+ if p < 0.0 || (s+p) > 1.0 {
+ return false
+ }
+
+ return true
+}
+
+func (q Quad) Intersect(ray geom.Ray) bool {
+ abc := NewTriangle(q.a, q.b, q.c)
+ bcd := NewTriangle(q.b, q.c, q.d)
+
+ return abc.Intersect(ray) || bcd.Intersect(ray)
+}
+
+func (s Sphere) Intersect(ray geom.Ray) bool {
+ v := subtract(ray.Origin, s.origin)
+ b := 2 * dot(v, ray.Direction)
+ c := dot(v, v) - s.r*s.r
+ discriminant := b*b - 4*c
+
+ if discriminant < 0 {
+ return false
+ }
+
+ tMinus := (-b - math.Sqrt(discriminant)) / 2.0
+ tPlus := (-b + math.Sqrt(discriminant)) / 2.0
+
+ if tMinus < 0 && tPlus < 0 {
+ return false
+ }
+
+ return true
+}
+
+func NewTriangle(a, b, c geom.Vector) Triangle {
+ return Triangle{
+ a: a,
+ b: b,
+ c: c,
+ }
+}
+
+func NewQuad(a, b, c, d geom.Vector) Quad {
+ return Quad{
+ a: a,
+ b: b,
+ c: c,
+ d: d,
+ }
+}
+
+func NewSphere(origin geom.Vector, r float64) Sphere {
+ return Sphere{
+ origin: origin,
+ r: r,
+ }
+}

Исмаил обнови решението на 19.11.2018 23:21 (преди 9 месеца)

package main
import (
"math"
"github.com/fmi/go-homework/geom"
)
const EPSILON float64 = 0.00000001
func add(v, p geom.Vector) geom.Vector {
return geom.NewVector(v.X+p.X, v.Y+p.Y, v.Z+p.Z)
}
func subtract(v, p geom.Vector) geom.Vector {
return geom.NewVector(v.X-p.X, v.Y-p.Y, v.Z-p.Z)
}
func scalarProduct(s float64, v geom.Vector) geom.Vector {
return geom.NewVector(s*v.X, s*v.Y, s*v.Z)
}
func crossProduct(v, p geom.Vector) geom.Vector {
x := v.Y*p.Z - v.Z*p.Y
y := v.Z*p.X - v.X*p.Z
z := v.X*p.Y - v.Y*p.X
return geom.NewVector(x, y, z)
}
func dot(v, p geom.Vector) float64 {
return v.X*p.X + v.Y*p.Y + v.Z*p.Z
}
type Triangle struct {
a, b, c geom.Vector
}
type Quad struct {
a, b, c, d geom.Vector
}
type Sphere struct {
origin geom.Vector
r float64
}
func (t Triangle) Intersect(ray geom.Ray) bool {
u := subtract(t.b, t.a)
v := subtract(t.c, t.a)
n := crossProduct(u, v)
direction := subtract(ray.Direction, ray.Origin)
b := dot(n, direction)
if math.Abs(b) < EPSILON {
return false
}
w0 := subtract(ray.Origin, t.a)
a := dot(n, w0) * -1
r := a / b
if r < 0.0 {
return false
}
// Intersection point
i := add(ray.Origin, scalarProduct(r, direction))
uu := dot(u, u)
uv := dot(u, v)
vv := dot(v, v)
w := subtract(i, t.a)
wu := dot(w, u)
wv := dot(w, v)
d := uv*uv - uu*vv
s := (uv*wv - vv*wu) / d
if s < 0.0 || s > 1.0 {
return false
}
p := (uv*wu - uu*wv) / d
if p < 0.0 || (s+p) > 1.0 {
return false
}
return true
}
func (q Quad) Intersect(ray geom.Ray) bool {
abc := NewTriangle(q.a, q.b, q.c)
- bcd := NewTriangle(q.b, q.c, q.d)
+ adc := NewTriangle(q.a, q.d, q.c)
- return abc.Intersect(ray) || bcd.Intersect(ray)
+ return abc.Intersect(ray) || adc.Intersect(ray)
}
func (s Sphere) Intersect(ray geom.Ray) bool {
v := subtract(ray.Origin, s.origin)
b := 2 * dot(v, ray.Direction)
c := dot(v, v) - s.r*s.r
discriminant := b*b - 4*c
if discriminant < 0 {
return false
}
tMinus := (-b - math.Sqrt(discriminant)) / 2.0
tPlus := (-b + math.Sqrt(discriminant)) / 2.0
if tMinus < 0 && tPlus < 0 {
return false
}
return true
}
func NewTriangle(a, b, c geom.Vector) Triangle {
return Triangle{
a: a,
b: b,
c: c,
}
}
func NewQuad(a, b, c, d geom.Vector) Quad {
return Quad{
a: a,
b: b,
c: c,
d: d,
}
}
func NewSphere(origin geom.Vector, r float64) Sphere {
return Sphere{
origin: origin,
r: r,
}
}

Подреждането на файла ти е малко странно. Бих го направил така:

  • Тип
  • Конструктор функция на типа
  • Методи на типа
  • Следващ тип
  • Конструктор функция на типа
  • ...

В момента файла е разхвърлян. Типовете са размесени един през друг и трудно се следи кода.

Исмаил обнови решението на 20.11.2018 11:13 (преди 9 месеца)

package main
import (
"math"
"github.com/fmi/go-homework/geom"
)
const EPSILON float64 = 0.00000001
-func add(v, p geom.Vector) geom.Vector {
- return geom.NewVector(v.X+p.X, v.Y+p.Y, v.Z+p.Z)
-}
+type Vector geom.Vector
-func subtract(v, p geom.Vector) geom.Vector {
- return geom.NewVector(v.X-p.X, v.Y-p.Y, v.Z-p.Z)
-}
-
-func scalarProduct(s float64, v geom.Vector) geom.Vector {
- return geom.NewVector(s*v.X, s*v.Y, s*v.Z)
-}
-
-func crossProduct(v, p geom.Vector) geom.Vector {
- x := v.Y*p.Z - v.Z*p.Y
- y := v.Z*p.X - v.X*p.Z
- z := v.X*p.Y - v.Y*p.X
-
- return geom.NewVector(x, y, z)
-}
-
-func dot(v, p geom.Vector) float64 {
- return v.X*p.X + v.Y*p.Y + v.Z*p.Z
-}
-
type Triangle struct {
- a, b, c geom.Vector
+ A, B, C geom.Vector
}
-type Quad struct {
- a, b, c, d geom.Vector
+func NewTriangle(a, b, c geom.Vector) Triangle {
+ return Triangle{
+ A: a,
+ B: b,
+ C: c,
+ }
}
-type Sphere struct {
- origin geom.Vector
- r float64
-}
-
func (t Triangle) Intersect(ray geom.Ray) bool {
- u := subtract(t.b, t.a)
- v := subtract(t.c, t.a)
+ u := subtract(t.B, t.A)
+ v := subtract(t.C, t.A)
n := crossProduct(u, v)
direction := subtract(ray.Direction, ray.Origin)
b := dot(n, direction)
if math.Abs(b) < EPSILON {
return false
}
- w0 := subtract(ray.Origin, t.a)
+ w0 := subtract(ray.Origin, t.A)
a := dot(n, w0) * -1
r := a / b
if r < 0.0 {
return false
}
// Intersection point
i := add(ray.Origin, scalarProduct(r, direction))
uu := dot(u, u)
uv := dot(u, v)
vv := dot(v, v)
- w := subtract(i, t.a)
+ w := subtract(i, t.A)
wu := dot(w, u)
wv := dot(w, v)
d := uv*uv - uu*vv
s := (uv*wv - vv*wu) / d
if s < 0.0 || s > 1.0 {
return false
}
p := (uv*wu - uu*wv) / d
if p < 0.0 || (s+p) > 1.0 {
return false
}
return true
}
+type Quad struct {
+ A, B, C, D geom.Vector
+}
+
+func NewQuad(a, b, c, d geom.Vector) Quad {
+ return Quad{
+ A: a,
+ B: b,
+ C: c,
+ D: d,
+ }
+}
+
func (q Quad) Intersect(ray geom.Ray) bool {
- abc := NewTriangle(q.a, q.b, q.c)
- adc := NewTriangle(q.a, q.d, q.c)
+ abc := NewTriangle(q.A, q.B, q.C)
+ adc := NewTriangle(q.A, q.D, q.C)
return abc.Intersect(ray) || adc.Intersect(ray)
}
+type Sphere struct {
+ Origin geom.Vector
+ R float64
+}
+
+func NewSphere(origin geom.Vector, r float64) Sphere {
+ return Sphere{
+ Origin: origin,
+ R: r,
+ }
+}
+
func (s Sphere) Intersect(ray geom.Ray) bool {
- v := subtract(ray.Origin, s.origin)
+ v := subtract(ray.Origin, s.Origin)
b := 2 * dot(v, ray.Direction)
- c := dot(v, v) - s.r*s.r
+ c := dot(v, v) - s.R*s.R
discriminant := b*b - 4*c
if discriminant < 0 {
return false
}
tMinus := (-b - math.Sqrt(discriminant)) / 2.0
tPlus := (-b + math.Sqrt(discriminant)) / 2.0
if tMinus < 0 && tPlus < 0 {
return false
}
return true
}
-func NewTriangle(a, b, c geom.Vector) Triangle {
- return Triangle{
- a: a,
- b: b,
- c: c,
- }
+func add(v, p geom.Vector) geom.Vector {
+ return geom.NewVector(v.X+p.X, v.Y+p.Y, v.Z+p.Z)
}
-func NewQuad(a, b, c, d geom.Vector) Quad {
- return Quad{
- a: a,
- b: b,
- c: c,
- d: d,
- }
+func subtract(v, p geom.Vector) geom.Vector {
+ return geom.NewVector(v.X-p.X, v.Y-p.Y, v.Z-p.Z)
}
-func NewSphere(origin geom.Vector, r float64) Sphere {
- return Sphere{
- origin: origin,
- r: r,
- }
+func scalarProduct(s float64, v geom.Vector) geom.Vector {
+ return geom.NewVector(s*v.X, s*v.Y, s*v.Z)
+}
+
+func crossProduct(v, p geom.Vector) geom.Vector {
+ x := v.Y*p.Z - v.Z*p.Y
+ y := v.Z*p.X - v.X*p.Z
+ z := v.X*p.Y - v.Y*p.X
+
+ return geom.NewVector(x, y, z)
+}
+
+func dot(v, p geom.Vector) float64 {
+ return v.X*p.X + v.Y*p.Y + v.Z*p.Z
}

Исмаил обнови решението на 20.11.2018 11:45 (преди 9 месеца)

package main
import (
"math"
"github.com/fmi/go-homework/geom"
)
const EPSILON float64 = 0.00000001
-type Vector geom.Vector
-
type Triangle struct {
A, B, C geom.Vector
}
func NewTriangle(a, b, c geom.Vector) Triangle {
return Triangle{
A: a,
B: b,
C: c,
}
}
func (t Triangle) Intersect(ray geom.Ray) bool {
u := subtract(t.B, t.A)
v := subtract(t.C, t.A)
n := crossProduct(u, v)
direction := subtract(ray.Direction, ray.Origin)
b := dot(n, direction)
if math.Abs(b) < EPSILON {
return false
}
w0 := subtract(ray.Origin, t.A)
a := dot(n, w0) * -1
r := a / b
if r < 0.0 {
return false
}
// Intersection point
i := add(ray.Origin, scalarProduct(r, direction))
uu := dot(u, u)
uv := dot(u, v)
vv := dot(v, v)
w := subtract(i, t.A)
wu := dot(w, u)
wv := dot(w, v)
d := uv*uv - uu*vv
s := (uv*wv - vv*wu) / d
if s < 0.0 || s > 1.0 {
return false
}
p := (uv*wu - uu*wv) / d
if p < 0.0 || (s+p) > 1.0 {
return false
}
return true
}
type Quad struct {
A, B, C, D geom.Vector
}
func NewQuad(a, b, c, d geom.Vector) Quad {
return Quad{
A: a,
B: b,
C: c,
D: d,
}
}
func (q Quad) Intersect(ray geom.Ray) bool {
abc := NewTriangle(q.A, q.B, q.C)
adc := NewTriangle(q.A, q.D, q.C)
return abc.Intersect(ray) || adc.Intersect(ray)
}
type Sphere struct {
Origin geom.Vector
R float64
}
func NewSphere(origin geom.Vector, r float64) Sphere {
return Sphere{
Origin: origin,
R: r,
}
}
func (s Sphere) Intersect(ray geom.Ray) bool {
v := subtract(ray.Origin, s.Origin)
b := 2 * dot(v, ray.Direction)
c := dot(v, v) - s.R*s.R
discriminant := b*b - 4*c
if discriminant < 0 {
return false
}
tMinus := (-b - math.Sqrt(discriminant)) / 2.0
tPlus := (-b + math.Sqrt(discriminant)) / 2.0
if tMinus < 0 && tPlus < 0 {
return false
}
return true
}
func add(v, p geom.Vector) geom.Vector {
return geom.NewVector(v.X+p.X, v.Y+p.Y, v.Z+p.Z)
}
func subtract(v, p geom.Vector) geom.Vector {
return geom.NewVector(v.X-p.X, v.Y-p.Y, v.Z-p.Z)
}
func scalarProduct(s float64, v geom.Vector) geom.Vector {
return geom.NewVector(s*v.X, s*v.Y, s*v.Z)
}
func crossProduct(v, p geom.Vector) geom.Vector {
x := v.Y*p.Z - v.Z*p.Y
y := v.Z*p.X - v.X*p.Z
z := v.X*p.Y - v.Y*p.X
return geom.NewVector(x, y, z)
}
func dot(v, p geom.Vector) float64 {
return v.X*p.X + v.Y*p.Y + v.Z*p.Z
}

Исмаил обнови решението на 21.11.2018 00:07 (преди 9 месеца)

package main
import (
"math"
"github.com/fmi/go-homework/geom"
)
const EPSILON float64 = 0.00000001
type Triangle struct {
A, B, C geom.Vector
}
func NewTriangle(a, b, c geom.Vector) Triangle {
return Triangle{
A: a,
B: b,
C: c,
}
}
func (t Triangle) Intersect(ray geom.Ray) bool {
u := subtract(t.B, t.A)
v := subtract(t.C, t.A)
n := crossProduct(u, v)
direction := subtract(ray.Direction, ray.Origin)
b := dot(n, direction)
if math.Abs(b) < EPSILON {
return false
}
w0 := subtract(ray.Origin, t.A)
a := dot(n, w0) * -1
r := a / b
if r < 0.0 {
return false
}
// Intersection point
i := add(ray.Origin, scalarProduct(r, direction))
uu := dot(u, u)
uv := dot(u, v)
vv := dot(v, v)
w := subtract(i, t.A)
wu := dot(w, u)
wv := dot(w, v)
d := uv*uv - uu*vv
s := (uv*wv - vv*wu) / d
if s < 0.0 || s > 1.0 {
return false
}
p := (uv*wu - uu*wv) / d
if p < 0.0 || (s+p) > 1.0 {
return false
}
return true
}
type Quad struct {
A, B, C, D geom.Vector
}
func NewQuad(a, b, c, d geom.Vector) Quad {
return Quad{
A: a,
B: b,
C: c,
D: d,
}
}
func (q Quad) Intersect(ray geom.Ray) bool {
- abc := NewTriangle(q.A, q.B, q.C)
- adc := NewTriangle(q.A, q.D, q.C)
+ var left, right Triangle
+ if approximateSurface(q.A, q.C, q.B)*approximateSurface(q.A, q.C, q.D) < 0.0 {
+ left = NewTriangle(q.A, q.B, q.C)
+ right = NewTriangle(q.A, q.D, q.C)
+ } else {
+ left = NewTriangle(q.B, q.D, q.C)
+ right = NewTriangle(q.B, q.D, q.A)
+ }
- return abc.Intersect(ray) || adc.Intersect(ray)
+ return left.Intersect(ray) || right.Intersect(ray)
}
type Sphere struct {
Origin geom.Vector
R float64
}
func NewSphere(origin geom.Vector, r float64) Sphere {
return Sphere{
Origin: origin,
R: r,
}
}
func (s Sphere) Intersect(ray geom.Ray) bool {
v := subtract(ray.Origin, s.Origin)
b := 2 * dot(v, ray.Direction)
c := dot(v, v) - s.R*s.R
discriminant := b*b - 4*c
if discriminant < 0 {
return false
}
tMinus := (-b - math.Sqrt(discriminant)) / 2.0
tPlus := (-b + math.Sqrt(discriminant)) / 2.0
if tMinus < 0 && tPlus < 0 {
return false
}
return true
}
func add(v, p geom.Vector) geom.Vector {
return geom.NewVector(v.X+p.X, v.Y+p.Y, v.Z+p.Z)
}
func subtract(v, p geom.Vector) geom.Vector {
return geom.NewVector(v.X-p.X, v.Y-p.Y, v.Z-p.Z)
}
func scalarProduct(s float64, v geom.Vector) geom.Vector {
return geom.NewVector(s*v.X, s*v.Y, s*v.Z)
}
func crossProduct(v, p geom.Vector) geom.Vector {
x := v.Y*p.Z - v.Z*p.Y
y := v.Z*p.X - v.X*p.Z
z := v.X*p.Y - v.Y*p.X
return geom.NewVector(x, y, z)
}
func dot(v, p geom.Vector) float64 {
return v.X*p.X + v.Y*p.Y + v.Z*p.Z
+}
+
+func approximateSurface(a, b, c geom.Vector) float64 {
+ return approximateVector(a, b) + approximateVector(b, c) + approximateVector(c, a)
+}
+
+func approximateVector(a, b geom.Vector) float64 {
+ return (a.X - b.X) * (a.Y + b.Y) / 2.0
}