home *** CD-ROM | disk | FTP | other *** search
- Attribute VB_Name = "modCloud"
- '******************************************************************'
- '* *'
- '* TurboCAD for Windows *'
- '* Copyright (c) 1993 - 2001 *'
- '* International Microcomputer Software, Inc. *'
- '* (IMSI) *'
- '* All rights reserved. *'
- '* *'
- '******************************************************************'
-
- ' Converts a selected polyline into a "cloud"
- Public Sub Cloud()
-
- Dim ActDr As Drawing
- Dim Grs As Graphics
- Dim GrPolygon As Graphic, GrCloud As Graphic
- Dim Vers As Vertices
- Dim Ver As Vertex, Ver1 As Vertex, Ver2 As Vertex
- Dim x As Double, y As Double, a As Double, alpha As Double, beta As Double, Pi As Double
-
- Set ActDr = IMSIGX.Application.ActiveDrawing
-
- If ActDr.Selection.Count = 0 Then
- Beep
- MsgBox "Please select a polyline to convert"
- Else
- Set GrPolygon = ActDr.Selection.Item(0)
- ' convert the segments into double arcs
- Set Vers = GrPolygon.Vertices
- n = Vers.Count
-
- ' find out the direction
- Area = PolyArea(GrPolygon)
- Direction = Sgn(Area)
-
- Set GrCloud = ActDr.Graphics.Add(imsiGroup) ' will be a group
-
- For i = 1 To n - 1
-
- Set Ver1 = Vers.Item(i - 1)
- Set Ver2 = Vers.Item(i)
-
- Pi = (Atn(1) * 4)
- a = Atn2(Ver2.y - Ver1.y, Ver2.x - Ver1.x)
- If Direction > 0 Then
- alpha = Pi + a
- beta = 2 * Pi + a
- Else
- alpha = a
- beta = Pi + a
- End If
- ' add another vertex 2/3 from the first
- x = (Ver1.x + Ver2.x * 2) / 3
- y = (Ver1.y + Ver2.y * 2) / 3
-
- Set newarc = GrCloud.Graphics.AddArcCenterAndPoint((Ver1.x + x) / 2, (Ver1.y + y) / 2, 0, x, y, 0, alpha, beta)
- Set newarc = GrCloud.Graphics.AddArcCenterAndPoint((x + Ver2.x) / 2, (y + Ver2.y) / 2, 0, Ver2.x, Ver2.y, 0, alpha, beta)
-
- Next i
-
- GrPolygon.Unselect
- GrPolygon.Delete
- GrCloud.Select
-
- End If
-
- End Sub
-
- Function Atn2(dy As Double, dx As Double) As Double
-
- Dim Pi As Double
-
- Pi = (Atn(1) * 4)
- If dx <> 0 Then
- If dx > 0 Then
- retval# = Atn(dy / dx)
- Else
- retval# = Atn(dy / dx) + Pi
- End If
- Else
- retval# = Pi / 2 * Sgn(dy)
- End If
- Atn2 = retval#
-
- End Function
-
- Function PolyArea(Gr As Graphic) As Double
-
- Dim i As Integer
- Dim Vers As Vertices
- Dim Ver1 As Vertex, Ver2 As Vertex
- Dim Area As Double
- Area = 0
- Set Vers = Gr.Vertices
- ' for all vertices, find the area (using cross product)
- For i = 0 To Vers.Count - 2
- Set Ver1 = Vers.Item(i)
- Set Ver2 = Vers.Item(i + 1)
- ' i j k
- ' x1 y1 z1
- ' x2 y2 z2
- ' area = half the length of the cross product
- x1 = Ver1.x
- y1 = Ver1.y
- z1 = Ver1.Z
- x2 = Ver2.x
- y2 = Ver2.y
- z2 = Ver2.Z
- xx = y1 * z2 - y2 * z1
- yy = x1 * z2 - x2 * z1
- zz = x1 * y2 - x2 * y1
- Area = Area + Sqr(xx * xx + yy * yy + zz * zz) * Sgn(zz)
- Next i
- PolyArea = Area
-
- End Function
-