mapbasic code to create 10 points in a single long/lat without overlapping to each other

829 views Asked by At

Good day! I know how to create a points in a mapbasic having a single long/lat, but i wanted to create 10 points on a single coordinates without overlapping to each other but separated by about 5m radius apart from the given coordinates.

Any idea how should i start coding this.

br, Ivan

1

There are 1 answers

0
Wernfried Domscheit On

In principal it looks like this

Dim x,y as Float
Dim offset as Integer

offset = 5 'distance 5 meters

'single coordinate
x = 1000
y= 2000

For i = 1 To 10
   Create Point (x + Cos(i * (360/10) * DEG_2_RAD) * offset, y + Sin(i * (360/10) * DEG_2_RAD) * offset)
Next

Please note, this works properly only for cartesian coordinate system, e.g. UTM. If you work on Lat/lon you have to do some additinal trigonometry for the offset.

Update

Have also a look at function CartesianOffset( object, angle, distance, units ) and CartesianOffsetXY( object, xoffset, yoffset, units ), maybe they are easier to use.

Dim obj as Object        
obj = CreatePoint(1000, 2000) 'Start point

For i = 1 To 10
    Create Point(CentroidX(obj), CentroidY(obj))
    obj = CartesianOffset(obj, -10, 5, "m") ' move by 5 meters for -10°
Next