❔ ✅ Applying math to programming
Hi,
this is not necessarily a C# question and more question towards math and programming. I am using C# as my language so I hope it's okay to ask this here.
I have always been struggling with applying math equations and so on to programming and I am finally tackling this mental block I have and trying to force myself to learn more.
I have a 2 dimensional array (grid) of 0 or 1 (which size is set dynamically)
I would like to use
x^4 + y^4 = 1
to fill it out.
https://www.wolframalpha.com/input?i=x%5E4+%2B+y%5E4+%3D+1
How can I draw this shape in it?
I would also like to go beyond and how could I fill it out or reverse fill it out in my grid?
Just a small pointer on how to use math to achieve some different result would help help so much.
Thank you.
Example (With bigger size edges would be smoother):
8 Replies
i hope i understood the question correctly and will give it a try
so thats a 10x10 grid
asuming the zeropoint is exactly in the middle and goes from -1 to 1 it would mean every point is 0.2 away from the next
so now loop from -1 to 1 in 0.2 increments and set x to that value, then solve for y
set the closest to index to true...
that would be a very naive approach
Thank you very much, helped a bit to understand how to approach something like this 🙂
You have someArray[,]
Not being a math person, I don't know how SolveFunction is supposed to work. But the thing I'm trying to point out is that your array already has x and y, and just subtracting half of the size gets the center to 0 (or near it) for graphing purposes
Judging by your example, SolveFunction is probably just something like
And so you'll have to make sure the array is an appropriate size to be able to have that ever be true, or apply some scaling factor to it
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.
Was this issue resolved? If so, run /close
- otherwise I will mark this as stale and this post will be archived until there is new activity.The previous suggestions seem to assume that the function will be exactly equal at some "pixels"; that will almost never be the case for any nontrivial formula.
You may instead want to calculate a bunch of (x, y) points that lie exactly on the curve, for your example function perhaps converting the function to its polar form then iterating through theta would be a good start.
Then for each point, you could round to the nearest "pixel coordinate" to set that cell's value.
@patrickk is this a bug in Accord?
Other than the title not removing the solved checkmark no
It was closed, then reopened because of a message and then never closed
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.