oscilloscope algorithms (with pictures)

oscilloscope algorithms (with pictures)

Anonymous
Not applicable
711 Views
15 Replies
Message 1 of 16

oscilloscope algorithms (with pictures)

Anonymous
Not applicable
Hi gang,

I've been away for a while, but I'm back maxing and need some help.

I'm trying to mimic an oscilloscope via maxScript but I'm having trouble figuring out the code to make some of the basic shapes. I know that numbers on the attached images refer to the ratio between two sine waves used generate the shape. 1:1 being a unison 2:1 being an octave 4:3 is a 4th and 3:2 is a 5th. (The unlabeled ones are of a tighter interval or possibly of more than two sine waves.) But try as I might, I don't know how to get from the two sin functions to points in 3d space. If anyone knows anything about oscilloscopes, or these sinusoidal shapes in general, any help would be great.

Thanks in advance,

James

0 Likes
712 Views
15 Replies
Replies (15)
Message 2 of 16

Anonymous
Not applicable
And wada ya know. The second I post this, I figure it out. If anyone's interested it looks something like this:


pts = 36 -- the number of points in the spline
rat = 2.0/3.0 -- the ratio of the two frequencies

for n = 0 to pts do (
deg = (360/pts)*n
x = sin deg*rad
y = cos deg*rad
z = sin (deg/rat)*rad
)
0 Likes
Message 3 of 16

stigatle
Enthusiast
Enthusiast
Cool, thanks for sharing the code with us 🙂
0 Likes
Message 4 of 16

Anonymous
Not applicable
Have to say... they look great. I don't know why I didn't come up with this before. I'll post the final result when it's done.
0 Likes
Message 5 of 16

stigatle
Enthusiast
Enthusiast
You can probably drive it by audio also? wave controller?
0 Likes
Message 6 of 16

Steve_Curley
Mentor
Mentor
Lissajous curves

And welcome back btw 🙂

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 7 of 16

Anonymous
Not applicable
Lissajous curves

And welcome back btw 🙂

Sweet. I had no idea what they were called so I couldn't look them up.

And it's good to be back, thanks.
0 Likes
Message 8 of 16

Anonymous
Not applicable
You can probably drive it by audio also? wave controller?

You can use the audio control to affect the ratio, yes, but it won't be 'real'. Max doesn't have the sound processing capabilities to analyze the frequencies on the level needed to get anything like real sound wave data out of a file. But it does work for 'faking it'.
0 Likes
Message 9 of 16

Anonymous
Not applicable
So, here's a little animatic I made for a radiohead video contest. It uses lissajous curves and varies the ratio between the frequencies to the beat. Looks pretty cool if you ask me. I also wrote a script that would project these curves onto any geometry (in this case, a model of the lead singer's head), still keeping the curve's animation. The encoding isn't great because there's so much movement, but I think you get the idea.

You can see the vid here. (and if you like, sign up and vote...)

Thanks, guys.

james
0 Likes
Message 10 of 16

Anonymous
Not applicable
And while I'm here, I might as well update the code a bit. The new element is 'wraps' which allows you to decide how many times to wrap the line around. For non-rational frequencies, the more wraps, the more lines. For rational frequencies, the line will eventually meet up with itself.

fn posOsc rad rat segs wraps = (
-- rad: the radius of the circle
-- rat: the ratio between the two frequencies
-- segs: the number of segments in the spline
-- wraps: the number of times to wrap the spline around the 'cylinder'
for n = 0 to segs do ( -- note: there is one more knot than segments
deg = ((360*wraps)/segs)*n
px = sin deg*rad
py = cos deg*rad
pz = sin (deg/rat)*rad + rad -- shift up by rad so it sits on the ground plane
-- position knot number n to
)
)

0 Likes
Message 11 of 16

joshpurple
Advocate
Advocate
Cool! You got my vote James! 🙂 And Thanks for the code.
0 Likes
Message 12 of 16

Anonymous
Not applicable
I'm going to sound really really ignorant here (probably because I am), but I don't know how to use the code:

pts = 36 -- the number of points in the spline
rat = 2.0/3.0 -- the ratio of the two frequencies

for n = 0 to pts do (
deg = (360/pts)*n
x = sin deg*rad
y = cos deg*rad
z = sin (deg/rat)*rad
)

Do you apply it to an existing spline, embeed an Spline creation to the macro or do something compleatly diferent?
0 Likes
Message 13 of 16

Steve_Curley
Mentor
Mentor
I would guess he's using that algorithm to create a new spline object.

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 14 of 16

Anonymous
Not applicable
You can use it to create a single spline, but if you want to change the ratio over time (which is what I did in the video) you need to create a spline with the desired number of points; set the points to "smooth" if they're not already; apply a spline IK control modifier and click the "create helpers" which will create a helper object for each point and then run the posOsc function, replacing the "-- position knot number n to " with something like, "getNodeByName ("point" + n as string).pos = ". If you do this in an "animate on" context over time, you'll see the spline animating over time.

Does that help? Maybe I'll work up a start to finish example when I have a second...
0 Likes
Message 15 of 16

Anonymous
Not applicable
ok - here goes...

First run this:

segments = 36
fn makeOsc = (

osc = splineShape()
osc.adaptive = true

osc.render_renderable = true
osc.render_displayRenderMesh = true
osc.render_thickness = 1
osc.render_rectangular = false
osc.render_sides = 12

addNewSpline osc
for n = 0 to segments do (
pt =
addKnot osc 1 #smooth #curve pt
)
updateshape osc

spik = spline_ik_control()
addmodifier osc spik
)

This creates a spline with 36 segments with a spline ik modifier. I couldn't get the next step to work via script and don't have time to figure it out (if anyone knows how, please let us know) so just select the spline by hand and click 'create helpers' and make sure the 'link types' is set to 'no linking'.

Now run this:

segments = 36
fn posOsc rad rat segs wraps = (
-- rad: the radius of the circle
-- rat: the ratio between the two frequencies
-- segs: the number of segments in the spline
-- wraps: the number of times to wrap the spline around the 'cylinder'
for n = 0 to segments do (
deg = ((360*wraps)/segs)*n
px = sin deg*rad
py = cos deg*rad
pz = sin (deg/rat)*rad + rad -- shift up by rad so it sits on the ground plane
if n < 9 then nstr = ("0" + (n+1) as string) else nstr = (n+1) as string
(getNodeByName("Point" + nstr)).pos =
)
)

startRat = 1.0
endRat = 0.1
startFrame = 0
endFrame = 100
for t = startFrame to endFrame do
with animate on
at time t
posOsc 100 (startRat+((startRat-endRat)/(endFrame-startFrame))*t) segments 4


You should have the spline animated from frame 0 to 100.

Now you can play with the start and end ratios to see what the shape does. Simple fractions will give you simpler shapes (1:1, 1:2, 2:3, 3:4...) the tighter the numbers, the more lines you get. Also play with the wraps variable. The more wraps, the more complex the line, but the less smooth the curve. If you really want to test your box, start again and set segments to 360 or higher and you can see how complex these shapes can get.
0 Likes
Message 16 of 16

Anonymous
Not applicable
Thank you very much.
0 Likes