fixed orientation bug

This commit is contained in:
zzzzrrr 2009-08-05 11:25:56 -04:00
parent 456a6a8d15
commit ae5cf98122
2 changed files with 36 additions and 11 deletions

View File

@ -124,7 +124,7 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
// Implement sweep-line // Implement sweep-line
private def sweep { private def sweep {
for(i <- 1 until 10 /*points.size*/) { for(i <- 1 until points.size) {
val point = points(i) val point = points(i)
// Process Point event // Process Point event
val triangle = pointEvent(point) val triangle = pointEvent(point)
@ -334,7 +334,19 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
val v2 = p1 - p2 val v2 = p1 - p2
val v3 = p1 - p4 val v3 = p1 - p4
val v4 = p3 - p4 val v4 = p3 - p4
if((v1 dot v2) < 0 && (v3 dot v4) < 0)
val cosA = v1 dot v2
val cosB = v3 dot v4
if(cosA < 0 && cosB < 0)
return true
else if(cosA > 0 && cosB > 0)
return false
val sinA = v1 cross v2
val sinB = v3 cross v4
if(cosA*sinB + sinA*cosB < -0.01f)
true true
else else
false false

View File

@ -118,15 +118,28 @@ class Triangle(val points: Array[Point], val neighbors: Array[Triangle]) {
// Locate next triangle crossed by constraied edge // Locate next triangle crossed by constraied edge
def findNeighbor(e: Point): Triangle = { def findNeighbor(e: Point): Triangle = {
var sameSign = Math.signum(ik cross e) == Math.signum(ij cross e) if(orient(points(0), points(1), e) > 0)
if(!sameSign) return neighbors(0) return neighbors(2)
sameSign = Math.signum(jk cross e) == Math.signum(ji cross e) if(orient(points(1), points(2), e) > 0)
if(!sameSign) return neighbors(1) return neighbors(0)
sameSign = Math.signum(kj cross e) == Math.signum(ki cross e) if(orient(points(2), points(0), e) > 0)
if(!sameSign) return neighbors(2) return neighbors(1)
else
// Point must reside inside this triangle
this this
} }
// Return: positive if point p is left of ab
// negative if point p is right of ab
// zero if points are colinear
def orient(b: Point, a: Point, p: Point): Float = {
val acx = a.x - p.x
val bcx = b.x - p.x
val acy = a.y - p.y
val bcy = b.y - p.y
acx * bcy - acy * bcx
}
// The neighbor CW to given point // The neighbor CW to given point
def neighborCW(point: Point): Triangle = { def neighborCW(point: Point): Triangle = {
if(point == points(0)) { if(point == points(0)) {