the code below is just drawing points which i was later going to edit to connect from point to point as soon as i got the spiral function working.
Code:
Function Draw()
Dim iImageCenterPointH As Integer = pbOut.Height / 2
Dim iImageCenterPointW As Integer = pbOut.Width / 2
Dim iCircleSpace As Integer = 10
'# x²+y² = R² or [y = sqr(R²-x²) und y = -sqr(R²-x²)]
Dim oGrapics As System.Drawing.Graphics
Dim myImage As New Bitmap(pbOut.Width, pbOut.Height)
pbOut.Image = myImage
oGrapics = pbOut.CreateGraphics
For i As Integer = 0 To 100 Step 5
Dim x, y, r As Integer
'# step 1 >>
x = i
y = 0
r = (y * y) + (x * x)
r = Math.Sqrt(r)
myImage.SetPixel(iImageCenterPointW + r, iImageCenterPointH, Color.Black)
'# step 2 >^
x = i
y = i
r = (y * y) + (x * x)
r = Math.Sqrt(r)
myImage.SetPixel(iImageCenterPointW + (r / 2), iImageCenterPointH + (r / 2), Color.Black)
'# step 3 ^^
x = 0
y = i
r = (y * y) + (x * x)
r = Math.Sqrt(r)
myImage.SetPixel(iImageCenterPointW, iImageCenterPointH + r, Color.Black)
'# step 4 ^^
x = i
y = -i
r = (y * y) + (x * x)
r = Math.Sqrt(r)
myImage.SetPixel(iImageCenterPointW - (r / 2), iImageCenterPointH + (r / 2), Color.Black)
x = -i
y = i
r = (y * y) + (x * x)
r = Math.Sqrt(r)
myImage.SetPixel(iImageCenterPointW + (r / 2), iImageCenterPointH - (r / 2), Color.Black)
x = -i
y = 0
r = (y * y) + (x * x)
r = Math.Sqrt(r)
myImage.SetPixel(iImageCenterPointW - r, iImageCenterPointH, Color.Black)
x = -i
y = -i
r = (y * y) + (x * x)
r = Math.Sqrt(r)
myImage.SetPixel(iImageCenterPointW - (r / 2), iImageCenterPointH - (r / 2), Color.Black)
x = 0
y = -i
r = (y * y) + (x * x)
r = Math.Sqrt(r)
myImage.SetPixel(iImageCenterPointW, iImageCenterPointH - r, Color.Black)
Next
pbOut.Image = myImage
Return ""
End Function
im not 100% the output is matching the formula here's what im getting atm ...
Last edited by illskills; Feb 20th, 2009 at 03:41 PM.
Reason: Resolved
Re: [2008] Drawing spirals using the Graphics object ?
Here is the code I use to draw a spiral on the form. You can specify the starting and ending angle. When drawing a spiral, think trigonometry. Imagine a pen moving along a ruler at a steady pace. The result would be a straight line, of course. But now spin the ruler from its end on the surface of the table, also at a steady rate. The result is a spiral. The depth between layers depends on the ratio between the straight line motion of the pen along the ruler, and the circular motion of the ruler itself:
Code:
Option Strict On
Option Explicit On
Public Class Form1
Private Points As List(Of PointF)
Private PenWidth As Int16
Private Enum Direction
Clockwise = -1
AntiClockwise = 1
End Enum
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Points = New List(Of PointF)
PenWidth = 3
Dim Center As PointF = New PointF(CSng(Me.Width / 2), CSng(Me.Height / 2))
Dim Separation As Single = 10 + PenWidth
Dim Turns As Integer = 8
Dim Rotation As Direction = Direction.Clockwise
Dim Displacement As Single = 20
Dim StartAngle As Double = Math.PI / 4
Dim EndAngle As Double
StartAngle = Math.PI - StartAngle 'Orientate the angle relative to the 12'oclock position
EndAngle = 2 * Turns * Math.PI + StartAngle
If Rotation = Direction.Clockwise Then
EndAngle = StartAngle
StartAngle = 2 * Turns * Math.PI + EndAngle
End If
For Angle = StartAngle To EndAngle Step CInt(Rotation) * (Math.PI / 180)
Points.Add(New PointF(CSng(Center.X + Displacement * Math.Sin(Angle)), CSng(Center.Y + Displacement * Math.Cos(Angle))))
Displacement += Separation / 360
Next
End Sub
Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.DrawCurve(New Pen(Color.Black, PenWidth), Points.ToArray())
End Sub
End Class
Last edited by MaximilianMayrhofer; Feb 20th, 2009 at 12:45 PM.
- VS2008 Express, Access, SQL Server 2005 Express, VB/C#/ADO.NET -
Rate posts that have been helpful to you! It's a way of giving back to someone who has helped you
Re: [2008] Resolved - Drawing spirals using the Graphics object ?
im using it to design pieces of glass for my uni project i have waves / circles and now spirals working im using it to emulate me pouring pva glue onto glass for sand blasting later ... my little app can churn out more drawings in an hour than i could do in a year lol ;0)