Click to See Complete Forum and Search --> : need to tilt an ellipse


anonymous
03-03-2003, 10:04 AM
[Originally posted by sha]

Hi
I need to draw a tilted ellipse. it's quite simple to draw one parallel to x,y axis but I don't know how to tilt it by a given angle.
thanks

anonymous
03-03-2003, 11:38 AM
[Originally posted by Brent Coppock]

It is not possible to tilt the standard vb shape control within the interface of the shape control.˙ You would most likely need to use the shape control to program a new shape control with tilt capability.˙ Or find an existing shape control that has this functionality already in it.˙ You might be able to use the Windows API to tilt the VB shape control but I am not sure how that would be done.

Cheers,
Brent

anonymous
03-03-2003, 12:33 PM
[Originally posted by allen]

Here's an example.˙ The MatrixBuild and RotatePoint functions were taken from code posted in the Code Section of FreeVBCode.com by Alan Buzbee (Thanks Alan)

Save the text below to a .frm file, then open it in VB.

VERSION 5.00
Begin VB.Form Form1
˙ Caption˙ ˙ ˙ ˙ =˙ "Form1"
˙ ClientHeight˙ ˙ =˙ 3195
˙ ClientLeft˙ ˙ ˙ =˙ 60
˙ ClientTop˙ ˙ ˙ =˙ 345
˙ ClientWidth˙ ˙ =˙ 4680
˙ LinkTopic˙ ˙ ˙ =˙ "Form1"
˙ ScaleHeight˙ ˙ =˙ 3195
˙ ScaleWidth˙ ˙ ˙ =˙ 4680
˙ StartUpPosition =˙ 3˙ 'Windows Default
˙ Begin VB.TextBox txtYR
˙ ˙ ˙ Height˙ ˙ ˙ ˙ ˙ =˙ 285
˙ ˙ ˙ Left˙ ˙ ˙ ˙ ˙ ˙ =˙ 3120
˙ ˙ ˙ TabIndex˙ ˙ ˙ ˙ =˙ 5
˙ ˙ ˙ Text˙ ˙ ˙ ˙ ˙ ˙ =˙ "500"
˙ ˙ ˙ Top˙ ˙ ˙ ˙ ˙ ˙ =˙ 1440
˙ ˙ ˙ Width˙ ˙ ˙ ˙ ˙ =˙ 1215
˙ End
˙ Begin VB.TextBox txtXR
˙ ˙ ˙ Height˙ ˙ ˙ ˙ ˙ =˙ 285
˙ ˙ ˙ Left˙ ˙ ˙ ˙ ˙ ˙ =˙ 3120
˙ ˙ ˙ TabIndex˙ ˙ ˙ ˙ =˙ 3
˙ ˙ ˙ Text˙ ˙ ˙ ˙ ˙ ˙ =˙ "1500"
˙ ˙ ˙ Top˙ ˙ ˙ ˙ ˙ ˙ =˙ 1080
˙ ˙ ˙ Width˙ ˙ ˙ ˙ ˙ =˙ 1215
˙ End
˙ Begin VB.TextBox txtAngle
˙ ˙ ˙ Height˙ ˙ ˙ ˙ ˙ =˙ 285
˙ ˙ ˙ Left˙ ˙ ˙ ˙ ˙ ˙ =˙ 3120
˙ ˙ ˙ TabIndex˙ ˙ ˙ ˙ =˙ 1
˙ ˙ ˙ Text˙ ˙ ˙ ˙ ˙ ˙ =˙ "0"
˙ ˙ ˙ Top˙ ˙ ˙ ˙ ˙ ˙ =˙ 1800
˙ ˙ ˙ Width˙ ˙ ˙ ˙ ˙ =˙ 1215
˙ End
˙ Begin VB.CommandButton Command1
˙ ˙ ˙ Caption˙ ˙ ˙ ˙ =˙ "Draw"
˙ ˙ ˙ Height˙ ˙ ˙ ˙ ˙ =˙ 375
˙ ˙ ˙ Left˙ ˙ ˙ ˙ ˙ ˙ =˙ 2520
˙ ˙ ˙ TabIndex˙ ˙ ˙ ˙ =˙ 0
˙ ˙ ˙ Top˙ ˙ ˙ ˙ ˙ ˙ =˙ 600
˙ ˙ ˙ Width˙ ˙ ˙ ˙ ˙ =˙ 1815
˙ End
˙ Begin VB.Label Label3
˙ ˙ ˙ AutoSize˙ ˙ ˙ ˙ =˙ -1˙ 'True
˙ ˙ ˙ Caption˙ ˙ ˙ ˙ =˙ "Y Radius"
˙ ˙ ˙ Height˙ ˙ ˙ ˙ ˙ =˙ 195
˙ ˙ ˙ Left˙ ˙ ˙ ˙ ˙ ˙ =˙ 2400
˙ ˙ ˙ TabIndex˙ ˙ ˙ ˙ =˙ 6
˙ ˙ ˙ Top˙ ˙ ˙ ˙ ˙ ˙ =˙ 1485
˙ ˙ ˙ Width˙ ˙ ˙ ˙ ˙ =˙ 645
˙ End
˙ Begin VB.Label Label2
˙ ˙ ˙ AutoSize˙ ˙ ˙ ˙ =˙ -1˙ 'True
˙ ˙ ˙ Caption˙ ˙ ˙ ˙ =˙ "X Radius"
˙ ˙ ˙ Height˙ ˙ ˙ ˙ ˙ =˙ 195
˙ ˙ ˙ Left˙ ˙ ˙ ˙ ˙ ˙ =˙ 2400
˙ ˙ ˙ TabIndex˙ ˙ ˙ ˙ =˙ 4
˙ ˙ ˙ Top˙ ˙ ˙ ˙ ˙ ˙ =˙ 1125
˙ ˙ ˙ Width˙ ˙ ˙ ˙ ˙ =˙ 645
˙ End
˙ Begin VB.Label Label1
˙ ˙ ˙ Caption˙ ˙ ˙ ˙ =˙ "Angle:"
˙ ˙ ˙ Height˙ ˙ ˙ ˙ ˙ =˙ 255
˙ ˙ ˙ Left˙ ˙ ˙ ˙ ˙ ˙ =˙ 2520
˙ ˙ ˙ TabIndex˙ ˙ ˙ ˙ =˙ 2
˙ ˙ ˙ Top˙ ˙ ˙ ˙ ˙ ˙ =˙ 1845
˙ ˙ ˙ Width˙ ˙ ˙ ˙ ˙ =˙ 615
˙ End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Type TDPoint
x As Double
y As Double
z As Double
End Type

Dim RM(0 To 3, 0 To 3) As Double

Private Sub MatrixBuild(ByVal x As Double, ByVal y As Double, ByVal z As Double)
' this sub builds the rotation matrix with x, y and z as axis angles
Dim SinX, CosX, SinY, CosY, SinZ, CosZ, C1, C2

SinX = Sin(x)
CosX = Cos(x)
SinY = Sin(y)
CosY = Cos(y)
SinZ = Sin(z)
CosZ = Cos(z)

'For C1 = 0 To 3 'identity matrix
'For C2 = 0 To 3
'If C1 = C2 Then
'˙ ˙ RM(C1, C2) = 0
'Else
'˙ ˙ RM(C1, C2) = 1
'End If
'Next C2
'Next C1

RM(0, 0) = (CosZ * CosY)
RM(0, 1) = (CosZ * -SinY * -SinX + SinZ * CosX)
RM(0, 2) = (CosZ * -SinY * CosX + SinZ * SinX)
RM(1, 0) = (-SinZ * CosY)
RM(1, 1) = (-SinZ * -SinY * -SinX + CosZ * CosX)
RM(1, 2) = (-SinZ * -SinY * CosX + CosZ * SinX)
RM(2, 0) = SinY
RM(2, 1) = CosY * -SinX
RM(2, 2) = CosY * CosX
End Sub

Private Function RotatePoint(ByVal x As Integer, ByVal y As Integer, ByVal z As Integer) As TDPoint
' finds new point using Rotate Matrix with x, y and z as current point positions
Dim TempPoint As TDPoint
TempPoint.x = (x * RM(0, 0)) + (y * RM(0, 1)) + (z * RM(0, 2)) + RM(0, 3)
TempPoint.y = (x * RM(1, 0)) + (y * RM(1, 1)) + (z * RM(1, 2)) + RM(1, 3)
TempPoint.z = (x * RM(2, 0)) + (y * RM(2, 1)) + (z * RM(2, 2)) + RM(2, 3)

RotatePoint = TempPoint
End Function

Private Sub Command1_Click()
Dim pt As TDPoint
Dim xi As Long, yi As Long, a As Double, r As Double, xr As Long, yr As Long
Dim cx As Long, cy As Long, i As Integer
Dim rot As Double

cx = Me.Width / 2
cy = Me.Height / 2
xr = Val(txtXR.Text)
yr = Val(txtYR.Text)
rot = Val(txtAngle.Text)

MatrixBuild 0, 0, 3.1415926 * 2 / 360 * (rot)


For i = 0 To 360
˙ a = 3.1415926 * 2 / 360 * (i)
˙ pt = RotatePoint(xr * Cos(a), yr * Sin(a), 0)
˙ xi = cx + pt.x
˙ yi = cy + pt.y
˙ ˙ ˙ If i = 0 Then
˙ ˙ Me.CurrentX = xi
˙ ˙ Me.CurrentY = yi
˙ ˙ Else
˙ ˙ Me.Line -(xi, yi)
˙ End If
Next



End Sub