I'm building a 2D level editor for my game, and you can deal with two types of geometries which are circles and polygons.
I've got it working so I can apply any transformation matrix to the polygons, and the vertices will transform correctly. I'm now thinking about ho开发者_StackOverfloww to apply the transformation matrix to a circle.
My circle is defined by a center position and a radius. The problem is that because the circle is only defined by one point, a matrix scale operation will result in the circle just being translated, not being scaled.
I'm not sure if this would work, but my solution was going to be when the circle was transformed, place two temporary vertices on the edge of the circle on opposite sides, apply the transformations to those vertices, and then recreate the position (midpoint between the two vertices) and radius (distance between the two vertices divided by 2).
Is there a better / easier way to transform a circle using transformation matrices?
I would take two points: the center of the circle and any point on the edge. That way, you already have the new center, and you just have to calculate the distance to get the radius. It's like you proposed, but slightly simpler.
精彩评论