# simplest 3d line rotation

• ### Question

• Hi all !

I need to know, understand , learn ,how can i draw in 3d (lines only,not more).

l search the simpliest code ever ,with only one mouse event.

I find one code, what working with dots. I "complete" with this code:

(

Dim koord1 As New Dot
Dim koord2 As New Dot
For i = 0 To koordList.ToArray.Count - 2
koord1 = koordList(i)
koord2 = koordList(i + 1)
e.Graphics.DrawLine(Pens.Red, CSng(koord1.point.X), CSng(koord1.point.Y), CSng(koord2.point.X), CSng(koord2.point.Y))
Next

)

Now i see the lines, i can scale ,but only the dots rotate .

Thank you ,Regards Zoli.

The code:

Public Class Form1
Const twoPI As Double = Math.PI * 2
Private Structure Vertex3
Public X As Single
Public Y As Single
Public Z As Single
End Structure
Private Structure Dot
Public point As Vertex3
Public koordColor As Color

Public Sub Draw(g As Graphics)
Using dotBrush As New SolidBrush(koordColor)
g.FillEllipse(dotBrush, point.X, point.Y, 2, 2)
End Using
End Sub
End Structure

Private rand As New Random
Private koordList As New List(Of Dot)
Private koordRender() As Dot
Private AngX As Double
Private AngY As Double
Private lastAngX As Double
Private lastAngY As Double
Private deltaAngX As Double
Private deltaAngY As Double
Private ScaleFactor As Single = 1.0F
Private zeroPoint As PointF
Private UseBodyAxis As Boolean = True

DoubleBuffered = True
Dim koord As Dot
'create some 3D points to draw
For i = 0 To 8
koord.koordColor = Color.Yellow
koord.point.X = rand.Next(40, 100)
koord.point.Y = rand.Next(-100, 100)
koord.point.Z = rand.Next(-100, 100)
Next
koordRender = koordList.ToArray
zeroPoint = New PointF(ClientSize.Width / 2, ClientSize.Height / 2)
End Sub

Private Sub Form1_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
Static lastPos As Point
Dim CosAngX As Double
Dim SinAngX As Double
Dim CosAngZ As Double
Dim SinAngZ As Double
Dim CosAngY As Double
Dim SinAngY As Double
Dim xi, yi, zi As Double

If e.Button = MouseButtons.Left Then
If My.Computer.Keyboard.ShiftKeyDown Then          'Designating screen center
zeroPoint = e.Location
Invalidate()

Else                                               'Modifying rotation angles
AngX += (e.X - lastPos.X) / 100.0F
AngY -= (e.Y - lastPos.Y) / 100.0F
deltaAngX = AngX - lastAngX
deltaAngY = AngY - lastAngY
If AngX > Math.PI Then                'limit to +/- 180 degrees
AngX -= twoPI
ElseIf AngX < -Math.PI Then
AngX += twoPI
End If

If AngY > Math.PI Then
AngY -= twoPI
ElseIf AngY < -Math.PI Then
AngY += twoPI
End If
lastAngX = AngX
lastAngY = AngY

CosAngX = Math.Cos(AngX) 'use current Angles and reference original points
SinAngX = Math.Sin(AngX)
CosAngZ = 1  'we're not rotating around Z
SinAngZ = 0  'so use 0 degree values
CosAngY = Math.Cos(AngY)
SinAngY = Math.Sin(AngY)

Dim idx As Integer
For Each koord As Dot In koordList
xi = CosAngX * koord.point.X - SinAngX * koord.point.Y
yi = SinAngX * koord.point.X + CosAngX * koord.point.Y
With koordRender(idx).point
.X = CSng(CosAngZ * xi + SinAngZ * koord.point.Z)
zi = CosAngZ * koord.point.Z - SinAngZ * xi
.Y = CSng(CosAngY * yi - SinAngY * zi)
.Z = CSng(SinAngY * yi + CosAngY * zi)
End With
idx += 1
Next
End If
Invalidate()

ElseIf e.Button = MouseButtons.Right Then
ScaleFactor *= 1 + (e.X - lastPos.X) * 0.001F
If ScaleFactor < 0.1F Then ScaleFactor = 0.1F
If ScaleFactor > 10.0F Then ScaleFactor = 10.0F
Invalidate()
End If
lastPos = e.Location
End Sub

Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.TranslateTransform(zeroPoint.X, zeroPoint.Y)
e.Graphics.ScaleTransform(ScaleFactor, ScaleFactor)

For Each koord As Dot In koordRender
koord.Draw(e.Graphics)

Dim koord1 As New Dot
Dim koord2 As New Dot
For i = 0 To koordList.ToArray.Count - 2

koord1 = koordList(i)
koord2 = koordList(i + 1)
e.Graphics.DrawLine(Pens.Red, CSng(koord1.point.X), CSng(koord1.point.Y), CSng(koord2.point.X), CSng(koord2.point.Y))

Next
Next
End Sub
End Class

Saturday, January 18, 2020 1:32 PM

• I have modified your example to draw three lines for the x, y, and z axis.

Now when you drag the mouse the image rotates.

You are not drawing correctly. All you do in your paint event is draw X and Y but where is Z?

See how I draw from the orgin an then one line each to x, y, z axis points. That is drawing the vertices.

So I had to code that in the paint event.

Your example does not do that automatically.

So I dont know where your example comes from or where it is supposed to go. Where did your example come from?

It is easier for me to give you a different example rather than try to make your code work.

What is it your application does exactly and why are you drawing this?

Here is your example which I modified to draw the x, y, z axis. See how I changed the data to the 3 axis points in form load and 3 drawlines in the paint event.

```Public Class Form2

Const twoPI As Double = Math.PI * 2
Private Structure Vertex3
Public X As Single
Public Y As Single
Public Z As Single
End Structure
Private Structure Dot
Public point As Vertex3
Public koordColor As Color

Public Sub Draw(g As Graphics)
Using dotBrush As New SolidBrush(koordColor)
g.FillEllipse(dotBrush, point.X, point.Y, 2, 2)
End Using
End Sub
End Structure

Private rand As New Random
Private koordList As New List(Of Dot)
Private koordRender() As Dot
Private AngX As Double
Private AngY As Double
Private lastAngX As Double
Private lastAngY As Double
Private deltaAngX As Double
Private deltaAngY As Double
Private ScaleFactor As Single = 1.0F
Private zeroPoint As PointF
Private UseBodyAxis As Boolean = True

DoubleBuffered = True
'Dim koord As Dot
''create some 3D points to draw
'For i As Integer = 0 To 8
'    koord.koordColor = Color.Yellow
'    koord.point.X = rand.Next(40, 100)
'    koord.point.Y = rand.Next(-100, 100)
'    koord.point.Z = rand.Next(-100, 100)
'Next

'make a square
Dim koordX1 As New Dot
With koordX1
.koordColor = Color.Yellow
.point.X = 0
.point.Y = 0
.point.Z = 0
End With

Dim koordX2 As New Dot
With koordX2
.koordColor = Color.Yellow
.point.X = 10
.point.Y = 0
.point.Z = 0
End With

Dim koordY2 As New Dot
With koordY2
.koordColor = Color.Yellow
.point.X = 0
.point.Y = 10
.point.Z = 0
End With

Dim koordZ3 As New Dot
With koordZ3
.koordColor = Color.Yellow
.point.X = 0
.point.Y = 0
.point.Z = 10
End With

koordRender = koordList.ToArray
zeroPoint = New PointF(CSng(ClientSize.Width / 2), CSng(ClientSize.Height / 2))
End Sub

Private Sub Form1_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
Static lastPos As Point
Dim CosAngX As Double
Dim SinAngX As Double
Dim CosAngZ As Double
Dim SinAngZ As Double
Dim CosAngY As Double
Dim SinAngY As Double
Dim xi, yi, zi As Double

If e.Button = MouseButtons.Left Then
If My.Computer.Keyboard.ShiftKeyDown Then          'Designating screen center
zeroPoint = e.Location
Invalidate()

Else                                               'Modifying rotation angles
AngX += (e.X - lastPos.X) / 100.0F
AngY -= (e.Y - lastPos.Y) / 100.0F
deltaAngX = AngX - lastAngX
deltaAngY = AngY - lastAngY
If AngX > Math.PI Then                'limit to +/- 180 degrees
AngX -= twoPI
ElseIf AngX < -Math.PI Then
AngX += twoPI
End If

If AngY > Math.PI Then
AngY -= twoPI
ElseIf AngY < -Math.PI Then
AngY += twoPI
End If
lastAngX = AngX
lastAngY = AngY

CosAngX = Math.Cos(AngX) 'use current Angles and reference original points
SinAngX = Math.Sin(AngX)
CosAngZ = 1  'we're not rotating around Z
SinAngZ = 0  'so use 0 degree values
CosAngY = Math.Cos(AngY)
SinAngY = Math.Sin(AngY)

Dim idx As Integer
For Each koord As Dot In koordList
xi = CosAngX * koord.point.X - SinAngX * koord.point.Y
yi = SinAngX * koord.point.X + CosAngX * koord.point.Y
With koordRender(idx).point
.X = CSng(CosAngZ * xi + SinAngZ * koord.point.Z)
zi = CosAngZ * koord.point.Z - SinAngZ * xi
.Y = CSng(CosAngY * yi - SinAngY * zi)
.Z = CSng(SinAngY * yi + CosAngY * zi)
End With
idx += 1
Next
End If
Invalidate()

ElseIf e.Button = MouseButtons.Right Then
ScaleFactor *= 1 + (e.X - lastPos.X) * 0.001F
If ScaleFactor < 0.1F Then ScaleFactor = 0.1F
If ScaleFactor > 10.0F Then ScaleFactor = 10.0F
Invalidate()
End If
lastPos = e.Location
End Sub

Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint

Dim scalefactor As Single = 10
e.Graphics.ScaleTransform(ScaleFactor, ScaleFactor)
e.Graphics.TranslateTransform(12, 12)

'draw the origin with axis lines
Using p As New Pen(Color.Red, 0.4)
'xaxis
e.Graphics.DrawLine(p, koordRender(0).point.X, koordRender(0).point.Y, koordRender(1).point.X, koordRender(1).point.Y)
'yaxis
e.Graphics.DrawLine(p, koordRender(0).point.X, koordRender(0).point.Y, koordRender(2).point.X, koordRender(2).point.Y)
'zaxis
e.Graphics.DrawLine(p, koordRender(0).point.X, koordRender(0).point.Y, koordRender(3).point.X, koordRender(3).point.Y)

End Using

'For Each koord As Dot In koordRender
'    koord.Draw(e.Graphics)

'    Dim koord1 As New Dot
'    Dim koord2 As New Dot
'    For i As Integer = 0 To koordList.ToArray.Count - 2

'        koord1 = koordList(i)
'        koord2 = koordList(i + 1)
'        e.Graphics.DrawLine(Pens.Red, CSng(koord1.point.X), CSng(koord1.point.Y), CSng(koord2.point.X), CSng(koord2.point.Y))

'    Next
'Next

End Sub
End Class```

YOu need to review the examples I gave you on april 7 maybe you can use one of those examples:

https://social.msdn.microsoft.com/Forums/en-US/cf803758-e05c-425b-9874-5fdea56418aa/arrray-problem-in-vb2015?forum=vbgeneral

• Marked as answer by Sunday, January 19, 2020 6:39 PM
Saturday, January 18, 2020 3:16 PM

### All replies

• I have modified your example to draw three lines for the x, y, and z axis.

Now when you drag the mouse the image rotates.

You are not drawing correctly. All you do in your paint event is draw X and Y but where is Z?

See how I draw from the orgin an then one line each to x, y, z axis points. That is drawing the vertices.

So I had to code that in the paint event.

Your example does not do that automatically.

So I dont know where your example comes from or where it is supposed to go. Where did your example come from?

It is easier for me to give you a different example rather than try to make your code work.

What is it your application does exactly and why are you drawing this?

Here is your example which I modified to draw the x, y, z axis. See how I changed the data to the 3 axis points in form load and 3 drawlines in the paint event.

```Public Class Form2

Const twoPI As Double = Math.PI * 2
Private Structure Vertex3
Public X As Single
Public Y As Single
Public Z As Single
End Structure
Private Structure Dot
Public point As Vertex3
Public koordColor As Color

Public Sub Draw(g As Graphics)
Using dotBrush As New SolidBrush(koordColor)
g.FillEllipse(dotBrush, point.X, point.Y, 2, 2)
End Using
End Sub
End Structure

Private rand As New Random
Private koordList As New List(Of Dot)
Private koordRender() As Dot
Private AngX As Double
Private AngY As Double
Private lastAngX As Double
Private lastAngY As Double
Private deltaAngX As Double
Private deltaAngY As Double
Private ScaleFactor As Single = 1.0F
Private zeroPoint As PointF
Private UseBodyAxis As Boolean = True

DoubleBuffered = True
'Dim koord As Dot
''create some 3D points to draw
'For i As Integer = 0 To 8
'    koord.koordColor = Color.Yellow
'    koord.point.X = rand.Next(40, 100)
'    koord.point.Y = rand.Next(-100, 100)
'    koord.point.Z = rand.Next(-100, 100)
'Next

'make a square
Dim koordX1 As New Dot
With koordX1
.koordColor = Color.Yellow
.point.X = 0
.point.Y = 0
.point.Z = 0
End With

Dim koordX2 As New Dot
With koordX2
.koordColor = Color.Yellow
.point.X = 10
.point.Y = 0
.point.Z = 0
End With

Dim koordY2 As New Dot
With koordY2
.koordColor = Color.Yellow
.point.X = 0
.point.Y = 10
.point.Z = 0
End With

Dim koordZ3 As New Dot
With koordZ3
.koordColor = Color.Yellow
.point.X = 0
.point.Y = 0
.point.Z = 10
End With

koordRender = koordList.ToArray
zeroPoint = New PointF(CSng(ClientSize.Width / 2), CSng(ClientSize.Height / 2))
End Sub

Private Sub Form1_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
Static lastPos As Point
Dim CosAngX As Double
Dim SinAngX As Double
Dim CosAngZ As Double
Dim SinAngZ As Double
Dim CosAngY As Double
Dim SinAngY As Double
Dim xi, yi, zi As Double

If e.Button = MouseButtons.Left Then
If My.Computer.Keyboard.ShiftKeyDown Then          'Designating screen center
zeroPoint = e.Location
Invalidate()

Else                                               'Modifying rotation angles
AngX += (e.X - lastPos.X) / 100.0F
AngY -= (e.Y - lastPos.Y) / 100.0F
deltaAngX = AngX - lastAngX
deltaAngY = AngY - lastAngY
If AngX > Math.PI Then                'limit to +/- 180 degrees
AngX -= twoPI
ElseIf AngX < -Math.PI Then
AngX += twoPI
End If

If AngY > Math.PI Then
AngY -= twoPI
ElseIf AngY < -Math.PI Then
AngY += twoPI
End If
lastAngX = AngX
lastAngY = AngY

CosAngX = Math.Cos(AngX) 'use current Angles and reference original points
SinAngX = Math.Sin(AngX)
CosAngZ = 1  'we're not rotating around Z
SinAngZ = 0  'so use 0 degree values
CosAngY = Math.Cos(AngY)
SinAngY = Math.Sin(AngY)

Dim idx As Integer
For Each koord As Dot In koordList
xi = CosAngX * koord.point.X - SinAngX * koord.point.Y
yi = SinAngX * koord.point.X + CosAngX * koord.point.Y
With koordRender(idx).point
.X = CSng(CosAngZ * xi + SinAngZ * koord.point.Z)
zi = CosAngZ * koord.point.Z - SinAngZ * xi
.Y = CSng(CosAngY * yi - SinAngY * zi)
.Z = CSng(SinAngY * yi + CosAngY * zi)
End With
idx += 1
Next
End If
Invalidate()

ElseIf e.Button = MouseButtons.Right Then
ScaleFactor *= 1 + (e.X - lastPos.X) * 0.001F
If ScaleFactor < 0.1F Then ScaleFactor = 0.1F
If ScaleFactor > 10.0F Then ScaleFactor = 10.0F
Invalidate()
End If
lastPos = e.Location
End Sub

Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint

Dim scalefactor As Single = 10
e.Graphics.ScaleTransform(ScaleFactor, ScaleFactor)
e.Graphics.TranslateTransform(12, 12)

'draw the origin with axis lines
Using p As New Pen(Color.Red, 0.4)
'xaxis
e.Graphics.DrawLine(p, koordRender(0).point.X, koordRender(0).point.Y, koordRender(1).point.X, koordRender(1).point.Y)
'yaxis
e.Graphics.DrawLine(p, koordRender(0).point.X, koordRender(0).point.Y, koordRender(2).point.X, koordRender(2).point.Y)
'zaxis
e.Graphics.DrawLine(p, koordRender(0).point.X, koordRender(0).point.Y, koordRender(3).point.X, koordRender(3).point.Y)

End Using

'For Each koord As Dot In koordRender
'    koord.Draw(e.Graphics)

'    Dim koord1 As New Dot
'    Dim koord2 As New Dot
'    For i As Integer = 0 To koordList.ToArray.Count - 2

'        koord1 = koordList(i)
'        koord2 = koordList(i + 1)
'        e.Graphics.DrawLine(Pens.Red, CSng(koord1.point.X), CSng(koord1.point.Y), CSng(koord2.point.X), CSng(koord2.point.Y))

'    Next
'Next

End Sub
End Class```

YOu need to review the examples I gave you on april 7 maybe you can use one of those examples:

https://social.msdn.microsoft.com/Forums/en-US/cf803758-e05c-425b-9874-5fdea56418aa/arrray-problem-in-vb2015?forum=vbgeneral

• Marked as answer by Sunday, January 19, 2020 6:39 PM
Saturday, January 18, 2020 3:16 PM
• Hi Tommy !

I found my example with google search,it was the simplest of the many, it is good to learn.

It is old example from 2014, but i like it, because very simple, and if i want to draw many lines

(later,maybe from txt file), the  "For i = 0 To koordList.ToArray.Count - 2" code is simplest solution.

Now I'm looking for another solution.  You're right, i forgetyour former help.

I'm trying to complete your code because i can't scale the lines with the mouse , this part is easy.

Thank you for your help .

Sunday, January 19, 2020 6:39 PM
• Hi Tommy !

I found my example with google search,it was the simplest of the many, it is good to learn.

It is old example from 2014, but i like it, because very simple, and if i want to draw many lines

(later,maybe from txt file), the  "For i = 0 To koordList.ToArray.Count - 2" code is simplest solution.

Now I'm looking for another solution.  You're right, i forgetyour former help.

I'm trying to complete your code because i can't scale the lines with the mouse , this part is easy.

Thank you for your help .

Ok then. I am not sure what you mean exactly.

Here is another "simple" basic example that only shows rotation about the z axis. Maybe you already know all this.

This example is looking (camera position looking at model position) at the plan view x, y plane from "above" on the z axis while moving the view location around the z axis using the mouse.

You can see in the mouemove event the one rotation angle Theta is changed and the screen redrawn. That is the only direction that is changing in this example.

With your first example is it is not drawing the lines in proper order? Actually I am not sure, it is hard to say what we see since it draws only random chaos.

That is why I simplified it to the 3 direction axes and made my own model of the 3 axes.

In my first example I coded the points of the "primitive" 3 line origin vertex shape object. And in the paint event I drew the 3 lines from the points.

So there is a process of turning the points into 3d shapes like lines and cubes. And that process has other future things like back face culling ie remove objects that are behind others. And shading. We want to develop a process to logically make the 3d drawing which is really a 3d data model and a 2d drawing.

In this second example you can see there are points of the cube corners or vertices and then there are "line" primitive objects made using vertices points.

When we draw we draw each saved line based on its two defined points.

When we rotate we calculate the new position of the points based on the rotation angle(s). Then we draw each line based on the new rotated point positions.

In this example paint event we call DrawLine3d sub and it draws the lines in the 2d drawing view based on the current rotation angle Theta. So this is a special line object case that we made for our 3d drawings. We can have 3d arcs, Cubes, etc. Or we can only have lines and make 3d meshes.

Therefore once you understand the basics and as we get a more detailed drawing the math gets complex. Best to use an established working code than mess with your own. Thats what I mean.

Hopefully seeing only the one Theta angle rotation and how the primitive objects are created from the initial points will help visualize the process of how the 3d view is built up.

```Public Class Form3
Private Class Line3d
Public pt1 As Point3d
Public pt2 As Point3d
Public color As Color
Public width As Single

Public Sub New(_color As Color, _width As Single, _pt1 As Point3d, _pt2 As Point3d)
pt1 = _pt1
pt2 = _pt2
color = _color
width = _width
End Sub
End Class

Private Class Point3d
Public x As Single
Public y As Single
Public z As Single

Public Sub New(_x As Single, _y As Single, _z As Single)
x = _x
y = _y
z = _z
End Sub
End Class

Private Lines As New List(Of Line3d)
Private GridAxisLines As New List(Of Line3d)
Private Points As New List(Of Point3d)
Private Theta As Double = -30
Private MouseDownPt As Point

ClientSize = New Size(300, 300)
BackColor = Color.White
ResizeRedraw = True
DoubleBuffered = True
Text = "3d Graph"

'axis lines x axis
GridAxisLines.Add(New Line3d(Color.SkyBlue, 0.01, New Point3d(0, 0, 0), New Point3d(11, 0, 0)))
''y axis
GridAxisLines.Add(New Line3d(Color.SkyBlue, 0.01, New Point3d(0, 11, 0), New Point3d(0, 0, 0)))
''z axis
GridAxisLines.Add(New Line3d(Color.SkyBlue, 0.01, New Point3d(0, 0, 0), New Point3d(0, 0, 11)))

'data points - plot connected with lines

'back face cube frame
Lines.Add(New Line3d(Color.Red, 0.01, New Point3d(1, 3, 1), New Point3d(7, 3, 1)))
Lines.Add(New Line3d(Color.Red, 0.01, New Point3d(1, 7, 1), New Point3d(7, 7, 1)))
Lines.Add(New Line3d(Color.Red, 0.01, New Point3d(1, 3, 1), New Point3d(1, 7, 1)))
Lines.Add(New Line3d(Color.Red, 0.01, New Point3d(7, 3, 1), New Point3d(7, 7, 1)))
'front face
Lines.Add(New Line3d(Color.Red, 0.01, New Point3d(1, 3, 5), New Point3d(7, 3, 5)))
Lines.Add(New Line3d(Color.Red, 0.01, New Point3d(1, 7, 5), New Point3d(7, 7, 5)))
Lines.Add(New Line3d(Color.Red, 0.01, New Point3d(1, 3, 5), New Point3d(1, 7, 5)))
Lines.Add(New Line3d(Color.Red, 0.01, New Point3d(7, 3, 5), New Point3d(7, 7, 5)))
'left side
Lines.Add(New Line3d(Color.Red, 0.01, New Point3d(1, 3, 1), New Point3d(1, 3, 5)))
Lines.Add(New Line3d(Color.Red, 0.01, New Point3d(1, 7, 1), New Point3d(1, 7, 5)))
'right side
Lines.Add(New Line3d(Color.Red, 0.01, New Point3d(7, 3, 1), New Point3d(7, 3, 5)))
Lines.Add(New Line3d(Color.Red, 0.01, New Point3d(7, 7, 1), New Point3d(7, 7, 5)))

End Sub

Private Sub Form3_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown
MouseDownPt = e.Location
End Sub

Private Sub Form3_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
If e.Button = MouseButtons.Left Then
Theta += (MouseDownPt.Y - e.Y) / 50
Invalidate()
End If
End Sub

Private Sub Form3_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
With e.Graphics
.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
Dim theScale As Double = 20
Dim scaleRatio As Single = CSng(ClientSize.Width / theScale)
.ScaleTransform(scaleRatio, scaleRatio)
.TranslateTransform(4, 6)

'draw grid
Using f1 As New Font("arial", 0.5),
f2 As New Font("arial", 0.8, FontStyle.Italic)
'axis lines
For Each ln As Line3d In GridAxisLines
DrawLine3d(e.Graphics, ln)
Next
'axis labels
Dim x1, y1 As Single
For x As Integer = 0 To 10 Step 2
.DrawString(x.ToString, f1, Brushes.SkyBlue, x, 0)
.DrawString(x.ToString, f1, Brushes.SkyBlue, 0, x)
x1 = CSng(x * Math.Cos(Theta / 57.8))
y1 = CSng(x * Math.Sin(Theta / 57.8))
.DrawString(x.ToString, f1, Brushes.SkyBlue, x1, y1)
Next
.DrawString("X", f2, Brushes.Black, 11, 0.5)
.DrawString("Y", f2, Brushes.Black, 0.5, 11)
.DrawString("Z", f2, Brushes.Black, CSng(11 * Math.Cos(Theta / 57.8)), CSng(11 * Math.Sin(Theta / 57.8)))
End Using
End With

'draw the list of line objects that make cube
For Each ln As Line3d In Lines
DrawLine3d(e.Graphics, ln)
Next

'graph points connected with line
For i As Integer = 0 To Points.Count - 2
DrawLine3d(e.Graphics, New Line3d(Color.Green, 0.2, Points(i), Points(i + 1)))
DrawPoint3d(e.Graphics, Points(i + 1))
Next
DrawPoint3d(e.Graphics, Points(0))

End Sub

Private Sub DrawPoint3d(g As Graphics, pt1 As Point3d)
Using p As New Pen(Color.Lime, 0.1)
Dim r As Single = 0.4
g.DrawEllipse(p, New RectangleF(CSng(pt1.x + (pt1.z * Math.Cos(Theta / 57.8))) - (r / 2),
CSng(pt1.y + (pt1.z * Math.Sin(Theta / 57.8))) - (r / 2), r, r))
End Using
End Sub

Private Sub DrawLine3d(g As Graphics, line1 As Line3d)
Using p As New Pen(line1.color, line1.width)
g.DrawLine(p,
New PointF(CSng(line1.pt1.x + (line1.pt1.z * Math.Cos(Theta / 57.8))),
CSng(line1.pt1.y + (line1.pt1.z * Math.Sin(Theta / 57.8)))),
New PointF(CSng(line1.pt2.x + (line1.pt2.z * Math.Cos(Theta / 57.8))),
CSng(line1.pt2.y + (line1.pt2.z * Math.Sin(Theta / 57.8)))))
End Using
End Sub

End Class```

Sunday, January 19, 2020 11:17 PM
• Hi Tommy !

This two example is very big help for me .

Thank you all !  Regards Zoli.

Monday, January 20, 2020 9:55 PM