2015-10-22 180 views
0

我使用下面的代碼繪製一個矩形,一個半徑爲200的矩形內的圓,一箇中心點(300,300),然後在中心點繪製一個點基一度是90度,但結果不是我想要的。我用下式:在給定角度和半徑的圓上找到點

x = centerX + radius * cos(degrees) 
y = centerY + radius * sin(degrees) 

下面是代碼:

Dim CAVtable As New Hashtable 
Dim oCanvas As New Bitmap(507, 507) 

Dim graphicsObj As Graphics = Graphics.FromImage(oCanvas) 
graphicsObj.Clear(Color.White) 

Dim pCenter As New Point(300, 300) 
DrawPoint(pCenter, graphicsObj, Color.Blue) 
Dim rc2 As New Rectangle(pCenter, New Size(1, 1)) 

Dim penARC2 As New Pen(Color.Red, 2) 
rc2.Inflate(200, 200) 
graphicsObj.DrawRectangle(Pens.Black, rc2) 

graphicsObj.DrawArc(penARC2, rc2, 0, 360) 

Dim xtem As Double = pCenter.X + 200 * Math.Cos(90.0!) 
Dim ytem As Double = pCenter.Y + 200 * Math.Sin(90.0!) 
Dim ptem As New Point(xtem, ytem) 
DrawPoint(ptem, graphicsObj, Color.Blue) 

Response.ContentType = "image/jpeg" 
oCanvas.Save(Response.OutputStream, ImageFormat.Jpeg) 
Response.End() 

graphicsObj.Dispose() 
oCanvas.Dispose() 

結果是

actual results

爲什麼不能(因爲我用90度):

expected results

還有,我想要計算座標圓上的位置點(x,y),如下圖所示。我該怎麼做?我可以申請哪些配方?

final desired result

+0

我看到的結果不是度數是90,我不知道! –

回答

2

Math.Sin和Math.Cos使用弧度,不度。請嘗試: Dim xtem As Double = pCenter.X + 200 * Math.Cos(90 * Math.PI/180) Dim ytem As Double = pCenter.Y + 200 * Math.Sin(90 * Math.PI/180)

這些是圓上點的x和y座標。

+0

謝謝先生! –

相關問題