Home > Software engineering >  Known to any two points, as the long axis of the ellipse two endpoints, and short axis length, survi
Known to any two points, as the long axis of the ellipse two endpoints, and short axis length, survi

Time:10-25

Any two points is known, as the long axis of the ellipse two endpoints, and short axis length, survival into elliptical code

Is first point two times as long axis, automatically generate a perpendicular bisector, then define a short axis endpoint, thus know short axial length,

Note is arbitrary Angle either horizontal or vertical,

I this kind of code but debugging of ellipse is not too much, always partial


 Private Sub drawC (objName As Object, As point p1, p2 As point, As Single b) 
'input x1, x2, y1, y2, b long axis line endpoint, length of short half axis
Dim x1 As Single
Dim x2 As Single
Dim y1 As Single
Dim y2 As Single
Dim x0 As Single center
'Dim y0 As Single center
'Dim As a Single 'long axis half
Dim k1 As Single slope
'Dim theta Angle As Single '
Dim temp As point


X1=p1. X
X2=p2. X
Y1=p1. Y
Y2=p2. Y

X0=(x1 + x2)/2 'anchor point
Y0=(y1 and y2)/2


If x1 x2=Then 'theta equals PI/2 or 3 PI/2
A=(Abs (y1, y2))/2
X0=x1
Y0=0.5 * (y1 and y2)
For I=1 To 360 Step 1
ObjName. Circle (x0, y0), a, QBColor (12), the Arc * (I - 1), the Arc * 1, (a/b)
Next I
The Exit Sub
End the If

K1=(y2 - y1)/(x2 - x1)
Theta=180 * Atn ((y2 - y1)/(x2 - x1))/3.1415926
A=Sqr ((x2 - x1) ^ 2 + (y2 - y1) ^ 2)/2
N=100 'in the period of 2 PI score
Dt=2 * 3.1415926/n
T=0
If Tan (theta) & gt; Then '0 0 & lt; Theta & lt; PI/2 or piCurrentX=0.5 * (x1 + x2) + b * k1/Sqr (k1 ^ 2 + 1)
CurrentY=0.5 * (y1 and y2) + b/Sqr (k1 ^ 2 + 1)
ElseIf Tan (theta) & lt; 0 Then 'PI/2 & lt; Theta & lt; PI or 3 PI/2 & lt; Theta & lt; 2 PI
CurrentX=0.5 * (x1 + x2) - b * k1/Sqr (k1 ^ 2 + 1)
CurrentY=0.5 * (y1 and y2) - b/Sqr (k1 ^ 2 + 1)
Else '=Y1 Y2, theta equals zero or PI PI/2
CurrentX=0.5 * (x1 + x2)
CurrentY=0.5 * (y1 and y2)
End the If
ObjName. PSet (CurrentX, CurrentY), vbRed
'objName. PSet (x0, y0), vbYallow
For j=0 To n
Temp. X=x0 + a * Cos (theta) * Sin (t) - b * Sin (theta) * Cos (t)
Temp.=y0 y + a * Sin (theta) * Sin (t) - b * Cos (theta) * Cos (t)
ObjName. Line - (temp. X, temp., y), QBColor (12)
T=t + dt
Next j

End Sub

CodePudding user response:

Find a function, and the Internet and a are not right, also not the same as two math is not good, please to see

 Private Sub drawC2 (objName As Object, As Single x, y, As Single As a Single, As Single b, c As Single, petColor As OLE_COLOR, d As an Integer) 
Dim t As Double
Dim tempx As Single
Dim tempy As Single
Dim x1 As Single
Dim y1 As Single
Dim c1 As Single
ObjName. DrawWidth=d
C1=- Atn 45 * (1)/c
For t=3.1415926535 To 3.1415926535 Step 0.003
Tempx=Cos (t) * a
Tempy=Sin (t) * b
X1=x + tempx * Cos (c1) - tempy * Sin (c1)
Y1=y + tempx * Sin (c1) + tempy * Cos (c1)
ObjName. PSet (x1, y1), petColor
Next t

End Sub

CodePudding user response:

1)
Draw the ellipse, then the translation, rotation, elliptical image
2)
Write elliptic equations, translation, rotation, new elliptic equation is obtained, and then make your own interpolation algorithm, draw the ellipse,

CodePudding user response:

Private Declare the Function the Ellipse Lib "gdi32" (ByVal HDC As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long


Do you know the coordinates of the long axis, also know the length of the short axis, should it is easy to determine the draw area at the upper left of the rectangle and the coordinates of the lower right corner, know after, can use: Elipse plotted,

CodePudding user response:

Simple example, the Picture1 with elliptical
 
'define several constants and functionPublic Const r_pi=3.14159265758979 ', 3.14159265358979323846
Public Const d_pi=180


As Function d2r (a Double) As a Double
D2r=a * r_pi/d_pi
End the Function

As Function r2d (a Double) As a Double
R2d=a * d_pi/r_pi
End the Function

As Function SinD (a Double) As a Double
SinD=Sin (d2r) (a)
End the Function

As Function CosD (a Double) As a Double
CosD=Cos (d2r) (a)
End the Function

'draw ellipse
Private Sub Command1_Click ()
Dim x As Single, y As Single
Dim x1 As Single, y1 As Single
Dim As a Single
Dim As Double b
Dim alpha As Double


'
'the parametric equation of ellipse
'x=a cosine (alpha)
'y=b sin (alpha)
'
'
Dim beta As a Double

Dim theta As Long
Dim sc As Long
Sc=8
For theta=0 To 360 * sc
A=1400
B=1200
Beta=60

X0=1500
Y0=2400

Alpha=theta * 1 #


X1=a + a * SinD (alpha/sc)
Y1=b + b * CosD (alpha/sc)

X=x0 + x1 x SinD (beta) + y1 * CosD (beta)
Y=y0 + x1 * CosD (beta) - y1 * SinD (beta)

Picture1. PSet (x, y), RGB (200, 100, 100)

Next is

End Sub

CodePudding user response:

3/f,
 Private Declare the Function the Ellipse Lib "gdi32" (ByVal HDC As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long 
Private Sub Command1_Click ()
The Ellipse Picture1. HDC, 500, 0, 0, 300
End Sub

CodePudding user response:

Call API draw ellipse axle not on the axis direction, the need to do the following processing
1) coordinate translation and rotation this must master
2) the Ellipse drawing
3) to use the path keep drawing parameters, in order to rotate coordinates
4) after the rotation of the path charted
Want to use the following API

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related