用matlab 画一个椭圆,如何保存椭圆周上的点的坐标,谢谢
3个回答
展开全部
,y1)和(x2,y2)
求椭圆步骤:
1、求a,b: a=len/2 b=sqr((x1-x2)^2+(y1-y2)^2)
2、求旋转角α :求出(y1-y2)/(x1-x2)的反正切值即为α
3、求椭圆中心坐标(x0,y0): x0=(x1+x2)/2 y0=(y1+y2)/2
3、计算椭圆上点的坐标(x,y):
x=acosθ , y=bsinθ ( 0<=θ< 2*π)
4、计算图形绕原点旋转α 弧度后的坐标(xx,yy):
xx=x*cos(-α )+y*sin(-α )
yy=-x*sin(-α )+y*cos(-α )
5、计算椭圆中心从原点平移到(x0,y0)后椭圆上点的坐标(xxx,yyy):
xxx=xx+x0
yyy=yy+y0
6、在坐标(xxx,yyy)处画一各点
7、在( 0<=θ< 2*π)范围内,按一定间隔取值,重复3-7步骤,即得所要求的椭圆。
以下是vb写的简单示例,新建一各工程,把代码粘贴进去替换原来的所有代码,运行即可看效果
Option Explicit
Dim X1, Y1, X0, Y0, X2, Y2 As Double
Dim A, B, PI As Double
Dim F As Boolean
Private Sub Form_Load()
PI = 3.14159265358979
F = False
DrawWidth = 2
Width = 10000
Height = 8000
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
X1 = X
Y1 = Y
B = 1000
F = True
End Sub
Public Sub tuoYuan()
Dim Jiao As Double
Dim i, m, n, m1, n1 As Double
Cls
X0 = (X1 + X2) / 2
Y0 = (Y1 + Y2) / 2
A = Sqr((X0 - X2) ^ 2 + (Y0 - Y2) ^ 2)
If X1 <> X2 Then
Jiao = Atn((Y1 - Y2) / (X1 - X2))
Else
Jiao = PI / 2
End If
Form1.PSet (X1, Y1), RGB(255, 0, 0)
Form1.PSet (X0, Y0), RGB(255, 0, 0)
Form1.PSet (X2, Y2), RGB(255, 0, 0)
For i = 0 To PI * 2 Step 0.01
m = A * Cos(i)
n = B * Sin(i)
'Form1.PSet (m + X0, n + Y0), RGB(255, 0, 0)
m1 = m * Cos(-Jiao) + n * Sin(-Jiao)
n1 = -m * Sin(-Jiao) + n * Cos(-Jiao)
Form1.PSet (m1 + X0, n1 + Y0), RGB(0, 255, 0)
Next i
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If F = True Then
X2 = X
Y2 = Y
Call tuoYuan
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
F = False
X2 = X
Y2 = Y
Call tuoYuan
End Sub
求椭圆步骤:
1、求a,b: a=len/2 b=sqr((x1-x2)^2+(y1-y2)^2)
2、求旋转角α :求出(y1-y2)/(x1-x2)的反正切值即为α
3、求椭圆中心坐标(x0,y0): x0=(x1+x2)/2 y0=(y1+y2)/2
3、计算椭圆上点的坐标(x,y):
x=acosθ , y=bsinθ ( 0<=θ< 2*π)
4、计算图形绕原点旋转α 弧度后的坐标(xx,yy):
xx=x*cos(-α )+y*sin(-α )
yy=-x*sin(-α )+y*cos(-α )
5、计算椭圆中心从原点平移到(x0,y0)后椭圆上点的坐标(xxx,yyy):
xxx=xx+x0
yyy=yy+y0
6、在坐标(xxx,yyy)处画一各点
7、在( 0<=θ< 2*π)范围内,按一定间隔取值,重复3-7步骤,即得所要求的椭圆。
以下是vb写的简单示例,新建一各工程,把代码粘贴进去替换原来的所有代码,运行即可看效果
Option Explicit
Dim X1, Y1, X0, Y0, X2, Y2 As Double
Dim A, B, PI As Double
Dim F As Boolean
Private Sub Form_Load()
PI = 3.14159265358979
F = False
DrawWidth = 2
Width = 10000
Height = 8000
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
X1 = X
Y1 = Y
B = 1000
F = True
End Sub
Public Sub tuoYuan()
Dim Jiao As Double
Dim i, m, n, m1, n1 As Double
Cls
X0 = (X1 + X2) / 2
Y0 = (Y1 + Y2) / 2
A = Sqr((X0 - X2) ^ 2 + (Y0 - Y2) ^ 2)
If X1 <> X2 Then
Jiao = Atn((Y1 - Y2) / (X1 - X2))
Else
Jiao = PI / 2
End If
Form1.PSet (X1, Y1), RGB(255, 0, 0)
Form1.PSet (X0, Y0), RGB(255, 0, 0)
Form1.PSet (X2, Y2), RGB(255, 0, 0)
For i = 0 To PI * 2 Step 0.01
m = A * Cos(i)
n = B * Sin(i)
'Form1.PSet (m + X0, n + Y0), RGB(255, 0, 0)
m1 = m * Cos(-Jiao) + n * Sin(-Jiao)
n1 = -m * Sin(-Jiao) + n * Cos(-Jiao)
Form1.PSet (m1 + X0, n1 + Y0), RGB(0, 255, 0)
Next i
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If F = True Then
X2 = X
Y2 = Y
Call tuoYuan
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
F = False
X2 = X
Y2 = Y
Call tuoYuan
End Sub
展开全部
matlab根据函数画的,你用函数生成坐标就行了啊。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询