4

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).

problem illustration

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

kenor
  • 1,888
  • 2
  • 16
  • 27
  • You may pray or give this job to a friend... Rotation, translation and scaling are supported by most UI engine and refer to maths... – Aubin Mar 31 '13 at 20:58
  • @Aubin Sure, I do not want to draw the shape, just compute the missing coordinates using some Java transformation tools that I am not aware of (without getting into analytical geometry). – kenor Mar 31 '13 at 21:05
  • Program done, thanks to java.awt.geom. – Aubin Mar 31 '13 at 21:43
  • I have done a suite to your question: http://stackoverflow.com/questions/15742563/affine-transforms-for-graph-not-for-text-and-labels – Aubin Apr 01 '13 at 11:27

1 Answers1

3

java.awt.geom.AffineTransform may be a startup point.

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]);
      }
   }
}

Outputs:

{ 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.

Community
  • 1
  • 1
Aubin
  • 14,617
  • 9
  • 61
  • 84