高分求 编程 c语言 已知2点求角度
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了高分求 编程 c语言 已知2点求角度相关的知识,希望对你有一定的参考价值。
c c++语言里 已知2点坐标求出此2点构成直线的角度 并求出再此之后新的不同的2点构成直线与之前直线的角度差或者弧度差
回答正确后再追加100分
其实思路我有 和你的基本一样 但是写出的代码 总是不对 所有希望是源码
#include<stdlib.h>
#include<math.h>
#define pi 3.1415926
struct point
double X;
double Y;
;
struct line
point A;
point B;
double deg;
;
int main( )
line lineA;
line lineB;
double tmp;
printf("请输点坐标(x,y)构造第一条直线\n");
printf("第一点x与y:");
scanf( "%lf%lf", &lineA.A.X, &lineA.A.Y );
printf("第二点x与y:");
scanf( "%lf%lf", &lineA.B.X, &lineA.B.Y );
//求角度
tmp=(lineA.B.Y-lineA.A.Y)/(lineA.B.X-lineA.A.X);
lineA.deg=atan(tmp);
lineA.deg=lineA.deg*double(180)/pi;
printf( "第一条直线斜线角度:%lf,%lf\n", tmp,lineA.deg );
printf("请输点坐标(x,y)构造第二条直线\n");
printf("第一点x与y:");
scanf( "%lf%lf", &lineB.A.X, &lineB.A.Y );
printf("第二点x与y:");
scanf( "%lf%lf", &lineB.B.X, &lineB.B.Y );
//求角度
tmp=(lineB.B.Y-lineB.A.Y)/(lineB.B.X-lineB.A.X);
lineB.deg=atan(tmp);
lineB.deg=lineB.deg*double(180)/pi;
printf( "第二条直线斜线角度:%lf,%lf\n", tmp,lineB.deg );
printf( "两条直线角度差:%lf\n", lineA.deg-lineB.deg );
return 0;
/*
atan等三角函数算出来的是pi形式的,看看45度的:
printf("%f\n",tan(double(45)/double(180)*pi));
printf("%f\n",atan(1)*double(180)/pi);
写的真累,看你题目是C语言,所以没用C++类来写
用类来写,又好写,又好读,又不容易出错
point点(x,y)其实可以直接用COORD,又怕你没有数据结构COORD
比如:
struct line
point A;
point B;
double deg;
;
改成
struct line
COORD dian; //COORD编译器数据结构dian有dian.X和dian.Y
double deg;
;
*/ 参考技术A 虽然分数很高,但还是懒得写代码,给出思路供参考
把第一个点作为原点,先求出目标点的相对位置及所在象限,用反sin函数求出角度
第二条直线需要平移到上面使用的原点,然后角度就出来了 参考技术B #include<stdio.h>
#define N 80/*宏定义N为80*/
int fun(char *str)/*声明调用函数fun*/
int i,n=0,fg=1;/*定义变量i,n,fg*/
char *p=str;/*指针p指向字符数组*/
while (*p)/*while语句循环统计字符串长度*/
n++;
p++;
for (i=0;i<n/2;i++)
if (str[i]==str[n-1-i]);/*for循环判断顺读和倒读是否都是一样的字符串并维持fg原来的值1*/
else
fg=0;/*否则改变fg的值为0,然后跳出循环*/
break;
return fg;/*返回fg的值*/
main()/*主函数*/
char s[N];/*定义数组s*/
printf("Enter a string:"); gets(s);/*输入字符串*/
printf("\n\n");puts(s);/*空格后输出字符串*/
if(fun(s)) printf("YES\n");/*调用函数fun如果返回值是1输出YES*/
else printf("NO\n");/*否则输出NO*/
getch();/*此语句用来从键盘输入缓冲区读取下一个键盘输入字符的,返回值为读取的字符*/
如果还没解决你的问题,可以加我百度HI账号。 参考技术C int fun(char *str)/*声明调用函数fun*/
int i,n=0,fg=1;/*定义变量i,n,fg*/
char *p=str;/*指针p指向字符数组*/
while (*p)/*while语句循环统计字符串长度*/
n++;
p++;
for (i=0;i<n/2;i++)
if (str[i]==str[n-1-i]);/*for循环判断顺读和倒读是否都是一样的字符串并维持fg原来的值1*/
else
fg=0;/*否则改变fg的值为0,然后跳出循环*/
break;
return fg;/*返回fg的值*/ 参考技术D #include <stdio.h>
#include <math.h>
#define __pi 3.1415926535897932384626433832795
int main()
int x0, y0, x1, y1;
scanf("%d%d", &x0, &y0);
if (x0 != 0)
printf("%.4f\n", atan((double)y0 / x0) / __pi * 180);
else
puts("Input error.");
return 0;
scanf("%d%d", &x1, &y1);
if (x1 != 0)
printf("%.4f\n", (atan((double)y1 / x1) - atan((double)y0 / x0)) / __pi * 180);
else
puts("Input error.");
return 0;
TOJ 2392 Bounding box(已知正n边形三点求最小矩形覆盖面积)
描述
The Archeologists of the Current Millenium (ACM) now and then discover ancient artifacts located at vertices of regular polygons. The moving sand dunes of the desert render the excavations difficult and thus once three vertices of a polygon are discovered there is a need to cover the entire polygon with protective fabric.
输入
Input contains multiple cases. Each case describes one polygon. It starts with an integer n <= 50, the number of vertices in the polygon, followed by three pairs of real numbers giving the x and y coordinates of three vertices of the polygon. The numbers are separated by whitespace. The input ends with a n equal 0, this case should not be processed.
输出
For each line of input, output one line in the format shown below, giving the smallest area of a rectangle which can cover all the vertices of the polygon and whose sides are parallel to the x and y axes.
样例输入
4
10.00000 0.00000
0.00000 -10.00000
-10.00000 0.00000
6
22.23086 0.42320
-4.87328 11.92822
1.76914 27.57680
23
156.71567 -13.63236
139.03195 -22.04236
137.96925 -11.70517
0
样例输出
Polygon 1: 400.000
Polygon 2: 1056.172
Polygon 3: 397.673
题意
已知正n边形三点求最小矩形覆盖面积。
题解
正n边形上三点,求出正n边形上唯一外接圆
顺时针绕圆心旋转圆心角得到每个顶点的坐标
然后答案就是(最大的x-最小的x)*(最大的y-最小的y)
代码
1 #include<bits/stdc++.h> 2 using namespace std; 3 4 struct Point 5 { 6 double x,y; 7 Point(double x=0,double y=0):x(x),y(y){} 8 }; 9 Point tcircle(Point pt1,Point pt2,Point pt3,double &radius) 10 { 11 double x1=pt1.x,x2=pt2.x,x3=pt3.x; 12 double y1=pt1.y,y2 =pt2.y,y3=pt3.y; 13 double a=x1-x2,b=y1-y2,c=x1-x3,d=y1-y3; 14 double e=((x1*x1-x2*x2)+(y1*y1-y2*y2))/2.0; 15 double f=((x1*x1-x3*x3)+(y1*y1-y3*y3))/2.0; 16 double det=b*c-a*d; 17 double x0=(b*f-d*e)/det; 18 double y0=(c*e-a*f)/det; 19 radius=hypot(x1-x0,y1-y0); 20 return Point(x0,y0); 21 } 22 Point rotateShun(Point p,Point dx,double selt) 23 { 24 double xx=(p.x-dx.x)*cos(-selt)-(p.y-dx.y)*sin(-selt)+dx.x; 25 double yy=(p.x-dx.x)*sin(-selt)+(p.y-dx.y)*cos(-selt)+dx.y; 26 return Point(xx,yy); 27 } 28 Point p[55]; 29 int main() 30 { 31 int n,ca=1; 32 double PI=acos(-1); 33 while(scanf("%d",&n),n) 34 { 35 for(int i=1;i<=3;i++) 36 scanf("%lf%lf",&p[i].x,&p[i].y); 37 double r=0.; 38 Point cir=tcircle(p[1],p[2],p[3],r); 39 double selt=2.*PI/n; 40 double maxx=p[1].x,minx=p[1].x,maxy=p[1].y,miny=p[1].y; 41 for(int i=2;i<=n;i++) 42 { 43 p[i]=rotateShun(p[i-1],cir,selt); 44 maxx=max(maxx,p[i].x); 45 minx=min(minx,p[i].x); 46 maxy=max(maxy,p[i].y); 47 miny=min(miny,p[i].y); 48 } 49 double ans=(maxx-minx)*(maxy-miny); 50 printf("Polygon %d: %.3f ",ca++,ans); 51 } 52 return 0; 53 }
以上是关于高分求 编程 c语言 已知2点求角度的主要内容,如果未能解决你的问题,请参考以下文章