LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Circle square; How draw/compute w square pixels? Trigonometry, language (https://www.linuxquestions.org/questions/programming-9/circle-square%3B-how-draw-compute-w-square-pixels-trigonometry-language-4175578487/)

rico001 04-27-2016 01:31 PM

Circle square; How draw/compute w square pixels? Trigonometry, language
 
Greetings;

I have been out of high school and college for awhile. I struggled through math alot. I was wondering how a circle is drawn on the computer, and how a square is? I can't find the trigonomic equation for a square.

Was trying to look into programming languages to draw graphics on the screen. The Wolfram programming language looks intuitive. Also studying video and optics.

?Squaring the Circle :-)
Thanks.

Michael Uplawski 04-27-2016 01:41 PM

Good evening.

I regret to have mentioned this too often already, but I am not a native English speaker. Now, in your post, I read the words and understand what they say, but I still do not get what you are after...

Quote:

Originally Posted by rico001 (Post 5537434)
I have been out of high school and college for awhile. I struggled through math alot. I was wondering how a circle is drawn on the computer, and how a square is? I can't find the trigonomic equation for a square.

PSE correct my understanding, where I am erring: Do you wish to program a routine that draws geometric forms on screen? Just like that or what would you hope to draw them on?
Alternatively, is it just the math that is missing and you are already happy with your chosen programming language and -environment?
Or.., are you wondering about how others do it?

Lastly, what kind of advantage would a “trigonometric equation“ for a square bring you, what would it facilitate? Maybe it is the wrong kind of question and just obstructs your way to drawing a plain ol' square.

suicidaleggroll 04-27-2016 01:55 PM

It will depend on the graphics library you're using. Most high level plotting libraries allow you to pass an array of X and Y coordinates, and the library will "connect the dots" so-to-speak. In that case, for a square you would simply pass it the coordinates of the corners, and in the process of connecting the dots, the library will draw your square for you. For a circle you would generate an array of angles from 0 to 2*pi, then your X and Y coordinates would be the cos() and sin() of those angles. The higher the resolution of your angles, the more "circular" your circle will be. Four points will draw a square, 8 will draw an octagon, and so on until it looks more and more round.

rico001 04-27-2016 02:10 PM

Quote:

Originally Posted by Michael Uplawski (Post 5537442)
Good evening.

...


PSE correct my understanding, where I am erring: Do you wish to program a routine that draws geometric forms on screen? Just like that or what would you hope to draw them on?
Alternatively, is it just the math that is missing and you are already happy with your chosen programming language and -environment?
Or.., are you wondering about how others do it?

Lastly, what kind of advantage would a “trigonometric equation“ for a square bring you, what would it facilitate? Maybe it is the wrong kind of question and just obstructs your way to drawing a plain ol' square.

you understood me well. suicidaleggroll, explained the square ok, but I do not understand the circle yet.

rico001 04-27-2016 02:22 PM

Quote:

Originally Posted by suicidaleggroll (Post 5537449)
It will depend on the graphics library you're using. Most high level plotting libraries allow you to pass an array of X and Y coordinates, and the library will "connect the dots" so-to-speak. In that case, for a square you would simply pass it the coordinates of the corners, and in the process of connecting the dots, the library will draw your square for you. For a circle you would generate an array of angles from 0 to 2*pi, then your X and Y coordinates would be the cos() and sin() of those angles. The higher the resolution of your angles, the more "circular" your circle will be. Four points will draw a square, 8 will draw an octagon, and so on until it looks more and more round.

The square makes sense and helps my learning, thanks. (from computer science I-II) 4 arrays, 2 for x and y, I get it, and I could say a hexidecimal rgb value for color. I don't like pi, (c/d) a example of some things I am looking at for fun... wxchaos on sourceforge I was also looking at puzzles such as: what's the smallest circle you could make. (64x64 pixels and still looks ok?) Thanks so far everyone, still confused about circles /'array of angles',I don't speak math, bad for me.

ntubski 04-27-2016 02:41 PM

You can also use the (non-trigonomic?) circle equation: x^2 + y^2 = r^2, rearrange as a function of y = ±√(r^2 - x^2), no pi needed.

rico001 04-27-2016 04:48 PM

Quote:

Originally Posted by ntubski (Post 5537469)
You can also use the (non-trigonomic?) circle equation: x^2 + y^2 = r^2, rearrange as a function of y = ±√(r^2 - x^2), no pi needed.

Thanks that explains and ends my confusion... When I typed in search trying to get the equation of circle, sites kept giving me square roots that I didn't want so that explains that. A site also mentioned Parametric Equation of a Circle is used to help with algorithms.

This answers many of my questions. Fractal Formula: z = tan(z) made a nice one. Will continue to research... Still have questions not directly related to topic, will mark as solved. Thanks everyone!


All times are GMT -5. The time now is 09:35 AM.