Archive: hey guys!


14th October 2009 01:51 UTC

hey guys!
long time no postie! XD

hey I just wanted to try out something that I'm learning in school (heh, collage!)

obviously in AVS we're limited to a -1 <-> 1 in both x & y fields, but I want to try and make lines that would normally be graphed greater than 1 and get the same result.

I've tweaked out the math (like decreasing x & y by a multiple) with no result.

so, at least my example that I would like to work with is a line using f(x) = x / ( x^2 - x - 2)

which solving for x, you swap "f(x)" as "y", and use "x" (in our case) should be the "i" (drawing the line)

the result should split the line twice with two vertical asymptotes with those being at x= -1 & 2

can anyone translate this into an avs field (between -1 <-> 1)?


14th October 2009 19:21 UTC

Should just be a simple case of scaling i as needed.

Try something like:
Init
n = w;

Frame //This is just code for aspect ratio correct
asph = if(above(w, h), h / w, 1);
aspv = if(above(h, w), w / h, 1);

Point
k = (i * 10) - 5;
x = (k / 5) * asph;
y = (k / (pow(k, 2) - k - 2)) / aspv;



That should do roughly what you're looking for.


15th October 2009 01:52 UTC

Aw! thanks!

man, you have no idea how nice that looks.

so basically if i wanted to edit all of that for different lines, i could only need to replace the code, but keep the 'k' where it is, and substitute (in x & y) for 'k'?

or just keep the function for k and x, but only change the 'y', and instead of said 'x' use 'k'? (then of course divide 'y' by 'k'


15th October 2009 11:46 UTC

K is the position along the line, and X is the scaled position along the line. (So it fits between -1 and 1)
So as long as you're just effecting Y you only need to edit the Y code, with K replacing X.
To change what it's calculated between just change the equation for K and tweak what K is divided by for X, so it's zoomed correctly.

Does that make sense?

This does not scale the height of Y though. And the Y axis is the wrong way around I think too.
To be honest it's not too complex to figure out anyway, it's not really anything AVS specific and where it is you can just turn to the Expression Help.


Oh whoops the '/ aspv' should be '* aspv' btw. (I should actually test stuff before just writing stuff)

(Someone shout at me if I'm wrong!)


15th October 2009 14:41 UTC

You're correct (tested it).
if framerate were important, I would use sqr(k) instead of pow(k,2).