Description 平面上有若干个点,对这些点进行平移或旋转操作。 Input 有多组数据。 每组数据的前两个数是点的坐标。第三个数是一个整数,1表示移动,2表示旋转。如果移动,则后两位是在两个方向平移距离;如果是旋转,则其后的两个数字是旋转参考点坐标,最后一个数字是旋转角度。 Output 平移或旋转后的点坐标,保留两位小数。 Sample Input 123.45 98.76 1 45.78 -68 837 634.34 2 -46.87 -837.75 64.78 Sample Output (169.23,30.76) (-1002.03,589.12)
时间: 2024-03-21 16:44:37 浏览: 15
下面是一个Java语言的程序,可以实现对每组输入数据进行平移或旋转操作,并输出结果:
```
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
double x = scanner.nextDouble();
double y = scanner.nextDouble();
int op = scanner.nextInt();
if (op == 1) {
double dx = scanner.nextDouble();
double dy = scanner.nextDouble();
x += dx;
y += dy;
} else {
double x0 = scanner.nextDouble();
double y0 = scanner.nextDouble();
double angle = scanner.nextDouble();
double dx = x - x0;
double dy = y - y0;
double cos = Math.cos(Math.toRadians(angle));
double sin = Math.sin(Math.toRadians(angle));
double newX = dx * cos - dy * sin + x0;
double newY = dx * sin + dy * cos + y0;
x = newX;
y = newY;
}
System.out.printf("(%.2f,%.2f)\n", x, y);
}
}
}
```
程序首先读入一个点的坐标和操作类型,然后根据操作类型进行平移或旋转操作。如果是平移操作,则读取平移距离,并将点的坐标加上平移距离;如果是旋转操作,则读取旋转参考点的坐标和旋转角度,并根据公式计算旋转后的点的坐标。最后输出结果,保留两位小数。程序使用了Java语言提供的Math库中的cos()、sin()等函数。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)