|
Post by Rod on Apr 7, 2020 16:20:00 GMT
Because we can use the triangles to create a filled polygon of any “normal” description. Either that or the drawer defines the polygon as triangle points instead of just points. Defining the triangles would be some work. Having the routine discover the triangles means you can simply define the external polygon.
Take a square, then a quadrilateral etc
We can line fill it very quickly with Andy’s routine by finding the triangles.
|
|
|
Post by honkytonk on Apr 7, 2020 17:03:27 GMT
To fill curves with triangles it might be long, right?
|
|
|
Post by Rod on Apr 7, 2020 17:26:28 GMT
By definition a polygon is not curved. It may have many facets but it is not curved. Don't get confused with flood filling shapes. This is not what we are discussing.
|
|
|
Post by B+ on Apr 7, 2020 20:47:22 GMT
OK here is a starter: 'PolyFill Test.txt for JB v2.0 B+ 2020-04-07
' Left click a ploygon points around the center of screen going clockwise or counter ' Right click the last point which will connect to first when polygon is drawn and filled ' This is just a simple starter Polygon Maker.
nomainwin global XMAX, YMAX, Xo, Yo, pIndex XMAX = 800 : YMAX = 600 : Xo = 400 : Yo = 300 WindowWidth = XMAX + 8 WindowHeight = YMAX + 32
dim p(100, 1) 'store the polygon points here
open "polyFill test" for graphics_nsb as #gr #gr "when leftButtonUp lButtonUp" #gr "when rightButtonUp rButtonUp" #gr "trapclose quit" #gr "down" #gr "color black" #gr "size 2" call init wait
sub init #gr "fill white" ' clear drawing board #gr "set ";Xo;" ";Yo ' show origin end sub
sub quit h$ close #gr end end sub
sub pause mil 'tsh version has scan built-in t0 = time$("ms") while time$("ms") < t0 + mil : scan : wend end sub
sub lButtonUp H$, mx, my 'must have handle and mouse x,y p(pIndex, 0) = mx : p(pIndex, 1) = my if pIndex = 0 then #gr "set ";mx;" ";my else #gr "line ";mx;" ";my;" ";p(pIndex -1, 0);" ";p(pIndex -1, 1) if pIndex < 100 then pIndex = pIndex + 1 end sub
sub rButtonUp H$, mx, my 'main event finish polygon outline, fill it wait 4 secs start over p(pIndex, 0) = mx : p(pIndex, 1) = my if pIndex = 0 then #H$ "set ";mx;" ";my else #H$ "line ";mx;" ";my;" ";p(pIndex -1, 0);" ";p(pIndex -1, 1) call fillPoly H$, Xo, Yo, pIndex 'finish drawing call pause 35000 '<<< for screen shot ;-)) pIndex = 0 'to build another polygon call init end sub
' p( , ) is the polygon's border, give the x, y origin and nPts ' nPts <<< actually need the top pIndex number (number of Points is 1 more thanks to base 0 arrays). ' set color you want before calling this sub sub fillPoly h$, xOrigin, yOrigin, nPts for i = 0 to nPts -1 call fillTriangle h$, xOrigin, yOrigin, p(i, 0), p(i, 1), p(i + 1, 0), p(i + 1, 1) next call fillTriangle h$, xOrigin, yOrigin, p(0, 0), p(0, 1), p(nPts, 0), p(nPts, 1) end sub
' Title: Filled Triangle Sub 'Programmer: JB port by Andy Amaya ' Date: 2010.10.27 'http://justbasic.conforums.com/index.cgi?board=shared&action=display&num=1307312447 Sub fillTriangle h$, x1, y1, x2, y2, x3, y3 'triangle coordinates must be ordered: where x1 < x2 < x3 If x2 < x1 Then x = x2 : y = y2 : x2 = x1 : y2 = y1 : x1 = x : y1 = y 'swap x1, y1, with x3, y3 If x3 < x1 Then x = x3 : y = y3 : x3 = x1 : y3 = y1 : x1 = x : y1 = y 'swap x2, y2 with x3, y3 If x3 < x2 Then x = x3 : y = y3 : x3 = x2 : y3 = y2 : x2 = x : y2 = y If x1 <> x3 Then slope1 = (y3-y1)/(x3-x1) 'draw the first half of the triangle length = x2 - x1 If length <> 0 Then slope2 = (y2-y1)/(x2-x1) For x = 0 To length #h$ "Line ";Int(x+x1);" ";Int(x*slope1+y1);" ";Int(x+x1);" ";Int(x*slope2+y1) Next End If 'draw the second half of the triangle y = length*slope1+y1 : length = x3-x2 If length <> 0 Then slope3 = (y3-y2)/(x3-x2) For x = 0 To length #h$ "Line ";Int(x+x2);" ";Int(x*slope1+y);" ";Int(x+x2);" ";Int(x*slope3+y2) Next End If End Sub
|
|
|
Post by Rod on Apr 8, 2020 8:41:27 GMT
Absolutely first class. Its fast enough and it seems flexible enough. I need to find time to play with it.
|
|
|
Post by Rod on Apr 8, 2020 14:33:37 GMT
Don't laugh. This is where I got to. Big assumption that you can find the mid point of the polygon and then draw triangles round it by following pairs. But it is a mess. its probably the round the clock ordering that needs attention.
'nomainwin
WindowWidth = 800 WindowHeight = 600 open "filledTriangle" for graphics_nsb as #main #main "trapclose [quit]" #main "down"
'set the drawing color #main "color red"
'triangle point$="100,10,100,50,50,50" call polyfill point$
'square point$="150,20,200,20,200,90,150,90" call polyfill point$
point$="280,20,380,20,370,90,270,90" call polyfill point$
point$="40,150,120,60,100,210,60,230,20,90" call polyfill point$
point$="150,150,200,180,250,150,220,200,200,250,180,210" call polyfill point$ wait
[quit] close #main end
sub polyfill p$ dim p(100,1) wi=1 px$=word$(p$,wi,",") py$=word$(p$,wi+1,",") mix=val(px$) max=val(px$) miy=val(py$) may=val(py$) while px$<>"" and py$<>"" p(pi,0)=val(px$) p(pi,1)=val(py$) 'find min max record it for mid pos if p(pi,0)<=mix then mix=p(pi,0) if p(pi,0)>=max then max=p(pi,0) if p(pi,1)<=miy then miy=p(pi,1) if p(pi,1)>=may then may=p(pi,1) wi=wi+2 pi=pi+1 px$=word$(p$,wi,",") py$=word$(p$,wi+1,",") wend np=pi sort p( 0,np-1,0 xm=int(mix+abs(max-mix)/2) ym=int(miy+abs(may-miy)/2) pi=0 while pi<=np-2 x1=p(pi,0) y1=p(pi,1) x2=p(pi+1,0) y2=p(pi+1,1) call fillTriangle x1,y1,xm,ym,x2,y2 pi=pi+1 wend 'closing triangle x1=p(0,0) y1=p(0,1) x2=p(np-1,0) y2=p(np-1,1) call fillTriangle x1,y1,xm,ym,x2,y2
end sub
'Title: Filled Triangle Sub 'Programmer: JB port by Andy Amaya 'Date: 2010.10.27 Sub fillTriangle x1,y1,x2,y2,x3,y3 print x1,y1,x2,y2,x3,y3
'triangle coordinates must be ordered: where x1 < x2 < x3 If x2 < x1 Then x = x2 : y = y2 : x2 = x1 : y2 = y1 : x1 = x : y1 = y
'swap x1, y1, with x3, y3 If x3 < x1 Then x = x3 : y = y3 : x3 = x1 : y3 = y1 : x1 = x : y1 = y
'swap x2, y2 with x3, y3 If x3 < x2 Then x = x3 : y = y3 : x3 = x2 : y3 = y2 : x2 = x : y2 = y
If x1 <> x3 Then slope1 = (y3-y1)/(x3-x1)
'draw the first half of the triangle length = x2 - x1 If length <> 0 Then slope2 = (y2-y1)/(x2-x1) For x = 0 To length #main "Line ";Int(x+x1);" ";Int(x*slope1+y1);" ";Int(x+x1);" ";Int(x*slope2+y1) Next End If end sub
|
|
|
Post by B+ on Apr 8, 2020 15:45:54 GMT
You know I was just considering a random set of points (for boundary). Not hard at all to order them clockwise or counter. Now that I think of it why not average x's and y's for a center? The center is there of max, min of x's and y's? OK I have my theory and hypothesis to test. Oh yeah! Of course, use a string to hold the points and WORD$ to parse it! One parameter, beautiful!
|
|
|
Post by honkytonk on Apr 8, 2020 16:02:29 GMT
OK here is a starter: 'PolyFill Test.txt for JB v2.0 B+ 2020-04-07
' Left click a ploygon points around the center of screen going clockwise or counter ' Right click the last point which will connect to first when polygon is drawn and filled ' This is just a simple starter Polygon Maker.
nomainwin global XMAX, YMAX, Xo, Yo, pIndex XMAX = 800 : YMAX = 600 : Xo = 400 : Yo = 300 WindowWidth = XMAX + 8 WindowHeight = YMAX + 32
dim p(100, 1) 'store the polygon points here
open "polyFill test" for graphics_nsb as #gr #gr "when leftButtonUp lButtonUp" #gr "when rightButtonUp rButtonUp" #gr "trapclose quit" #gr "down" #gr "color black" #gr "size 2" call init wait
sub init #gr "fill white" ' clear drawing board #gr "set ";Xo;" ";Yo ' show origin end sub
sub quit h$ close #gr end end sub
sub pause mil 'tsh version has scan built-in t0 = time$("ms") while time$("ms") < t0 + mil : scan : wend end sub
sub lButtonUp H$, mx, my 'must have handle and mouse x,y p(pIndex, 0) = mx : p(pIndex, 1) = my if pIndex = 0 then #gr "set ";mx;" ";my else #gr "line ";mx;" ";my;" ";p(pIndex -1, 0);" ";p(pIndex -1, 1) if pIndex < 100 then pIndex = pIndex + 1 end sub
sub rButtonUp H$, mx, my 'main event finish polygon outline, fill it wait 4 secs start over p(pIndex, 0) = mx : p(pIndex, 1) = my if pIndex = 0 then #H$ "set ";mx;" ";my else #H$ "line ";mx;" ";my;" ";p(pIndex -1, 0);" ";p(pIndex -1, 1) call fillPoly H$, Xo, Yo, pIndex 'finish drawing call pause 35000 '<<< for screen shot ;-)) pIndex = 0 'to build another polygon call init end sub
' p( , ) is the polygon's border, give the x, y origin and nPts ' nPts <<< actually need the top pIndex number (number of Points is 1 more thanks to base 0 arrays). ' set color you want before calling this sub sub fillPoly h$, xOrigin, yOrigin, nPts for i = 0 to nPts -1 call fillTriangle h$, xOrigin, yOrigin, p(i, 0), p(i, 1), p(i + 1, 0), p(i + 1, 1) next call fillTriangle h$, xOrigin, yOrigin, p(0, 0), p(0, 1), p(nPts, 0), p(nPts, 1) end sub
' Title: Filled Triangle Sub 'Programmer: JB port by Andy Amaya ' Date: 2010.10.27 'http://justbasic.conforums.com/index.cgi?board=shared&action=display&num=1307312447 Sub fillTriangle h$, x1, y1, x2, y2, x3, y3 'triangle coordinates must be ordered: where x1 < x2 < x3 If x2 < x1 Then x = x2 : y = y2 : x2 = x1 : y2 = y1 : x1 = x : y1 = y 'swap x1, y1, with x3, y3 If x3 < x1 Then x = x3 : y = y3 : x3 = x1 : y3 = y1 : x1 = x : y1 = y 'swap x2, y2 with x3, y3 If x3 < x2 Then x = x3 : y = y3 : x3 = x2 : y3 = y2 : x2 = x : y2 = y If x1 <> x3 Then slope1 = (y3-y1)/(x3-x1) 'draw the first half of the triangle length = x2 - x1 If length <> 0 Then slope2 = (y2-y1)/(x2-x1) For x = 0 To length #h$ "Line ";Int(x+x1);" ";Int(x*slope1+y1);" ";Int(x+x1);" ";Int(x*slope2+y1) Next End If 'draw the second half of the triangle y = length*slope1+y1 : length = x3-x2 If length <> 0 Then slope3 = (y3-y2)/(x3-x2) For x = 0 To length #h$ "Line ";Int(x+x2);" ";Int(x*slope1+y);" ";Int(x+x2);" ";Int(x*slope3+y2) Next End If End Sub
Could you include a routine to draw a circle in 2 or 3 pixel steps and have it filled in? So that I study the code.
|
|
|
Post by Rod on Apr 8, 2020 17:23:08 GMT
This is rough, wait for B+'s polished version. But it fills a polygon that looks like a circle 100 times faster than point in polygon or getpixel style floodfill.
nomainwin WindowWidth = DisplayWidth WindowHeight = DisplayHeight UpperLeftX = int((DisplayWidth-WindowWidth)/2) UpperLeftY = int((DisplayHeight-WindowHeight)/2) midx=int(WindowWidth/2) midy=int(WindowHeight/2) open "Polygon" for graphics_nsb as #1 print #1, "trapclose [quit]" dim p(100,1) pi=0 #1 "down ; fill black" #1 "color white ; size 2" 'cheat
[polygoncircle] ox=midx-(200*sin(1/57.29577951)) oy=midy-(200*cos(1/57.29577951)) for n= 1 to 370 step 10 x=midx-(200*sin(n/57.29577951)) y=midy-(200*cos(n/57.29577951)) #1, "line ";ox;" ";oy;" ";x;" ";y p(pi,0)=x p(pi,1)=y pi=pi+1 ox=x oy=y next n
call fillPoly "#1",ox,oy,pi-1
wait sub fillPoly h$, xOrigin, yOrigin, nPts for i = 0 to nPts -1 call fillTriangle h$, xOrigin, yOrigin, p(i, 0), p(i, 1), p(i + 1, 0), p(i + 1, 1) next call fillTriangle h$, xOrigin, yOrigin, p(0, 0), p(0, 1), p(nPts, 0), p(nPts, 1) end sub
' Title: Filled Triangle Sub 'Programmer: JB port by Andy Amaya ' Date: 2010.10.27 'http://justbasic.conforums.com/index.cgi?board=shared&action=display&num=1307312447 Sub fillTriangle h$, x1, y1, x2, y2, x3, y3 'triangle coordinates must be ordered: where x1 < x2 < x3 If x2 < x1 Then x = x2 : y = y2 : x2 = x1 : y2 = y1 : x1 = x : y1 = y 'swap x1, y1, with x3, y3 If x3 < x1 Then x = x3 : y = y3 : x3 = x1 : y3 = y1 : x1 = x : y1 = y 'swap x2, y2 with x3, y3 If x3 < x2 Then x = x3 : y = y3 : x3 = x2 : y3 = y2 : x2 = x : y2 = y If x1 <> x3 Then slope1 = (y3-y1)/(x3-x1) 'draw the first half of the triangle length = x2 - x1 If length <> 0 Then slope2 = (y2-y1)/(x2-x1) For x = 0 To length #h$ "Line ";Int(x+x1);" ";Int(x*slope1+y1);" ";Int(x+x1);" ";Int(x*slope2+y1) Next End If 'draw the second half of the triangle y = length*slope1+y1 : length = x3-x2 If length <> 0 Then slope3 = (y3-y2)/(x3-x2) For x = 0 To length #h$ "Line ";Int(x+x2);" ";Int(x*slope1+y);" ";Int(x+x2);" ";Int(x*slope3+y2) Next End If End Sub
[quit] close #1 end
|
|
|
Post by B+ on Apr 8, 2020 20:05:08 GMT
Yeah using triangle to fill circle or ellipse is easier than polygon. Even though JB has Fill Circle or Fill Ellipse this is how it can be done with triangle. This code is actually good for any regular polygon even elliptical ones with axis parallel to x and y. Here is Elliptical Decagon (increase degrees steps to get smoother circle or ellipse): nomainwin global XMAX, YMAX XMAX = 800 : YMAX = 600 WindowWidth = XMAX + 8 WindowHeight = YMAX + 32 open "Decagon Fill" for graphics_nsb as #gr #gr "trapclose quit" #gr "color blue" ' <<< no cheat needed here, no poly fill sub either #gr "down" ww2 = XMAX/2 : wh2 = YMAX/2 ' origin of ellipse xradius = 350 : yradius = 250 for degrees = 0 to 360 step 36 ' 360/36 = 10 sides or decagon x = ww2 + int(xradius * cos(degrees/57.2957)) ' 1/57.29577951 = conversion from degrees to radians y = wh2 + int(yradius * sin(degrees/57.2957)) if degrees > 0 then call fillTriangle "#gr", ww2, wh2, lastX, lastY, x, y '<< OK Andy's Triangles holes on one edge '#gr "line ";ww2;" ";wh2;" ";lastX;" ";lastY ' <<< fill holes along one line end if lastX = x : lastY = y next wait
sub quit H$ close #gr end end sub
' Title: Filled Triangle Sub ' Programmer: JB port by Andy Amaya ' Date: 2010.10.27 ' http://justbasic.conforums.com/index.cgi?board=shared&action=display&num=1307312447 Sub fillTriangle h$, x1, y1, x2, y2, x3, y3 'triangle coordinates must be ordered: where x1 < x2 < x3 If x2 < x1 Then x = x2 : y = y2 : x2 = x1 : y2 = y1 : x1 = x : y1 = y 'swap x1, y1, with x3, y3 If x3 < x1 Then x = x3 : y = y3 : x3 = x1 : y3 = y1 : x1 = x : y1 = y 'swap x2, y2 with x3, y3 If x3 < x2 Then x = x3 : y = y3 : x3 = x2 : y3 = y2 : x2 = x : y2 = y If x1 <> x3 Then slope1 = (y3-y1)/(x3-x1) 'draw the first half of the triangle length = x2 - x1 If length <> 0 Then slope2 = (y2-y1)/(x2-x1) For x = 0 To length #h$ "Line ";Int(x+x1);" ";Int(x*slope1+y1);" ";Int(x+x1);" ";Int(x*slope2+y1) Next End If 'draw the second half of the triangle y = length*slope1+y1 : length = x3-x2 If length <> 0 Then slope3 = (y3-y2)/(x3-x2) For x = 0 To length #h$ "Line ";Int(x+x2);" ";Int(x*slope1+y);" ";Int(x+x2);" ";Int(x*slope3+y2) Next End If End Sub
Attachments:
|
|
|
Post by tsh73 on Apr 8, 2020 21:17:28 GMT
Hey! look at this! Draw some zigzag or spiral and make it spin (it does cut some corners - comment 'this does not check last triangles - it should wrap around ) 'PolyFill Test.txt for JB v2.0 B+ 2020-04-07
' Left click a ploygon points around the center of screen going clockwise or counter ' Right click the last point which will connect to first when polygon is drawn and filled ' This is just a simple starter Polygon Maker.
'nomainwin global XMAX, YMAX, Xo, Yo, pIndex global nPoints dim x(100), y(100) XMAX = 800 : YMAX = 600 : Xo = 400 : Yo = 300 WindowWidth = XMAX + 8 WindowHeight = YMAX + 32
dim p(100, 1) 'store the polygon points here
open "polyFill test" for graphics_nsb as #gr #gr "when leftButtonUp lButtonUp" #gr "when rightButtonUp rButtonUp" #gr "trapclose quit" #gr "down" #gr "color black" #gr "size 2" call init wait
sub init #gr "fill white" ' clear drawing board #gr "set ";Xo;" ";Yo ' show origin end sub
sub quit h$ close #gr end end sub
sub pause mil 'tsh version has scan built-in t0 = time$("ms") while time$("ms") < t0 + mil : scan : wend end sub
sub lButtonUp H$, mx, my 'must have handle and mouse x,y p(pIndex, 0) = mx : p(pIndex, 1) = my if pIndex = 0 then #gr "set ";mx;" ";my else #gr "line ";mx;" ";my;" ";p(pIndex -1, 0);" ";p(pIndex -1, 1) if pIndex < 100 then pIndex = pIndex + 1 end sub
sub rButtonUp H$, mx, my 'main event finish polygon outline, fill it wait 4 secs start over p(pIndex, 0) = mx : p(pIndex, 1) = my if pIndex = 0 then #H$ "set ";mx;" ";my else #H$ "line ";mx;" ";my;" ";p(pIndex -1, 0);" ";p(pIndex -1, 1) 'call fillPoly H$, Xo, Yo, pIndex 'finish drawing call fillPoly2 H$ call pause 35000 '<<< for screen shot ;-)) pIndex = 0 'to build another polygon call init end sub
' p( , ) is the polygon's border, give the x, y origin and nPts ' nPts <<< actually need the top pIndex number (number of Points is 1 more thanks to base 0 arrays). ' set color you want before calling this sub sub fillPoly h$, xOrigin, yOrigin, nPts for i = 0 to nPts -1 call fillTriangle h$, xOrigin, yOrigin, p(i, 0), p(i, 1), p(i + 1, 0), p(i + 1, 1) next call fillTriangle h$, xOrigin, yOrigin, p(0, 0), p(0, 1), p(nPts, 0), p(nPts, 1) end sub
sub fillPoly2 h$ 'pts p(i, 0), p(i, 1) 'i from 0 to pIndex '"ear clipping" approach 'https://en.wikipedia.org/wiki/Polygon_triangulation#Ear_clipping_method 'copy pts to x, y nPoints = pIndex+1 dim x(nPoints), y(nPoints) print "nPoints =";nPoints for i = 1 to nPoints x(i)=p(i-1, 0): y(i)=p(i-1, 1) print i, x(i), y(i) next print while nPoints >3 'find an ear found=0 for i = 1 to nPoints-2 'this does not check last triangles - it should wrap around i1=i: i2=i+1: i3=i+2 'check if line (i1) (i3) is totally in poligon ear=1 for a = 0.1 to 0.91 step .1 xx=x(i1)*a+x(i3)*(1-a) yy=y(i1)*a+y(i3)*(1-a) if isInPoly(xx, yy)=0 then ear = 0: exit for next if ear then 'we found an ear, cut it #h$ "color ";50+i*10;" 128 128" call fillTriangle h$, x(i1), y(i1), x(i2), y(i2),x(i3), y(i3) 'remove i2 for j = i2 to nPoints-1 x(j)=x(j+1):y(j)=y(j+1) next nPoints=nPoints-1 end if next wend 'last triangle #h$ "color pink" i = 1 i1=i: i2=i+1: i3=i+2 call fillTriangle h$, x(i1), y(i1), x(i2), y(i2),x(i3), y(i3) end sub
' Title: Filled Triangle Sub 'Programmer: JB port by Andy Amaya ' Date: 2010.10.27 'http://justbasic.conforums.com/index.cgi?board=shared&action=display&num=1307312447 Sub fillTriangle h$, x1, y1, x2, y2, x3, y3 'triangle coordinates must be ordered: where x1 < x2 < x3 If x2 < x1 Then x = x2 : y = y2 : x2 = x1 : y2 = y1 : x1 = x : y1 = y 'swap x1, y1, with x3, y3 If x3 < x1 Then x = x3 : y = y3 : x3 = x1 : y3 = y1 : x1 = x : y1 = y 'swap x2, y2 with x3, y3 If x3 < x2 Then x = x3 : y = y3 : x3 = x2 : y3 = y2 : x2 = x : y2 = y If x1 <> x3 Then slope1 = (y3-y1)/(x3-x1) 'draw the first half of the triangle length = x2 - x1 If length <> 0 Then slope2 = (y2-y1)/(x2-x1) For x = 0 To length #h$ "Line ";Int(x+x1);" ";Int(x*slope1+y1);" ";Int(x+x1);" ";Int(x*slope2+y1) Next End If 'draw the second half of the triangle y = length*slope1+y1 : length = x3-x2 If length <> 0 Then slope3 = (y3-y2)/(x3-x2) For x = 0 To length #h$ "Line ";Int(x+x2);" ";Int(x*slope1+y);" ";Int(x+x2);" ";Int(x*slope3+y2) Next End If End Sub
'************************************************ function isInPoly(x, y) 'casts ray from point to the right 'if it crosses odd number of edges then point in poligon edgesCrossed = 0 x2 = x(nPoints) y2 = y(nPoints) 'so first edge is (lstPoint)-(firstPoint) for i = 1 to nPoints x1 = x(i) y1 = y(i) if x1=x2 and y1=y2 then 'just skip doubled points else 'we have an edge x1 y1 - x2 y2, let's check it 'if y too low / to high... if y<min(y1,y2) OR y>max(y1,y2) then [check_done] 'if x too right if x>max(x1,x2) then [check_done] ' 'safeGuard: if point goes on a edge endpoint, do not use it at all ' if y = y1 OR y = y2 then isInPoly = 0 : exit function 'if horiz then (with checked y1 y2) it means we are through if y1 = y2 then edgesCrossed = edgesCrossed + 1: goto [check_done] 'else get intersection pt and check x crossX = x2*(y1-y)/(y1-y2)+x1*(y-y2)/(y1-y2) if crossX > x then edgesCrossed = edgesCrossed + 1 [check_done] x2 = x(i) y2 = y(i) end if next
isInPoly = edgesCrossed mod 2 end function
|
|
|
Post by Rod on Apr 9, 2020 8:08:53 GMT
Just in case anyone is shouting at the screen that you don't need triangular fill to fill a circle, true. But we are discussing polygon fill.
Code to create a filled circle, you could of course use circlefilled!
Don't know how we got onto circles, this is all about polygons.
nomainwin WindowWidth = DisplayWidth WindowHeight = DisplayHeight UpperLeftX = int((DisplayWidth-WindowWidth)/2) UpperLeftY = int((DisplayHeight-WindowHeight)/2) midx=int(WindowWidth/2) midy=int(WindowHeight/2) open "Filled Circle" for graphics_nsb as #1 print #1, "trapclose [quit]"
[clear] print #1, "down ; fill black" print #1, "color white ; size 1"
[circle] for n= 0 to 180 step .5 x=midx-(200*sin(n/57.29577951)) y=midy-(200*cos(n/57.29577951)) #1 "line ";midx+midx-x;" ";y;" ";x;" ";y next n
wait
[quit] close #1 end
|
|
|
Post by B+ on Apr 9, 2020 17:15:36 GMT
Rod Well it's you who have posted 2 tries at circle fill from HonkyTonk's request, I assume. tsh73 I am not seeing it from the code you posted, but you got me very excited to "make it spin".
|
|
|
Post by zzz000abc on Apr 16, 2020 23:21:34 GMT
hi Rod , it is quite easy to find the triangles in polygons. just a find any point inside the polygon say C. now that point together with the end points of any of its sides form a triangle. now for filling the triangle consider longest ,sweep lines from other two sides to it from its end points. As per geometry sum of any two lines is more than the length of the third side it always fills the triangle.
|
|
|
Post by tenochtitlanuk on Apr 17, 2020 9:14:21 GMT
|
|