You can add the Object2D to a Group2D at a specific offset then use the group for transforming
[code]dim shape As new RectShape
shape.Width = 200
shape.Height = 80
shape.X = 100
shape.Y = 40
dim group As new Group2D
group.Append(shape)[/code]
Here the groups origin is at <0, 0>, which in the shapes reference frame is <-100, -40>. Rotating, scaling and translating the group effectively gives the shape the origin <-100, -40>.
Or are you trying to reposition an already appended shape, that is, you don’t want to give the shape an origin, you just want to arbitrarily rotate it. Or are you trying to have an adjustable origin?
As far as manually moving the coordinate, that code you posted has the formula
me.x = (origin.x + ((me.x - origin.x) * cos(rotation) - (me.y - origin.y) * sin(rotation)))
me.y = (origin.y + ((me.x - origin.x) * sin(rotation) + (me.y - origin.y) * cos(rotation)))
First translate so that the origin point is at <0, 0>
dx = x - origin.x
dy = y - origin.y
Then apply the rotation formula
xr = dx * cos(a) - dy * sin(a)
yr = dx * sin(a) + dy * cos(a)
Then translate <0, 0> back to the origin point
x = origin.x + xr
y = origin.y + yr
As an ostensibly optimized method; maybe make it extends…
[code]Sub rotateObj2D(obj As Object2D, rotateAngle As double, origin As Point)
dim sina, cosa, dx, dy As double
sina = sin(rotateAngle) //precompute
cosa = cos(rotateAngle)
dx = obj.X - origin.x
dy = obj.Y - origin.y
obj.X = origin.x + dx * cosa - dy * sina //rotate objs position
obj.Y = origin.y + dx * sina + dy * cosa
obj.Rotation = obj.Rotation + rotateAngle //and add angle of rotation
End Sub[/code]