Implemented using a planar array of geometric transformation point

Learning job record

The title dimensional plane to achieve geometric transformation point, reading the coordinates of points, and the type of transformation parameters, and then outputs the transformed coordinate geometry.

Input formats:

Plane coordinates of the point pairs, separated by a comma between two values, data types are integer. Transform type represented as an integer number, corresponding 1,2,3 translation, scaling and rotation. Translation parameter coordinate form, separated by commas, the data type is double. Two scaling parameters separated by commas, type double. The rotation angle of rotation angle, counterclockwise positive, negative values ​​indicate clockwise integer.

Output formats:

Output coordinate point after rotation, between a coordinate pair separated by commas, int.

Sample input:

The following is a translation transform inputs. For example:
5,7
1
1.2,2

Sample output:

Given here corresponding output. For example:
6,9

Sample Input 2:

The following is a rotational input transformation. For example:
1,0
. 3
90

Output Sample 2:

Given here corresponding output. For example:
0,1

import java.util.Scanner;
import static java.lang.Math.cos;
import static java.lang.Math.sin;

public class Main {
    public static void main(String[] args) {
        Scanner sc =new Scanner(System.in);
        String str = sc.next();
        int ch=sc.nextInt();
        String [] s = str.split(",");
        int x=Integer.parseInt(s[0]);
        int y =Integer.parseInt(s[1]);

        if(ch==1){

            String str1 =sc.next();
            String [] s1 =  str1.split(",");
            double x1=Double.parseDouble(s1[0]);
            double y1=Double.parseDouble(s1[1]);
            int a =(int)(x1+x);
            int b =(int)(y1+y);
            System.out.println(a+","+b);

        }else if(ch==2){
            String str2 =sc.next();
            String [] s2 =  str2.split(",");
            double x2=Double.parseDouble(s2[0]);
            double y2=Double.parseDouble(s2[1]);
            int c =(int)(x2*x);
            int d =(int)(y2*y);
            System.out.println(c+","+d);
        }else if(ch==3){
            int w=sc.nextInt();
            int e =(int)(x*cos(Math.toRadians(w))-y*sin(Math .toRadians(w)));
            int f =(int)(y*cos(Math.toRadians(w))+x*sin(Math .toRadians(w)));
            System.out.println(e+","+f);

        }else
            return;
    }
}

J77
Released seven original articles · won praise 2 · Views 100

Guess you like

Origin blog.csdn.net/weixin_46053704/article/details/105393166