vb畫多邊形

時間 2022-05-05 17:22:30

1樓:濮冰楓

我貼上的, 對於多邊形面積就不知道怎麼算了

下面是**:

新建乙個txt文件,複製下面**儲存為.frm 就可以使用了

version 5.00

begin vb.form frmdraw

caption = "form1"

clientheight = 10425

clientleft = 120

clienttop = 450

clientwidth = 13260

linktopic = "form1"

scaleheight = 10425

scalewidth = 13260

startupposition = 3 '視窗預設

begin vb.commandbutton command1

caption = "清除影象"

height = 615

left = 1320

tabindex = 10

top = 120

width = 1455

endbegin vb.textbox tjg

height = 270

left = 2280

tabindex = 9

text = "1"

top = 1080

width = 495

endbegin vb.textbox tjs

height = 270

left = 1800

tabindex = 8

text = "5"

top = 1080

width = 495

endbegin vb.optionbutton option1

caption = "正多角形"

height = 255

index = 4

left = 120

tabindex = 6

top = 1080

width = 1095

endbegin vb.textbox tbs

height = 270

left = 1800

tabindex = 4

text = "3"

top = 840

width = 495

endbegin vb.optionbutton option1

caption = "正多邊形"

height = 255

index = 3

left = 120

tabindex = 3

top = 840

width = 1095

endbegin vb.optionbutton option1

caption = "五邊形"

height = 255

index = 2

left = 120

tabindex = 2

top = 600

width = 1095

endbegin vb.optionbutton option1

caption = "五角星"

height = 255

index = 1

left = 120

tabindex = 1

top = 360

width = 1095

endbegin vb.optionbutton option1

caption = "正三角形"

height = 255

index = 0

left = 120

tabindex = 0

top = 120

width = 1095

endbegin vb.label label2

caption = "角數:"

height = 255

left = 1320

tabindex = 7

top = 1080

width = 495

endbegin vb.label label1

caption = "邊數:"

height = 255

left = 1320

tabindex = 5

top = 840

width = 495

endend

attribute vb_name = "frmdraw"

attribute vb_globalnamespace = false

attribute vb_creatable = false

attribute vb_predeclaredid = true

attribute vb_exposed = false

option explicit

dim mx as long

dim my as long

dim nx as long

dim ny as long

dim num1 as double

dim num2 as double

dim num3 as double

dim oidx as long

private sub draw(byval x1 as long, byval y1 as long, byval x2 as long, byval y2 as long, byval clr as long)

on error resume next

select case oidx

case 0

drawdbx x1, y1, x2, y2, clr, 3

case 1

draww x1, y1, x2, y2, clr

case 2

drawdbx x1, y1, x2, y2, clr, 5

case 3

dim bs as long

bs = val(tbs.text)

if bs >= 3 then drawdbx x1, y1, x2, y2, clr, bs

case 4

dim js as long

dim jg as long

js = val(tjs.text)

jg = val(tjg.text)

if js mod 2 <> 1 then js = js + 1

tjs.text = js

if jg < 1 then jg = 1

if jg > js - 4 then jg = js - 4

if jg mod 2 <> 1 then jg = jg - 1

if js mod jg = 0 then jg = 1

tjg.text = jg

if js >= 5 and js mod 2 = 1 then drawdjx x1, y1, x2, y2, clr, js, jg

end select

end sub

private sub draww(byval x1 as long, byval y1 as long, byval x2 as long, byval y2 as long, byval clr as long)

dim x3 as long

dim y3 as long

dim x4 as long

dim y4 as long

dim x5 as long

dim y5 as long

getxy x3, y3, x1, y1, x2, y2

getxy x4, y4, x2, y2, x3, y3

getxy x5, y5, x3, y3, x4, y4

me.line (x1, y1)-(x2, y2), clr

me.line -(x3, y3), clr

me.line -(x4, y4), clr

me.line -(x5, y5), clr

me.line -(x1, y1), clr

end sub

private sub drawdbx(byval x1 as long, byval y1 as long, byval x2 as long, byval y2 as long, byval clr as long, optional byval bs as long = 3)

if bs < 3 then exit sub

dim x() as long

dim y() as long

dim i as long

redim x(bs - 3)

redim y(bs - 3)

dim du as double

du = (bs - 2) * 180 / bs

me.line (x1, y1)-(x2, y2), clr

getxy x(0), y(0), x1, y1, x2, y2, du

me.line -(x(0), y(0)), clr

if bs > 3 then

getxy x(1), y(1), x2, y2, x(0), y(0), du

me.line -(x(1), y(1)), clr

if bs > 4 then

for i = 2 to bs - 3

getxy x(i), y(i), x(i - 2), y(i - 2), x(i - 1), y(i - 1), du

me.line -(x(i), y(i)), clr

next

end if

end if

me.line -(x1, y1), clr

end sub

private sub drawdjx(byval x1 as long, byval y1 as long, byval x2 as long, byval y2 as long, byval clr as long, optional byval js as long = 5, optional byval jg as long = 1)

if js < 5 then exit sub

if js mod 2 <> 1 then exit sub

dim x() as long

dim y() as long

dim i as long

redim x(js - 3)

redim y(js - 3)

dim du as double

du = jg * 180 / js

me.line (x1, y1)-(x2, y2), clr

getxy x(0), y(0), x1, y1, x2, y2, du

me.line -(x(0), y(0)), clr

if js > 3 then

getxy x(1), y(1), x2, y2, x(0), y(0), du

me.line -(x(1), y(1)), clr

if js > 4 then

for i = 2 to js - 3

getxy x(i), y(i), x(i - 2), y(i - 2), x(i - 1), y(i - 1), du

me.line -(x(i), y(i)), clr

next

end if

end if

me.line -(x1, y1), clr

end sub

private sub getxy(byref x as long, byref y as long, byval x1 as long, byval y1 as long, byval x2 as long, byval y2 as long, optional byval sdu as double = 0)

dim ln as long

dim du as double

dim ys as long

dim ssdu as double

if sdu = 0 then ssdu = num3 else ssdu = sdu / num2

ys = iif(y2 > y1, -1, 1)

if y1 = y2 then

x = x2 + (x1 - x2) * cos(ssdu)

y = y2 - (x1 - x2) * sin(ssdu)

else

ln = sqr((x1 - x2) ^ 2 + (y1 - y2) ^ 2)

du = atn((x2 - x1) / (y2 - y1))

x = x2 + sin(ssdu + du) * ln * ys

y = y2 + cos(ssdu + du) * ln * ys

end if

end sub

private sub command1_click()

me.cls

end sub

private sub form_load()

num1 = sqr(3) / 2

num2 = 180 / 3.14159265

num3 = 36 / num2

option1_click 0

end sub

private sub form_mousedown(button as integer, shift as integer, x as single, y as single)

if button <> 1 then exit sub

mx = x

my = y

nx = x

ny = y

me.drawwidth = 2

me.drawmode = 7

'line (nx, ny)-(mx, my), rgb(255, 255, 255)

draw mx, my, nx, ny, rgb(255, 255, 255)

end sub

private sub form_mousemove(button as integer, shift as integer, x as single, y as single)

if button <> 1 then exit sub

me.drawwidth = 2

me.drawmode = 7

if int(x) <> nx or int(y) <> ny then

'line (nx, ny)-(mx, my), rgb(255, 255, 255)

draw mx, my, nx, ny, rgb(255, 255, 255)

nx = x

ny = y

draw mx, my, nx, ny, rgb(255, 255, 255)

'line (nx, ny)-(mx, my), rgb(255, 255, 255)

end if

end sub

private sub form_mouseup(button as integer, shift as integer, x as single, y as single)

if button <> 1 then exit sub

me.drawwidth = 2

me.drawmode = 7

draw mx, my, nx, ny, rgb(255, 255, 255)

'line (nx, ny)-(mx, my), rgb(255, 255, 255)

me.drawmode = 13

draw mx, my, x, y, rgb(255, 0, 0)

end sub

private sub option1_click(index as integer)

oidx = index

end sub

vb怎麼畫多邊形,輸入座標,畫出這些點圍起來的圖形,怎麼做啊

看看這個應該可以 line 方法 在物件上畫直線和矩形。語法object.line step x1,1 step x2,y2 color b f line 方法的語法有以下物件限定符和部分 部分 描述 object 可選的。物件表示式,其值為 應用於 列表中的物件。如果object 省略,具有焦點 ...

圓和正多邊形,圓是不是多邊形

是道好題!和我以前做過的一道高中的奧數題類似,具體記不到了,但是,我可以明確告訴你,最後的那個圓與它外面的那個正n變形幾乎全等。解題思路 首先,要明確剛才我說的那一點。其次,要找出圓心與各多邊形的邊的距離規律,以及圓心與各圓之間距離的規律,請相信,一定有規律可找的,不是這道題就解不出來了!再次,設最...

多邊形面積公式,正多邊形的面積公式是什麼?

多邊形是沒有具體的計算公式的,只能把它分解成幾個常見的圖形 如正方形 長方形 梯形等 然後各個計算而已!正多邊形內角計算公式與半徑無關 要已知正多邊形邊數為n 內角和 180 n 2 半徑為r 圓的內接三角形面積公式 3倍根號3 除以4再乘以r方 外切三角形面積公式 3倍根號3 r方外切正方形 4r...

多邊形建模的精髓是什麼,多邊形建模的簡介

想要系統的學習可以考慮報乙個網路直播課,推薦cgwang的網路課。老師講得細,上完還可以回看,還有同型別錄播課可以免費學 贈送終身vip 自製能力相對較弱的話,建議還是去好點的培訓機構,實力和規模在國內排名前幾的大機構,推薦行業龍頭 王氏教育。王氏教育全國直營校區面授課程試聽 複製後面鏈結在瀏覽器也...

多邊形怎麼求面積,多邊形的面積計算公式

多邊形是沒有具體的計算公式的,只能把它分解成幾個常見的圖形 如正方形 長方形 梯形等 然後各個計算而已!正多邊形內角計算公式與半徑無關 要已知正多邊形邊數為n 內角和 180 n 2 半徑為r 圓的內接三角形面積公式 3倍根號3 除以4再乘以r方 外切三角形面積公式 3倍根號3 r方 外切正方形 4...