使用 Java Polygons 进行反射和其他转换
我正在开发一个项目,需要我进行简单的几何变换:
- 平移
- x 轴和 y 轴上的
反射在 Java
小程序上绘制的一些图形上。
前一个开发该小程序的人正在从代表每个图形顶点的笛卡尔点的数组中绘制图形。
我决定将这些图形表示为多边形,因为它为代码添加了一些更好的组织,我可以使用他用来构造一个的数组,而且因为我认为转换会变得更容易。
在发现 Polygon 没有任何反射方法后,我尝试了另一条路线:
我将 Polygon 转换为 Shape,然后转换为 Area,然后应用应该完成我想要的操作的 AffineTransform
; 不幸的是,Graphics 没有绘制 Area 对象的方法,而且我无法转换回形状。
那么,有谁知道使用多边形进行几何反射的方法吗? 或者,我可以通过其他方式执行此操作吗?
I'm working on a project that requires me to do simple geometrical transformations:
- translation
- reflection over x and y axis
On some figures drawn on a Java
applet.
The previous guy working on the applet was drawing the figures from arrays representing the caretesian points for the vertices of each figure.
I decided to represent the figures as Polygons because it added some nicer organization to the code, I could use the arrays he was using to construct one, and also because I figured transformations would become easier.
After finding Polygon didn't have any methods for reflection, I tried another route:
I cast the Polygon as a Shape, then an Area, and then applied a AffineTransform
that should have done what I wanted; unfortunately, Graphics doesn't have a method to draw Area objects, and I couldn't cast back into a shape.
So, does anyone know of a way to do geometric reflection using Polygons?
Or, is there some other means through which I could perform this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有什么理由不能为此编写自己的函数吗? 喜欢:
Is there any reason why you can't just write your own functions for this? Like: