[SOLVED] Circle square; How draw/compute w square pixels? Trigonometry, language
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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
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.
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.
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.
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.
Last edited by rico001; 04-27-2016 at 02:28 PM.
Reason: clarification,detail
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!
Last edited by rico001; 04-27-2016 at 04:59 PM.
Reason: grammer error, salutations, rules -english format
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.