Write a function in VB.Net that takes a point and a length as parameters and returns another point such that if a line were drawn between the points it would be at a 70 degree angle and of the length specified through the length parameter. We will call this function "GetPt". Then I want you to write a function that takes a graphics object, a starting point, a width, height and depth which it would then use to draw a cuboid. The cuboid would be drawn by first drawing a rectangle who's upper left corner is the starting point specified by the parameter. The width and height of this rectangle would be determined by the width and height parameters. Then we would draw a line for each corner of the rectangle using the GetPt function from earlier to get the second point, passing the depth as the length to the GetPt function. Finally we would draw a second rectangle whose corners would be the points returned by the calls to GetPt.
Here is the implementation of the "GetPt" function in VB.Net:
vbnetPublic Function GetPt(ByVal point As Point, ByVal length As Integer) As Point
Dim x As Integer = point.X + (length * Math.Cos(70 * Math.PI / 180))
Dim y As Integer = point.Y + (length * Math.Sin(70 * Math.PI / 180))
Return New Point(x, y)
End Function
And here is the implementation of the "DrawCuboid" function in VB.Net:
vbnetPublic Sub DrawCuboid(ByVal g As Graphics, ByVal startPt As Point, ByVal width As Integer, ByVal height As Integer, ByVal depth As Integer)
' Draw the first rectangle
g.DrawRectangle(Pens.Black, startPt.X, startPt.Y, width, height)
' Get the points for the four corners of the first rectangle
Dim pt1 As Point = New Point(startPt.X, startPt.Y)
Dim pt2 As Point = New Point(startPt.X + width, startPt.Y)
Dim pt3 As Point = New Point(startPt.X + width, startPt.Y + height)
Dim pt4 As Point = New Point(startPt.X, startPt.Y + height)
' Draw lines from each corner of the first rectangle to the corresponding corner of the second rectangle
g.DrawLine(Pens.Black, pt1, GetPt(pt1, depth))
g.DrawLine(Pens.Black, pt2, GetPt(pt2, depth))
g.DrawLine(Pens.Black, pt3, GetPt(pt3, depth))
g.DrawLine(Pens.Black, pt4, GetPt(pt4, depth))
' Draw the second rectangle
g.DrawRectangle(Pens.Black, GetPt(pt1, depth).X, GetPt(pt1, depth).Y, width, height)
End Sub
Rewrite both functions to use floating point data types instead of integers.
Here is the updated implementation of the "GetPt" function using floating point data types:
vbnetPublic Function GetPt(ByVal point As PointF, ByVal length As Single) As PointF
Dim x As Single = point.X + (length * Math.Cos(70 * Math.PI / 180))
Dim y As Single = point.Y + (length * Math.Sin(70 * Math.PI / 180))
Return New PointF(x, y)
End Function
And here is the updated implementation of the "DrawCuboid" function using floating point data types:
vbnetPublic Sub DrawCuboid(ByVal g As Graphics, ByVal startPt As PointF, ByVal width As Single, ByVal height As Single, ByVal depth As Single)
' Draw the first rectangle
g.DrawRectangle(Pens.Black, startPt.X, startPt.Y, width, height)
' Get the points for the four corners of the first rectangle
Dim pt1 As PointF = New PointF(startPt.X, startPt.Y)
Dim pt2 As PointF = New PointF(startPt.X + width, startPt.Y)
Dim pt3 As PointF = New PointF(startPt.X + width, startPt.Y + height)
Dim pt4 As PointF = New PointF(startPt.X, startPt.Y + height)
' Draw lines from each corner of the first rectangle to the corresponding corner of the second rectangle
g.DrawLine(Pens.Black, pt1, GetPt(pt1, depth))
g.DrawLine(Pens.Black, pt2, GetPt(pt2, depth))
g.DrawLine(Pens.Black, pt3, GetPt(pt3, depth))
g.DrawLine(Pens.Black, pt4, GetPt(pt4, depth))
' Draw the second rectangle
g.DrawRectangle(Pens.Black, GetPt(pt1, depth).X, GetPt(pt1, depth).Y, width, height)
End Sub