在 Visual Basic 中使用极坐标绘图时移动原点
Move point of origin while drawing using polar coordinates in visual basic
所以我正在尝试使用极坐标在比萨饼上绘制意大利辣香肠,但我在移动原点时遇到了问题。这是我的代码:
Public Class polarToCartesian
Property X As Double
Property Y As Double
Sub New(Radius As Double, AngleDegree As Double)
Dim AngleRadian As Double = AngleDegree * 2 * Math.PI / 360
X = Radius * Math.Cos(AngleRadian)
Y = Radius * Math.Sin(AngleRadian)
End Sub
End Class
Public Class CartesianToPolar
Property Radius As Double
Property AngleRadian As Double
ReadOnly Property AngleDegree As Double
Get
Return AngleRadian * 360 / (2 * Math.PI)
End Get
End Property
Sub New(X As Double, Y As Double)
Radius = (X ^ 2 + Y ^ 2) ^ 0.5
AngleRadian = Math.Atan2(Y, X)
End Sub
End Class
下面是我画意大利辣香肠的方法:
If pTopping = True Then
Dim counter = 0
Dim imgPic(3) As Image
imgPic(0) = pepperoniOne
imgPic(1) = pepperoniTwo
imgPic(2) = pepperoniThree
Do Until counter > 38
Dim value As Integer = CInt(Int((3 * Rnd()) + 0))
Dim i = imgPic(value)
Dim PTC As New polarAndCartesian(CInt(Int((60 * Rnd()) + 0)), CInt(Int((360 * Rnd()) + 0)))
e.Graphics.DrawImage(i, CInt(PTC.X), CInt(PTC.Y))
counter += 1
Loop
End If
这是我的结果:
知道如何在开始绘图之前移动极坐标上的原点吗?我很难理解这个问题。
您必须计算比萨饼的中心并将其添加到意大利辣香肠 x 和 y 中。
PTC.X += ( pie.X + pie.Width ) \ 2 ' "\" for integer division instead of "/"
PTC.Y += ( pie.Y + pie.Height ) \ 2
此外,在极坐标下,馅饼的中心看起来比侧面有更多的意大利辣香肠。相反,您可以随机获取 X 和 Y 并检查它们是否在披萨饼圈内。
要在 .NET 中获取 0 到 2 之间的随机整数:
Dim random as New Random()
Dim value = random.Next(3);
所以我正在尝试使用极坐标在比萨饼上绘制意大利辣香肠,但我在移动原点时遇到了问题。这是我的代码:
Public Class polarToCartesian
Property X As Double
Property Y As Double
Sub New(Radius As Double, AngleDegree As Double)
Dim AngleRadian As Double = AngleDegree * 2 * Math.PI / 360
X = Radius * Math.Cos(AngleRadian)
Y = Radius * Math.Sin(AngleRadian)
End Sub
End Class
Public Class CartesianToPolar
Property Radius As Double
Property AngleRadian As Double
ReadOnly Property AngleDegree As Double
Get
Return AngleRadian * 360 / (2 * Math.PI)
End Get
End Property
Sub New(X As Double, Y As Double)
Radius = (X ^ 2 + Y ^ 2) ^ 0.5
AngleRadian = Math.Atan2(Y, X)
End Sub
End Class
下面是我画意大利辣香肠的方法:
If pTopping = True Then
Dim counter = 0
Dim imgPic(3) As Image
imgPic(0) = pepperoniOne
imgPic(1) = pepperoniTwo
imgPic(2) = pepperoniThree
Do Until counter > 38
Dim value As Integer = CInt(Int((3 * Rnd()) + 0))
Dim i = imgPic(value)
Dim PTC As New polarAndCartesian(CInt(Int((60 * Rnd()) + 0)), CInt(Int((360 * Rnd()) + 0)))
e.Graphics.DrawImage(i, CInt(PTC.X), CInt(PTC.Y))
counter += 1
Loop
End If
这是我的结果:
知道如何在开始绘图之前移动极坐标上的原点吗?我很难理解这个问题。
您必须计算比萨饼的中心并将其添加到意大利辣香肠 x 和 y 中。
PTC.X += ( pie.X + pie.Width ) \ 2 ' "\" for integer division instead of "/"
PTC.Y += ( pie.Y + pie.Height ) \ 2
此外,在极坐标下,馅饼的中心看起来比侧面有更多的意大利辣香肠。相反,您可以随机获取 X 和 Y 并检查它们是否在披萨饼圈内。
要在 .NET 中获取 0 到 2 之间的随机整数:
Dim random as New Random()
Dim value = random.Next(3);