C语言开发之实现直角坐标到极坐标的参考方法
来源:爱站网时间:2021-01-29编辑:网友分享
Python开发中使用二维数组实现直角坐标转换为极坐标,爱站技术频道小编主要为大家介绍的C语言开发之实现直角坐标到极坐标的参考方法,希望能为大家带来帮助。
Python开发中使用二维数组实现直角坐标转换为极坐标,爱站技术频道小编主要为大家介绍的C语言开发之实现直角坐标到极坐标的参考方法,希望能为大家带来帮助。
分享给大家供大家参考,具体如下:
#include#include struct complex_s{ double x,y; }; double real_part(struct complex_s z){ return z.x; } double img_part(struct complex_s z){ return z.y; } double magnitude(struct complex_s z){ return sqrt(z.x*z.x + z.y*z.y); } double angle(struct complex_s z){ return atan2(z.y, z.x); } struct complex_s make_from_real_img(double x, double y){ struct complex_s z; z.x = x; z.y = y; return z; } struct complex_s make_from_mag_ang(double r, double A){ struct complex_s z; z.x = r * cos(A); z.y = r * sin(A); return z; } struct complex_s add_complex(struct complex_s z1,struct complex_s z2){ return make_from_real_img(real_part(z1)+real_part(z2), img_part(z1) + img_part(z2)); } struct complex_s sub_complex(struct complex_s z1,struct complex_s z2){ return make_from_real_img(real_part(z1)-real_part(z2), img_part(z1) - img_part(z2)); } struct complex_s mul_complex(struct complex_s z1,struct complex_s z2){ return make_from_mag_ang(real_part(z1)*real_part(z2), img_part(z1) + img_part(z2)); } struct complex_s div_complex(struct complex_s z1,struct complex_s z2){ return make_from_mag_ang(real_part(z1)/real_part(z2), img_part(z1) + img_part(z2)); } int main(void){ struct complex_s z1 = {3.0,4.0}; struct complex_s z2= {2.0,5.0}; struct complex_s x; x = add_complex(z1,z2); printf("x={%f,%f}",x.x,x.y); return 0; }
结果:
[root@localhost struct]# ./jizuobiao.out x={5.000000,9.000000}
以上就是爱站技术频道小编为大家整理的C语言开发之实现直角坐标到极坐标的参考方法,不管怎么样,大家一定要选择正规、靠谱的平台学习,这样才能让顺利的进行下去。