基于C语言的圆曲线方程的示例代码 [英] Example code for equation of circle curve in C based language

查看:208
本文介绍了基于C语言的圆曲线方程的示例代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,感谢您阅读我的问题。我非常感谢您的关注。



我正在尝试绘制基于文本的圆圈而不绘制头文件或外部类。

但仅包括math.h或任何等效的标题/类,如pi值或余弦/正弦函数。



我的目标是制作一个基于文本的圈子,如下一个。



0000000000000000000000001

0000000000000000000001000

0000000000000000001000000

0000000000000010000000000

0000000000100000000000000

0000000010000000000000000

0000001000000000000000000

0000100000000000000000000

0100000000000000000000000

1000000000000000000000000



我需要一个基于C语言编程语言的圆曲线方程代码。

我尝试过使用**y = Cos(pi * x)制作曲线**但不幸的是它不是平面圆曲线。



因此我想要知道圆圈c在基于C语言的编程语言中使用方程式示例代码。



谢谢!

Hello, Thank you for read my question. I'm appreciated with your concern.

I'm trying to drawing a text based circle without drawing header file or external class.
but include only "math.h" or any equivalent header/class like has "pi" value or "cosine/sine" function stuffs.

My goal is make a text based circle like next.

0000000000000000000000001
0000000000000000000001000
0000000000000000001000000
0000000000000010000000000
0000000000100000000000000
0000000010000000000000000
0000001000000000000000000
0000100000000000000000000
0100000000000000000000000
1000000000000000000000000

I need a circle curve equation code for C based programming language.
I tried to make a curve with using **"y=Cos(pi*x)"** but unfortunately it's not a plane circle curve.

Hence I'd like to know the circle curve equation example code in C based programming language.

Thank you!

推荐答案

尝试玩: X * X + Y * Y = const

这是简单的圆方程;当然对于任何0< X< sqrt(const)你将有2个Y解决方案,正面和负面,这就是你想要的
try playing with : X*X + Y*Y = const
which is the simple circle equation; naturally for any 0 < X < sqrt(const) you'll have 2 Y solutions, positive and negative, which is what you want


你可能意味着一个参数化的圆形方程:让变量t从0到2运行* PI以小增量计算:

What you probably mean is a parameterized circle equation: Let variable t run from 0 to 2*PI in small increments and then calculate:
double x, y;
x = cos (t) * r;
y = sin (t) * r;



这将为您提供一组围绕原点围绕半径为r的圆形协调。



如果要按照问题中显示的方式打印圆圈,请考虑每个打印字符占用的空间在x和y方向上是不同的。因此,您必须通过在x或y计算中应用校正因子来对此进行补偿。否则圆圈将在图表上显示为椭圆。


This will give you a set of coordinated for a circle around the origin with radius r.

If you want to print the circle in the way you showed in your question then consider that the space taken up by each print character is different in x and y direction. Hence you have to compensate this by applying a correction factor in the x or y calculation. Otherwise the circle will appear as an ellipse on your chart.


如果我理解你,你需要创建二维数组的字符(填充 0 - 零),然后用其他字符替换一些字符( 1 - 一个)来模仿一个圆...数组的大小应该根据 r (半径)。



看看这里:http://cboard.cprogramming.com/c-programming/101213-drawing-circle-ascii-character.html [ ^ ] ,在这里: http://en.wikipedia.org/wiki/Midpoint_circle_algorithm [ ^ ]和这里:http://code-heaven.blogspot.com/2009/05/c-program-for-bresenham-circle -drawing.html [ ^ ]



简单替换 SetPixel / DrawPixel 使用您自己的函数来替换字符的2D数组中的char;)
If i understand you well, you need to create 2 dimension array of chars (filled with 0 - zero), then to replace some chars with other (1 - one) to imitate a circle... The size of array should be calculated based on r (radius).

Have a look here: http://cboard.cprogramming.com/c-programming/101213-drawing-circle-ascii-character.html[^], here: http://en.wikipedia.org/wiki/Midpoint_circle_algorithm[^] and here: http://code-heaven.blogspot.com/2009/05/c-program-for-bresenham-circle-drawing.html[^]

Simple replace SetPixel/DrawPixel function with your own to replace char in a 2D-array of chars ;)


这篇关于基于C语言的圆曲线方程的示例代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆