变换形状 [英] Transforming a shape

查看:61
本文介绍了变换形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以特定方式连接两个点 - 请参见第一张图片.我知道所有四个点的坐标.然后我需要将整个形状移动到坐标 [0, 0] 并旋转它,所以主要的两个点都在 x 轴上(见第二张图).接下来我需要挤压"x 轴上的形状,使最后一个点的坐标为 [0, 1](见最后一张图片).

I have two points that I want to connect in a specific way - see the first picture. I know the coordinates of all four points. I then need to move the whole shape to coordinates [0, 0] and rotate it, so the main two points are both on x-axis (see the second picture). Next I need to "squeeze" the shape on the x-axis only so that the last point has coordinates [0, 1] (see the last picture).

我的问题是 - 如何在不涉及手动分析数学的情况下在 Java 中有效地计算中间两点的坐标?

My question is - how do I compute the coordinates of the middle two points effectively in Java without getting into manual analytical maths?

推荐答案

java.awt.geom.AffineTransform 可能是一个启动点.

这个程序应用了 3 个转换(以相反的顺序):

This program apply the 3 transformations (in reverse order):

import java.awt.geom.AffineTransform;

public class TransRotScal {

   public static void main( String[] args ) {
      double theta = Math.atan2( -15.0, 40.0 );
      AffineTransform trans = new AffineTransform(); // Identity
      trans.scale( 1/43.0, 1.0 );
      trans.rotate( theta );
      trans.translate( -10, -20 );
      double[] in = {
         10, 20,
         10, 30,
         50, 30,
         50, 35
      };
      double[] out = new double[in.length];
      trans.transform( in, 0, out, 0, in.length/2 );
      for( int ptNdx = 0; ptNdx < out.length; ptNdx += 2 ) {
         System.out.printf( "{%7.4f, %7.4f }\n", out[ptNdx], out[ptNdx+1]);
      }
   }
}

输出:

{ 0,0000,  0,0000 }
{ 0,0817,  9,3633 }
{ 0,9527, -4,6816 }
{ 0,9935,  0,0000 }

为了给出这个答案,我写了一个小程序,但我希望一个更简单的程序,为此我发布了这个问题:图的仿射变换,而不是文本和标签的仿射变换.

To give this answer, I've wrote a little program, but I wish a simpler one, and to do that I'm have post this question : Affine transforms for graph, not for text and labels.

这篇关于变换形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆