
简单c语言编程
已知在平面xy坐标系中L1与X轴夹角为a,L2与L1垂直,且交与d点,点段od为常数R,在平面中有2点b和c,b点的坐标为(x3,y3),c点的坐标为(x4,y4)。b点...
已知在平面xy坐标系中L1与X轴夹角为a,L2与L1垂直,且交与d点,点段od为常数R,在平面中有2点b和c,b点的坐标为(x3,y3),c点的坐标为(x4,y4)。b点在L2上的投影为b’, c点在L2上的投影为c’。
求夹角a和线段c’b’长度的关系。X3=1;Y3=3;Od=5;X4=8Y4=10;
输入a,输出c’b’长度 展开
求夹角a和线段c’b’长度的关系。X3=1;Y3=3;Od=5;X4=8Y4=10;
输入a,输出c’b’长度 展开
4个回答
展开全部
#include <stdio.h>
#include <math.h>
void main()
{
int a;
float x3,y3,x4,y4;
double d,dd,x;
printf("请输入点 b 的坐标:");
scanf("%f%f",&x3,&y3);
printf("请输入点 c 的坐标:");
scanf("%f%f",&x4,&y4);
printf("请输入角a的弧度数:");
scanf("%d",&a);
x=atan((y3-y4)/(x3-x4));
dd=sqrt(pow(x3-x4,2)+pow(y3-y4,2));
printf("b c 两点的距离是:%.2f\n",dd);
d=dd*sin(x-a);
printf("投影的长度是:%.2f\n",d);
}
展开全部
如果要考虑4个象限,考虑各种x3y3x4y4, 比较麻烦。
大致思路,计算b点到线L1的距离,计算c点到线L1的距离,
用ang3,ang4 与 ang 的相对位置判断 l1 和 l2 应当相加还是相减得 总距离。
程序如下(没考虑4个象限):
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
void main()
{
double r1,r2;
double R=5.0, ang=1.05;
double Bx,By,P1x,P1y,P2x,P2y,l1,l2,L;
double x3=1,y3=3,x4=8,y4=10;
double ang3,ang4;
ang3 = atan(y3/x3);
ang4 = atan(y4/x4);
printf("input angle in deg: \n");
scanf("%lf",&ang);
ang = ang / 180.0 * 3.14159265;
Bx = R * cos(ang);
By = R * sin(ang);
r1 =( (x3*Bx)+(y3*By)) / (R*R);
P1x = r1 * Bx;
P1y = r1 * By;
l1 = sqrt( (x3-P1x)*(x3-P1x) + (y3-P1y)*(y3-P1y) );
r2 =( (x4*Bx)+(y4*By)) / (R*R);
P2x = r2 * Bx;
P2y = r2 * By;
l2 = sqrt( (x4-P2x)*(x4-P2x) + (y4-P2y)*(y4-P2y) );
if ( (ang3 >= ang) && (ang4 <= ang) ) L= fabs(l2 + l1);
else L = fabs(l2-l1);
printf("distance: %.2lf ",L);
}
大致思路,计算b点到线L1的距离,计算c点到线L1的距离,
用ang3,ang4 与 ang 的相对位置判断 l1 和 l2 应当相加还是相减得 总距离。
程序如下(没考虑4个象限):
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
void main()
{
double r1,r2;
double R=5.0, ang=1.05;
double Bx,By,P1x,P1y,P2x,P2y,l1,l2,L;
double x3=1,y3=3,x4=8,y4=10;
double ang3,ang4;
ang3 = atan(y3/x3);
ang4 = atan(y4/x4);
printf("input angle in deg: \n");
scanf("%lf",&ang);
ang = ang / 180.0 * 3.14159265;
Bx = R * cos(ang);
By = R * sin(ang);
r1 =( (x3*Bx)+(y3*By)) / (R*R);
P1x = r1 * Bx;
P1y = r1 * By;
l1 = sqrt( (x3-P1x)*(x3-P1x) + (y3-P1y)*(y3-P1y) );
r2 =( (x4*Bx)+(y4*By)) / (R*R);
P2x = r2 * Bx;
P2y = r2 * By;
l2 = sqrt( (x4-P2x)*(x4-P2x) + (y4-P2y)*(y4-P2y) );
if ( (ang3 >= ang) && (ang4 <= ang) ) L= fabs(l2 + l1);
else L = fabs(l2-l1);
printf("distance: %.2lf ",L);
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <stdio.h>
#include <math.h>
#define PI acos(-1.0);
int main()
{
double Lab,L2,a,cosab_L2,len=0,k2;//所求长度==Vab*VL2/|VL2|;向量算VL2=(1,k2),Vab(7,7);
scanf("%lf",&a);
a=a*180/PI;//如果是角度数
k2=-1/tan(a));
Lab=sqrt(2)*7;
L2=sqrt(1+k2*k2);
cosab_L2=(7+7*k2)/L2/Lab;
len=L2*Lab*cosab_L2/L2;
cout<<abs(len)<<endl;
return 0;
}
也许需要特判a==0||a>90等 但是应该也不难 我写了主要思路 剩下的你应该没问题了
#include <math.h>
#define PI acos(-1.0);
int main()
{
double Lab,L2,a,cosab_L2,len=0,k2;//所求长度==Vab*VL2/|VL2|;向量算VL2=(1,k2),Vab(7,7);
scanf("%lf",&a);
a=a*180/PI;//如果是角度数
k2=-1/tan(a));
Lab=sqrt(2)*7;
L2=sqrt(1+k2*k2);
cosab_L2=(7+7*k2)/L2/Lab;
len=L2*Lab*cosab_L2/L2;
cout<<abs(len)<<endl;
return 0;
}
也许需要特判a==0||a>90等 但是应该也不难 我写了主要思路 剩下的你应该没问题了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
先把公式解出来,再根据公式编,这种题意义不大
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询