Perhaps someone here could kindly come up with something significantly faster (which I can subsequently and shamelessly nick for a game project) without resorting to assembly language?

(I shall resort to C or assembler if I really have to...)
Code: Select all
REM Delaunay triangulation (slow!)
REM by DW
MODE 12 : OFF
ScrW% = @vdu%!208
ScrH% = @vdu%!212
nPts% = 100
DIM p(nPts%-1,1)
minDist% = 50 : REM No points can be closer than this
R% = RND(-123456)
REM Generate random points (subject to specified minimum distance):
FOR I% = 0 TO nPts%-1
IF I% = 0 THEN
p(I%,0) = ScrW%*RND(1)
p(I%,1) = ScrH%*RND(1)
ELSE
REPEAT
x = ScrW%*RND(1)
y = ScrH%*RND(1)
F% = FALSE
FOR J% = 0 TO I%-1
IF SQR( (x - p(J%,0))^2 + (y - p(J%,1))^2 ) < minDist% THEN
F% = TRUE
EXIT FOR
ENDIF
NEXT J%
UNTIL NOT F%
p(I%,0) = x
p(I%,1) = y
ENDIF
NEXT I%
REM Draw all the points:
GCOL 7
FOR I% = 0 TO nPts%-1
CIRCLE FILL 2*p(I%,0), 2*p(I%,1), 8
NEXT I%
REM Do the triangulation:
GCOL 2
TIME = 0
FOR K% = 0 TO nPts%-3
FOR J% = K%+1 TO nPts%-2
FOR I% = J%+1 TO nPts%-1
PROCcalc_circle( p(I%,0), p(I%,1), p(J%,0), p(J%,1), p(K%,0), p(K%,1), cx, cy, r_sq )
F% = FALSE
FOR L% = 0 TO nPts%-1
IF L%<>I% AND L%<>J% AND L%<>K% THEN
dx = p(L%,0) - cx
dy = p(L%,1) - cy
d_sq = dx*dx + dy*dy
IF d_sq < r_sq THEN
F% = TRUE
EXIT FOR
ENDIF
ENDIF
NEXT L%
IF NOT F% THEN
REM Draw triangle:
LINE 2*p(I%,0), 2*p(I%,1), 2*p(J%,0), 2*p(J%,1)
LINE 2*p(J%,0), 2*p(J%,1), 2*p(K%,0), 2*p(K%,1)
LINE 2*p(K%,0), 2*p(K%,1), 2*p(I%,0), 2*p(I%,1)
ENDIF
NEXT I%
NEXT J%
NEXT K%
T% = TIME
REM Redraw all the points:
GCOL 15
FOR I% = 0 TO nPts%-1
CIRCLE FILL 2*p(I%,0), 2*p(I%,1), 8
NEXT I%
PRINT "Finished!"'
PRINT "That took "; T%/100; " seconds"''
END
DEF PROCcalc_circle( x0, y0, x1, y1, x2, y2, RETURN cx, RETURN cy, RETURN r_sq )
LOCAL m1, m2, n1, n2, midx1, midy1, midx2, midy2, c1, c2
m1 = (y1 - y0) / (x1 - x0)
m2 = (y2 - y0) / (x2 - x0)
n1 = -1 / m1
n2 = -1 / m2
midx1 = (x0 + x1)/2
midy1 = (y0 + y1)/2
midx2 = (x0 + x2)/2
midy2 = (y0 + y2)/2
c1 = midy1 - n1*midx1
c2 = midy2 - n2*midx2
cx = (c2 - c1) / (n1 - n2)
cy = cx*n1 + c1
r_sq = (cx - x0)^2 + (cy - y0)^2
ENDPROC