本文目錄一覽:
- 1、c語言作業不會啊
- 2、用c語言判定兩個圓是否相交,
- 3、c語言程序求二維坐標中兩圓的面積及是否相交
- 4、判斷兩圓是否相交 用c 語言
- 5、C語言編程求解
- 6、用C語言編寫“求兩個圓之間的距離,相離,相切或相交”
c語言作業不會啊
沒怎麼按要求,但是差不多完成了前2個任務
/* Note:Your choice is C IDE */
#include “stdio.h”
#include “math.h”
typedef struct
{
int x;
int y;
}
point;
typedef struct
{
float a;
float b;
float c;
}
line;
typedef struct
{
point x;
point y;
point z;
point t;
}
rect;
typedef struct
{
point x;
int radius;
}
cycle;
double testpoint(void)
{
point x1,y1;
double l,temp;
printf(“請輸入第一個點的 x坐標\n”);
scanf(“%d”,x1.x);
printf(“請輸入第一個點的 y坐標\n”);
scanf(“%d”,x1.y);
printf(“請輸入第二個點的 x坐標\n”);
scanf(“%d”,y1.x);
printf(“請輸入第二個點的 y坐標\n”);
scanf(“%d”,y1.y);
temp=(double)(((x1.x)-(y1.x))*((x1.x)-(y1.x))+((x1.y)-(y1.y))*((x1.y)-(y1.y)));
l=sqrt(temp);
return l;
}
double testline(void)
{
point x1;
line g;
double temp1,temp2,d;
printf(“請輸入要求點的 x坐標\n”);
scanf(“%d”,x1.x);
printf(“請輸入要求點的 y坐標\n”);
scanf(“%d”,x1.y);
printf(“請輸入直線一般表達式aX+bY+c=0的三個係數\n”);
printf(“請輸入a\n”);
scanf(“%f”,g.a);
printf(“請輸入b\n”);
scanf(“%f”,g.b);
printf(“請輸入c\n”);
scanf(“%f”,g.c);
temp1=sqrt((g.a)*(g.a)+(g.b)*(g.b));
temp2=g.a*(double)(x1.x)+g.b*(double)(x1.y)+g.c;
if(temp2=0)
temp2=temp2;
else
temp2=-temp2;
d=temp2/temp1;
return d;
}
void main()
{
double l,d;
l=testpoint();
printf(“2點之間的距離是%9.9f\n”,l);
d=testline();
printf(“點到線的距離是%f\n”,d);
}
用c語言判定兩個圓是否相交,
判斷圓心距離和半徑的和 差之間的關係就行了;
bool xiangjiao(int x1,int y1,int r1,int x2,int y2,int r2)
{
doule s;
s = sqrt(double((y2-y1)*(y2-y1)+(x2-x1)*(x2-x1)));
if(int(s)r2+r1int(s)abs(r2-r1))
return true;
else
return false;
}
這是一個方法,寫代碼時候調用該方法就可以了。
c語言程序求二維坐標中兩圓的面積及是否相交
經典題。網上答案很多,給你抄一個:
假設半徑小的圓為c1,半徑大的圓為c2。
c1的半徑r1,圓心坐標(x1,y1)。c2的半徑r2,圓心坐標(x2,y2)。
d為兩圓圓心連線的長度。
相交面積為S
d=sqrt((x1-x2)^2+(y1-y2)^2)
(1)如果r1+r2=d
那麼兩圓相離,相交面積S=0
(2)如果r2-r1=d
那麼半徑小的圓內含半徑大的圓,那麼相交面積為小圓的面積S=pi*r1*r1
(3)既非(1)也非(2)
在圖上畫兩個相交圓,結合圖像看。
那麼兩圓相交,連接小圓的圓心與兩個圓的交點,連接大圓的圓心和兩個圓的交點。
可以發現形成的圖形被兩個圓心的連線平分成2個全等三角形。
由小圓圓心和交點所連兩條線(長度為半徑)以及在大圓之內的弧所形成的扇形為S1
由大圓圓心和交點所連兩條線(長度為半徑)以及在小圓之內的弧所形成的扇形為S2
由小圓圓心和交點所連兩條線以及由大圓圓心和交點所連兩條線所形成的四邊形的面積為S3
可見相交面積S=S1+S2-S3
要求出扇形的面積,要知道扇形的圓心角。
小圓包含的扇形的圓心角為2*a1(考慮一個三角形)
a1=acos((r1^2+d^2-r2^2)/(2.0*r1*d)) 餘弦定理
a2=acos((r2^2+d^2-r1^2)/(2.0*r2*d))
S1=pi*r1*r1*2*a1/(2*pi)=a1*r1*r1
同理
S2=a2*r2*r2
S3為一個三角形面積的2倍
S3=2*r1*d*sin(a1)/2=r1*d*sin(a1)
則S=a1*r1*r1+a2*r2*r2-r1*d*sin(a1)
代碼:
#define pi acos(-1.0)
#define maxn 10
struct node{
double x;
double y;
double r;
} c[maxn];
double area(int i,double r1,int j,double r2){
double d=
sqrt((c[i].x-c[j].x)*(c[i].x-c[j].x)+(c[i].y- c[j].y)*(c[i].y-c[j].y));//圓心距
if(r1r2){
double temp=r1;
r1=r2;
r2=temp;
}//r1取小
if(r1+r2=d)
return 0;//相離
else if(r2-r1=d)
return pi*r1*r1;//內含
else {
double a1=acos((r1*r1+d*d-r2*r2)/(2.0*r1*d));
double a2=acos((r2*r2+d*d-r1*r1)/(2.0*r2*d));
return (a1*r1*r1+a2*r2*r2-r1*d*sin(a1));
}//相交
}
=======
如果只有2個圓,前面可用:
#define maxn 2
main()
{
輸入或賦值 c[0].x, c[0].y,c[0].r, c[1].x, c[1].y,c[1].r,
調用 參數:i=0;r1=c[0].r; j=1;r2=c[1].r;
調用:
printf(“Area=%lf”, area(0,c[0].r,1,c[1].r) );
}
判斷兩圓是否相交 用c 語言
#include stdio.h
#include math.h
int main(void)
{
float x1, y1, x2, y2, r1, r2;
scanf(“%f %f %f”, x1, y1, r1);
scanf(“%f %f %f”, x2, y2, r2);
float len = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
if (len (r1+r2))
{
printf(“yes\n”);
}
else
printf(“no\n”);
return 0;
}
C語言編程求解
homework16.h裡面的內容:
struct Pointxy /*點*/
{
int x;
int y;
}
typedef struct Pointxy Point;
struct Cirlexy /*圓*/
{
Point center;
int r;
}
typedef struct Cirlexy Circle;
struct Rectanglexy /*長方形結構*/
{
Point leftp;
int a;
int b;
}
typedef struct Rectanglexy Rect;
struct LineAb /* y=k*x+b */
{
float k;
float b;
}
typedef stuct LineAb line;
homework16.c裡面的內容:還需要完善,先佔位,再完善了發過來
#include”homework16.h”
#include”math.h”
float PointToPoint(Point a,Point b) /*點到點的距離*/
{
return(sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
float PointToLine(Point a,Line l) /*點到直線的距離*/
{
}
int PointInCircle(Point a,Circle c) /*點是否在圓內*/
{
float dis=0;
dis=PointToPoint(Point a,c.center);
if(disc.r)
return 0;
else
return 1;
}
int PointInRect(Point a,Rect r) /*點是否在Rect內*/
{
}
int CircleInCircle(Circle a,Circle b) /*圓是否相交*/
{
float dis;
dis=PointToPoint(a.center,b.center);
if(disa.r+b.r)
return 0;
else
return 1;
}
用C語言編寫“求兩個圓之間的距離,相離,相切或相交”
#include stdio.h
#include math.h
int main()
{ double x1,x2,y1,y2,r1,r2,d;
printf(“請輸入圓1的圓心坐標和半徑:”);
scanf(“%lf%lf%lf”,x1,y1,r1);
printf(“請輸入圓2的圓心坐標和半徑:”);
scanf(“%lf%lf%lf”,x2,y2,r2);
d=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
if(dr1+r2)printf(“兩圓相離\n”);
else if(dr1+r2)printf(“兩圓相交\n”);
else printf(“兩圓相切\n”);
return 0;
}
原創文章,作者:EPQI,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/144343.html