Subscribed unsubscribe Subscribe Subscribe

多角形の図心を求める(nspired basic)

図心の計算
Define polycenter(verts)=
Prgm
:Local k,numverts,points,xg,yg,x,y,xc,yc,s,st
:numverts:=((dim(verts))/(2))
:points:=exact(augment(verts,{verts[1],verts[2]}))
:For k,1,((dim(points))/(2))
:x[k]:=points[2*k-1]
:y[k]:=points[2*k]
:EndFor
:xc:=((seqn(x[n]+x[n+1],numverts))/(3))
:yc:=((seqn(y[n]+y[n+1],numverts))/(3))
:s:=((seqn(x[n+1]*y[n]-y[n+1]*x[n],numverts))/(2))
:st:=sum(s)
:xg:=((sum(s*xc))/(st))
:yg:=((sum(s*yc))/(st))
:Disp "numVerts: ",numverts
:Disp "center x: ",xc
:Disp "center y: ",yc
:Disp "each area: ",s
:Disp "total area: ",st
:Disp "xg, yg: ",{xg,yg}
:EndPrgm

f:id:ti-nspire:20160606133210j:plain

Remove all ads