趣味图形之 二次函数与圆相交

先看看它像什么????!

好吧(∩_∩),它像,,,,很多,发挥自己的创意去组合吧

1.

/***二次函数与圆最完美图像***/
#include <stdio.h>
#include <math.h>

int main (void)
{
    int m, n, x;
    double y;
    for ( y = 20; y >= -10; y-- )
    {
        if ( y > 10 )
        {
            m = 1.8 * sqrt(y);
            for ( x = 1; x <= 40; x++ )
            {
                if ( x == 20 - m || x == 20 + m )
                    printf ( "*" );
                else
                    printf (" ");
            }
        }
        else if ( y >= 0 && y <= 10 )
        {
            m = 1.8 * sqrt ( y );
            n = 1.8 * sqrt ( 100 - y * y );
            for ( x = 1; x <= 40; x++ )
            {
                if ( x == 20 - m && x == 20 - n || x == 20 + m && x == 20 + n )
                    printf ("+");
                else if ( x == 20 - m || x == 20 - n || x == 20 + m || x == 20 + n )
                    printf ("*");
                else
                    printf (" ");
            }
        }
        else
        {
            n = 1.8 * sqrt ( 100 - y * y );
            for ( x = 1; x <= 40; x++ )
            {
                if ( x == 20 - n || x == 20 + n )
                    printf ("*");
                else
                    printf (" ");
            }
        }
        printf ("\n");
    }
    return 0;
}

2.

/***二次函数与圆的叠加显示2***/
# include <stdio.h>
# include <math.h>
int main (void)
{
    int x, m, n;
    double y;
    for (y = 10; y >= 0; y--)
    {
        m = 1.8 * sqrt( y );
        n = 1.8 * sqrt( 100 - y * y );
        for ( x = 1; x <= 40; x++ )
        {
            if ( (x == 20 - m) && (x == 20 - n) || (x == 20 + m) && (x == 20 + n) )
                printf ("+");
            else if ( (x == 20 - m) || (x == 20 - n) || (x == 20 + m) || (x == 20 + n) )
                printf ("*");
            else
                printf (" ");
        }
        printf ("\n");
    }
    for ( y = 0; y >= -10; y-- )
    {
        n = 1.8 * sqrt( 100 - y * y );
        for ( x = 1; x <= 40; x++ )
        {
            if ( x == 20 - n || x == 20 + n )
                printf ("*");
            else
                printf (" ");
        }
        printf ( "\n" );
    }
    return 0;
}

运行之后(和第一个不同,要注意的是,屏幕的长宽比不一样)

3.

/***二次函数与圆的叠加显示3***/
# include <stdio.h>
# include <math.h>
int main (void)
{
    int m, n;
    double y;
    for ( y = 10; y >= -10; y-- )
    {
        m = 1.8 * sqrt ( abs(y) );
        n = 1.8 * sqrt ( 100 - y * y );
        for ( int x = 0; x <= 40; x++ )
        {
            if ( (x == 20 - m) && (x == 20 - n) || ( x == 20 + m ) && ( x == 20 + n ) )
                printf ( "+" );
            else if ( (x == 20 - m) || (x == 20 - n) || ( x == 20 + m ) || ( x == 20 + n ) )
                printf ( "*" );
            else
                printf ( " " );
        }
        printf ( "\n" );
    }
    return 0;
}

运行之后

图片超神般存在

时间: 2024-08-30 12:52:23

趣味图形之 二次函数与圆相交的相关文章

趣味图形之 正弦函数sin&&余弦函数cos相交

高中的时候做的,前两天看了看,挺好玩的. 只想说,当初的代码风格,,,,咳咳,算不上风骚! /***sin(x)和cos(x)图像同时显示***/ # include < stdio.h > # include < math.h > int main ( void ) { double y; int x, m, n; for ( y = 1; y >= -1; y -= 0.1 ) { m = acos( y ) * 10; n = asin( y ) * 10; for (

POJ 2546 Circular Area(两个圆相交的面积)

题目链接 题意 : 给你两个圆的半径和圆心,让你求两个圆相交的面积大小. 思路 : 分三种情况讨论 假设半径小的圆为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)

POJ 2546 &amp; ZOJ 1597 Circular Area(求两圆相交的面积 模板)

题目链接: POJ:http://poj.org/problem?id=2546 ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=597 Description Your task is to write a program, which, given two circles, calculates the area of their intersection with the accuracy of three di

hdu 3264 Open-air shopping malls 求两圆相交

对每个圆二分半径寻找可行的最小半径,然后取最小的一个半径. 对于两圆相交就只要求到两个扇形,然后减去两个全等三角形就行了. #include<cstdio> #include<iostream> #include<cmath> #include<algorithm> using namespace std; #define pi acos(-1.0) #define eps 1e-8 #define maxn 50 int n; struct point{

HDU 3467 (求五个圆相交面积) Song of the Siren

还没开始写题解我就已经内牛满面了,从晚饭搞到现在,WA得我都快哭了呢 题意: 在DotA中,你现在1V5,但是你的英雄有一个半径为r的眩晕技能,已知敌方五个英雄的坐标,问能否将该技能投放到一个合适的位置,使得对面所有敌人都被眩晕,这样你就有机会能够逃脱. 分析: 对于敌方一个英雄来说,如果技能的投放位置距离他不超过r则满足要求,那么如果要眩晕所有的敌人,可行区域就是以五人为中心的半径为r的圆的相交区域. 现在问题就转化为求五个半径相同的圆的相交部分的面积,如果只有一个点则输出该点. 在求交之前,

HDU 4063 线段与圆相交+最短路

Aircraft Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 980    Accepted Submission(s): 228 Problem Description You are playing a flying game. In the game, player controls an aircraft in a 2D-

hdu 3264 Open-air shopping malls(求圆相交的面积,二分)

Open-air shopping malls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2256    Accepted Submission(s): 837 Problem Description The city of M is a famous shopping city and its open-air shopping

UVALive 4428 Solar Eclipse --计算几何,圆相交

题意:平面上有一些半径为R的圆,现在要在满足不与现有圆相交的条件下放入一个圆,求这个圆能放的位置的圆心到原点的最短距离. 解法:我们将半径扩大一倍,R = 2*R,那么在每个圆上或圆外的位置都可以放圆心了. 首先特判放到原点可不可以,如果不可以,再将所有圆的圆心与原点的直线与该圆相交的点放入队列,再将所有圆两两相交的点放入队列,然后处理整个队列,一一判断这些点行不行,可以证明,最优点一定在这些里面. 如果有一个圆的圆心在(0,0)点,那么要特判一下,因为此时圆心与原点连的直线长度为0,对于这种情

HDU 1798 两圆相交面积

Tell me the area Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1755    Accepted Submission(s): 535 Problem Description There are two circles in the plane (shown in the below picture), there is