/*实现函数y=x*x的图形与圆的图形迭加显示
*/
图形迭加的关键是要在分别计算出同一行中两个图形的列方向点坐标后,正确判断相互的位置关系。
为此,可以先判断图形的交点,再分别控制打印两个不同的图形。
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int x, x_circularity,x_parabola;
double y;
for(y=1;y>=-1;y-=0.1)
{
x_circularity=sqrt(1-pow(y,2))*25; //圆图形上y对应的列坐标
if(y>=0) //y=x*x函数只在y>=0时有图形
x_parabola=sqrt(y)*25; //y=x*x图形上y对应的列坐标
for(x=-25;x<=25;x++)
if((x==x_circularity&&x==x_parabola)||(x==(-1)*x_circularity&&x==(-1)*x_parabola))
cout<<"+"; //两个图形相交时打印'+'
else
if(x==(-1)*x_circularity||x==x_circularity)
cout<<"*"; //圆图形上的点打印'*'
else
if(y>=0&&(x==(-1)*x_parabola||x==x_parabola))
cout<<"+"; //抛物线图形上的点打印'+'
else
cout<<" ";
cout<<endl;
}
return 0;
}