天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 50|回复: 0

c语言直线和椭圆的交点,直线与椭圆相交求交点

[复制链接]
  • TA的每日心情
    开心
    2024-8-31 15:58
  • 签到天数: 89 天

    [LV.6]常住居民II

    488

    主题

    207

    回帖

    3366

    积分

    管理员

    积分
    3366
    发表于 2024-6-22 09:46:18 | 显示全部楼层 |阅读模式
    c语言直线和椭圆的交点,直线与椭圆相交求交点

    #include

    #include

    #include

    void main()

    {

    double a,b,c,x1,x2,y1,y2,k,j;

    printf("\nplease input a,b:\n");

    scanf("%lf%lf",&a,&b);

    printf("\nplease input x1,y1,x2,y2\n");

    scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);

    k=(y1-y2)/(x1-x2);

    c=y1-k*x1;

    j=(2*a*a*k*c)*(2*a*a*k*c)-4*(b*b+a*a*k*k)*a*a*(c*c-b*b);

    if(j<0)

    printf("\nthe line don't intersect with the ellipse");

    else

    if(j==0)

    {

    x1=-2*k*c*a*a/(2*(b*b+a*a*k*k));

    y1=k*x1+c;

    printf("\nthe line and ellipse intersect at\n(%lf,%lf)",x1,y1);

    }

    else

    {

    x1=(-2*k*c*a*a+sqrt(j))/(2*(b*b+a*a*k*k));

    y1=k*x1+c;

    x2=(-2*k*c*a*a-sqrt(j))/(2*(b*b+a*a*k*k));

    y2=k*x2+c;

    printf("\nthe line and ellipse intersect at\n(%lf,%lf) and (%lf,%lf)",x1,y1,x2,y2);

    }

    getch();

    }

     

     

     

     

    c语言直线和椭圆的交点,直线与椭圆相交求交点
    中国膜结构网打造全中国最好的膜结构综合平台 ,统一协调膜结构设计,膜结构施工,膜材采购,膜材定制,膜结构预算全方位服务。 中国空间膜结构协会合作单位。
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|Archiver|手机版|中国膜结构网|中国膜结构协会|进口膜材|国产膜材|ETFE|PVDF|PTFE|设计|施工|安装|车棚|看台|污水池| |网站地图

    GMT+8, 2024-9-8 09:16 , Processed in 0.064742 second(s), 26 queries .

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

    快速回复 返回顶部 返回列表