本文共 506 字,大约阅读时间需要 1 分钟。
名称:0019 将极坐标转换为直角坐标
作者:丁进 时间:2021.2.18要求:
写一个程序把极坐标(r, θ) (θ单位为度)转换为直角坐标(X, Y)。转换公式是: x = r.cosθ y = r.sinθ 样例输入:10 45(代表r = 10 θ = 45°) 样例输出:7.071068 7.071068#include#include #define PI 3.1415926int main(){ double r, theta, x, y; printf("极坐标r值和theta值: "); scanf_s("%lf %lf", &r, &theta); //***double类型输入必须用%lf x = r * cos(theta/180*PI); y = r * sin(theta/180*PI); printf("直角坐标:(%f,%f)\n", x, y); //***double类型输出用%f,%lf都可以}
输出结果
极坐标r值和theta值: 10 45直角坐标:(7.071068,7.071068)
转载地址:http://kcqm.baihongyu.com/