2

Knowing the center of rotation, start and end angles, inner an outer radius, how can this be achieved with MapBasic

Annular sector

2

You can create a function like this:

Function CreateAnnulusSector( ByVal oCenterPoint As Object
                            , ByVal fInnerRadius As Float   'in meters
                            , ByVal fOuterRadius As Float   'in meters
                            , ByVal fStartAngle As Float
                            , ByVal fEndAngle As Float
                            , ByVal nResolution As Integer
                            ) As Object

   Dim oSector, oCutter As Object
   Dim fAngle, fRotatedAngle, fX, fY, fDistance As Float
   Dim i As Integer

   CreateAnnulusSector = oCenterPoint

   '**Create concentric circle
   oSector = CartesianBuffer(oCenterPoint, nResolution, fOuterRadius, "m")
   oSector = Erase(oSector, CartesianBuffer(oCenterPoint, nResolution, fInnerRadius, "m"))

   '**Find center coordinates
   fX = CentroidX(oCenterPoint)
   fY = CentroidY(oCenterPoint)
   '**Calculate distance for cutter object
   fDistance = 3 * fOuterRadius

   '**Create cutter object
   Create Pline Into Variable oCutter
      1 (fX, fY)
   Alter Object oCutter
      Node Add (fX + fDistance, fY)

   fRotatedAngle = fEndAngle - fStartAngle
   If fRotatedAngle > 360 Then
      fRotatedAngle = fRotatedAngle - 360
   End If
   If fRotatedAngle < 0 Then
      fRotatedAngle = fRotatedAngle + 360
   End If

   For i = 4 To 1 Step -1
      If (i * 90) < fRotatedAngle Then
        Alter Object oCutter
            Node Add ( fX + ((Cos(fRotatedAngle * DEG_2_RAD)) * fDistance)
                     , fY + ((Sin(fRotatedAngle * DEG_2_RAD)) * fDistance))
        Exit For
    Else
        Alter Object oCutter
            Node Add ( fX + ((Cos((i * 90) * DEG_2_RAD)) * fDistance)
                     , fY + ((Sin((i * 90) * DEG_2_RAD)) * fDistance))
      End If
   Next

   '**Rotating cutter object to start angle
   oCutter = RotateAtPoint(oCutter, fStartAngle, oCenterPoint)
   '**Convert cutter polyline to a polygon
   oCutter = ConvertToRegion(oCutter)
   '**Erase the concentric circle with the cutter object
   oSector = Erase(oSector, oCutter)

   CreateAnnulusSector = oSector

End Function 

Clever mathematician could surely find an easier way to deal with the angles.

I use the way MapInfo Pro is working with angles here. The start from the East and move counter clockwise.

Also note that I'm using CartesianBuffer and some other logic that require you to work with a projected coordinate system - latitude/longitude will give you some issues.

  • Peter, Thanks for your answer. I'll give it a go and will let you know – Annulus Nov 20 '14 at 18:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.