#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<Windows.h>
#include<iostream>
#include<fstream>
#pragma warning(disable:4996)
#define pi 3.1415926
typedef struct cut
{
char ID[10];
double x;
double y;
double z;
}cutinfo;
int main{
cutinfo cut[1000] = { 0 };
int nNum;
FILE* fp = fopen("C:\\Users\\86159\\Desktop\\断面数据.txt", "r");
if (fp == NULL)
{
printf("not get it\n");
exit(0);
}
for (nNum = 3; nNum < 50; nNum++)
{
fscanf(fp, "%s,%lf,%lf,%lf\n", cut[nNum].ID, &cut[nNum].x, &cut[nNum].y, &cut[nNum].z);
printf("%lf,%lf,%lf\n", cut[nNum].x, cut[nNum].y, cut[nNum].z);
}
fclose(fp);
system("PAUSE");
return 0;
按照道理来说,是可以对x,y,z进行提取并计算的
我接下来的计算是
int i;
for (i=1;i<nNum;i++)
{
double z;
z=double deAB(cut[i].y,cut[i+1].y,cut[i+1].x,cut[i].x);
printf("%f/n",z);
}
double deAB(double YA, double YB, double XB, double XA)//计算坐标方位角
{
double AB;
double cyab, cxab;
cyab = YB - YA;
cxab = XB - XA;
AB = atan(cyab / cxab);
if (cyab > 0)
{
if (cxab > 0)
{
printf("degAB=%f", AB);
}
else if (cxab < 0)
{
AB = 180 - AB;
printf("degAB=%f", AB);
}
else
{
AB = 90.0;
printf("degAB=%f", AB);
}
}
else if (cyab < 0)
{
if (cxab < 0)
{
AB = 180 + AB;
printf("degAB=%f", AB);
}
else if (cxab > 0)
{
AB = 360 - AB;
printf("degAB=%f", AB);
}
else
{
AB = 270.0;
printf("degAB=%f", AB);
}
}
else if (cyab == 0)
{
if (cxab < 0)
{
AB = 180.0;
printf("degAB=%f", AB);
}
else
{
AB = 0.0;
printf("degAB=%f", AB);
}
}
return AB;
}
希望能够对此程序进行修改,写出修改后能提取并计算的版本,同时写出c++的文件提取x,y,z并计算的编程(本人在学c++,写好备注说明,谢谢了)
文件:链接: https://pan.baidu.com/s/1_wspk73oUnm5TS-jN53rvA?pwd=ccjv 提取码: ccjv
修改如下,供参考:
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<windows.h>
#include<iostream>
#include<fstream>
#pragma warning(disable:4996)
#define pi 3.1415926
typedef struct cut
{
char ID[10];
double x;
double y;
double z;
}cutinfo;
double deAB(double YA, double YB, double XB, double XA);//计算坐标方位角
int main() //main
{
cutinfo cut[1000] = { 0 };
char t_ID[128], t_x[128], t_y[128], t_z[128];
int nNum = 0, ret;
FILE* fp = fopen("C:\\Users\\86159\\Desktop\\断面数据.txt", "r");
if (fp == NULL)
{
printf("not get it\n");
exit(0);
}
ret = fscanf(fp, "%[^,],%[^,],%[^,],%[^\n]\n", t_ID, t_x, t_y, t_z);
while (ret != -1)
{
ret = fscanf(fp, "%[^,],%[^,],%[^,],%[^\n]\n", t_ID, t_x, t_y, t_z);
if (ret == 4) {
strcpy(cut[nNum].ID, t_ID); sscanf(t_x, "%lf", &cut[nNum].x);
sscanf(t_y, "%lf", &cut[nNum].y); sscanf(t_z, "%lf", &cut[nNum].z);
//printf("%s %lf %lf %lf\n", cut[nNum].ID, cut[nNum].x, cut[nNum].y, cut[nNum].z);
nNum++;
}
}
fclose(fp);
//printf("nNum=%d\n", nNum);
int i;
for (i = 0; i < nNum - 1; i++)
{
double z;
z = deAB(cut[i].y, cut[i + 1].y, cut[i + 1].x, cut[i].x);
printf("%f\n", z);
}
return 0;
}
double deAB(double YA, double YB, double XB, double XA)//计算坐标方位角
{
double AB;
double cyab, cxab;
cyab = YB - YA;
cxab = XB - XA;
AB = atan(cyab / cxab);
if (cyab > 0)
{
if (cxab > 0)
{
printf("degAB=%f", AB);
}
else if (cxab < 0)
{
AB = 180 - AB;
printf("degAB=%f", AB);
}
else
{
AB = 90.0;
printf("degAB=%f", AB);
}
}
else if (cyab < 0)
{
if (cxab < 0)
{
AB = 180 + AB;
printf("degAB=%f", AB);
}
else if (cxab > 0)
{
AB = 360 - AB;
printf("degAB=%f", AB);
}
else
{
AB = 270.0;
printf("degAB=%f", AB);
}
}
else if (cyab == 0)
{
if (cxab < 0)
{
AB = 180.0;
printf("degAB=%f", AB);
}
else
{
AB = 0.0;
printf("degAB=%f", AB);
}
}
return AB;
}
你好,我是有问必答小助手,非常抱歉,本次您提出的有问必答问题,超出我们目前的服务范围,暂时无法为您解答。
问答VIP目前服务范围为 :Python、Java、MySQL、Redis、MongoDB、HBase、Zookeeper、Kafka、Linux领域专业问题解答,为您提供解决问题的思路和指导。
不提供源码代写、项目文档代写、论文代写、安装包资源发送或安装指导等服务。
本次提问扣除的有问必答次数,会为您补发到账户,我们后续会持续优化,扩大我们的服务范围,为您带来更好地服务。