A question to Raul please: I really liked your simplified approach to plot against X^4 + y^4 <= 1 using:
require ‘viewmat’ viewmat 1>: +&|/~ ((i:300)%200)^4 But I noticed that since this is to the 4th power, why do you invoke +&| ? I see the same result using: viewmat 1>: +/~ ((i:300)%200)^4 Thanks, Rob > On 17 Aug 2022, at 8:37 am, Elijah Stone <elro...@elronnd.net> wrote: > > And the visualisation part (mostly just getting a screenful of normalised > coordinates to apply to): > > ' #' {~ 0 >: sdsquircle"1] 25 50 %"1~ _25 _50 +"1] ($ (#: i.@(*/))) 51 101 > > Ratio of 50 to 100 just accounts for aspect ratio; should be 1:1 if working > with square pixels. > > Also, sdsquircle _does_ seem to actually be a signed distance function, if > you halve it. I don't think this is true in general, but relies on some > specific properties of squares and circles (convexity?). > > On Mon, 15 Aug 2022, Elijah Stone wrote: > >> Was about to go to bed, but this tickled my imagination, so I will say a >> little something. >> >> Rather than calculus, I would do this as an implicit curve. >> >> Start off with the signed distance function of a circle: >> >> sdc=. ]: -~ +/&.:*: >> >> Then that of a box, taken from >> https://iquilezles.org/articles/distfunctions2d/: >> >> sdb=. (+/&.:*:@:(0&>.) + 0 <. >./)@:(]: -~ |) >> >> Both of these are adverbs, taking a radius as an operand and then a vector >> coordinate as an argument. (The latter can also be given a vector, in which >> case it calculates the distance to an n-dimensional rectangle, but that is >> irrelevant here.) >> >> Then, we are looking for the case when the distance to the box is equal to >> the distance to the circle. Such points will be inside the square, but >> outside the circle, so the distance functions of those shapes will have >> opposite sign, and we can just add them together: >> >> sdsquircle=. 1 sdc + 1 sdb >> >> sdsquircle is not, strictly speaking, a signed distance function. However, >> like a signed distance function, it has a value of 0 when applied to a >> coordinate on the squircle; and it is negative inside, and positive outside. >> So it is trivial to render the shape from it. >> >> I can expand further on this tomorrow, but I really must be getting to bed >> now. >> >> -E >> >> On Mon, 15 Aug 2022, Richard Donovan wrote: >> >>> Hi >>> >>> I want to construct and plot a Squircle in J. >>> >>> There is a lengthy article in Wikipedia but in simple language I want my >> Squircle to be defined as the continuous line between a unit circle and the >> unit square that encloses it such that every point on the Squircle is the >> mean of the nearest points of the circle and the square. >>> >>> Thus, the mean is zero at the four points where the circle and the square >> touch, and a maximum of (-: @ <: @ %:2) at the four corners of the square. >>> >>> Each intermediate point between 0 degrees and 90 degrees will be somewhere >> in the middle. >>> >>> I suspect the calculation of the intermediate points is a calculus >> function? >>> >>> Has anyone a good idea for performing that calculation? Could the J >> function “ plot “ then draw the Squircle? >>> >>> Thanks >>> >>> Richard Donovan >>> ---------------------------------------------------------------------- >>> For information about J forums see http://www.jsoftware.com/forums.htm >> ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm >> > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm