Loading

C/C++画一个巨型五角星

利用正弦定理判断一个点是否是否在五角星内,相对于五角星中心的四个象限特判一下来修改角度,把角度都转化成最上面的角,就差不多了,没仔细调整五角星位置,很丑
写完的时候想想才发现其实也有更方便的方法,我们可以通过转角度,把当前点通过不断旋转的方法转到五角星上面的一个角内,这种方法同样适用于N角星

#include <bits/stdc++.h>
using namespace std;
/*    freopen("k.in", "r", stdin);
    freopen("k.out", "w", stdout); */
//clock_t c1 = clock();
//std::cerr << "Time:" << clock() - c1 <<"ms" << std::endl;
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#define de(a) cout << #a << " = " << a << endl
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, a, n) for (int i = n; i >= a; i--)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef vector<int, int> VII;
#define inf 0x3f3f3f3f
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll MAXN = 1e6 + 7;
const ll MAXM = 1e6 + 7;
const ll MOD = 1e9 + 7;
const double eps = 1e-6;
const double pi = acos(-1.0);
int vis[MAXN];
int a[MAXN];
int main()
{
    double Y = 300, X = 100;
    double c = 180.0 / pi;
    for (int i = Y; i >=1; i--)
    {
        for (int j = 2 * Y; j>=1 ; j--)
        {
            double y = i, x = j / 2;
            x -= X;
            y -= X;
            if (y == 0)
                y -= 0.01;
            double p;                       //与中心连线与y轴角度
            double r = sqrt(x * x + y * y); //到中心距离
            if (x > 0 && y > 0)
                p = atan(x / y) * c;
            else if (x >= 0 && y < 0)
                p = 180 + atan(x / y) * c;
            else if (x <= 0 && y >= 0)
                p = -atan(x / y) * c;
            else
                p = 180 - atan(x / y) * c;
            if (p >= 36 && p <= 108)
                p = fabs(p - 72.0);
            else if (p > 108)
                p = fabs(144.0 - p);
            double t = (180 - 18 - p) / 180 * pi;
            if (r / sin(18 * pi / 180) <= X / sin(t))
                putchar('*');
            else
                putchar('.');
        }
        puts("");
    }
    return 0;
}

大概就长这样吧
长这样

posted @ 2019-09-27 19:27  GrayKido  阅读(2451)  评论(0编辑  收藏  举报