Srinath

02-06-2005, 06:50 AM

Hi,

Plz help me. I need to display the text around ellipse as shown in fig. in visual basic. Plz let me know how to do that.

ThankQ

eXeption

02-11-2005, 10:39 AM

Hi,

Plz help me. I need to display the text around ellipse as shown in fig. in visual basic. Plz let me know how to do that.

ThankQ

Shall I suggest something?!

A way to do this is to sub-divide an ellipse into smaller line segments. Let the number of line segments be 'N', and the length of the string to be wrapped around them be 'Sn', such that

Sn = Len("Test String")

Now we can set a spacing variable 'SpcVal' which denotes, the number of line segments between two consecutive characters in the string after it has been wrapped to the ellipse; very simple to compute... SpcVal = N/Sn

Now we know corresponding to which all subdivided line segments, we have to write each characters in the string;

ie First character in the string shall be written on '0'th line segment, then the second character on 'Spcval'th line segment... ie 'n'th character shall be written on 'n * SpcVal'th line segment...

Now we've decided which all characters are to written on which all line segments, How to do it is to compute the position and the angle for each character according to the position and slope of the corresponding line segment and to draw it.

The position can be calculated easily, now the angle is the angle of the 'normal' of the line segment making with horizontal.

see attatched image...

Here is a simple way to subdivide an ellipse! The ellipse is drawn on the form using small line segments, whose size can be controlled by using the 'dtheta' parameter.

' Start a new project and paste this as the form's code!

Option Explicit

Const pi = 3.14159265358979

Private Sub Form_Click()

Dim xmax&, ymax&

xmax = Me.ScaleWidth

ymax = Me.ScaleHeight

DrawEllipse Rnd() * xmax, Rnd() * ymax, Rnd() * xmax, Rnd() * ymax

End Sub

Private Sub Form_Load()

Randomize

Me.AutoRedraw = True

Me.ScaleMode = vbPixels

End Sub

Sub DrawEllipse(ByVal x#, ByVal y#, ByVal xx#, ByVal yy#)

Dim cx#, cy#, px#, py#, xp#, yp#

Dim theta#, dtheta#, a#, b#

cx = x + (xx - x) / 2#

cy = y + (yy - y) / 2#

a = (xx - x) / 2#

b = (yy - y) / 2#

dtheta = 0.05

For theta = 0# To 2 * pi + dtheta Step dtheta

xp = cx + a * Cos(theta)

yp = cy + b * Sin(theta)

If theta <> 0 Then Me.Line (xp, yp)-(px, py)

px = xp: py = yp

Next theta

Me.Refresh

End Sub

Regards,

'

HK