3D math shapes

offonoll's picture

Hi! Today I ve download Kineme3D pack and I am very happy to improve my designs. I am wondering if its possible to create a shape from a equation formula like on these site: http://local.wasp.uwa.edu.au/~pbourke/geometry/ I couldn't do it with 'Kineme 3D Parametric Surface'

Thank you!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

cwright's picture
Re: 3D math shapes

some yes, some no. It depends on the equations. If they're parametric (x, y, z in terms of u, v), they can be created with this patch, given appropriate equations.

I'm guessing that you're not scaling u and v to the proper range -- in many of his equations u and v go from 0 to 2π, or -π to +π (radians), or whatever, while u and v in kineme3d only go from 0 to 1, and the sin/cos functions expect values in degrees, so you have to do silly stuff like ((u*360)-180) to map it from 0-1 to -180-+180 (which is -π-+π radians).

Here's a klein bottle example. (don't try simplify on it, it might freak out due to some simplify bugs in the 1.2 beta).

PreviewAttachmentSize
klein bottle.qtz4.16 KB

offonoll's picture
Re: 3D math shapes

Sorry for the late replay... I will try to work with other shapes once I have more time. Still having many things to learn... Cheers!

jersmi's picture
Re: kineme 3D parametric surface

In the X expression for the Klein bottle example, say i want to turn the constant 1.5 into a variable i can interpolate:

cos((u * 360-180)) * ( -->1.5 + sin((v * 360-180)) * cos((u * 360-180)/2) - sin(2 * (v * 360-180)) * sin((u * 360-180)/2)/2)

i.e., inserting an input splitter reveals the equation as a string, so i guess my question is, how do i insert a number variable into the string?

cwright's picture
Re: kineme 3D parametric surface

You can replace the 1.5 with a variable (such as the letter r, or "bob", or "awesome" or whatever).

Then, you have to make a structure with a member called you variable name, set it's value to the value you want, and feed that into the Variables input.

jersmi's picture
Re: kineme 3D parametric surface

thanks so much!

rinboku's picture
Re: 3D math shapes

For writing equations I am using JavaScript patch.

PreviewAttachmentSize
klein bottle+var.qtz6.72 KB

leegrosbauer's picture
Re: 3D math shapes

Thanks so very much! Delightful!

jersmi's picture
Re: 3D math shapes

Thanks for that!

javascript question: why do the variables have to have + symbols around them, ie, "+a+" and "+b+"?

(and i'm at >3 fps for the posted example-- that sucks! any solutions?)

cwright's picture
Re: 3D math shapes + vars

For up the framerate, drop the u/v subdivisions (u is 96, v is 64 -- try 32 for both, or even 24)

You can also set Normals to Faceted to save on normal smoothing (it won't look as nice, but it'll be a bit faster).

the vars have '+'s because he's building strings. Here's the code:

result.Xexpression = "cos((u*360-180)) * ("+a+" + sin((v*360-180)) * cos((u*360-180)/2) - sin(2*(v*360-180)) * sin((u*360-180)/2)/2)";

He's got "a" in +'s because he's "adding" "a" to the string (string concatenation).

For example (simpler than the above, which is really long), if we had the line result.something = "aVar: " + 42, it would set result.something to the string "aVar: 42". Similarly, if it was result.something = "aVar: " + x, it would set it to "aVar: ..." where "..." is the whatever "x" is.

jersmi's picture
Re: 3D math shapes + vars

very much appreciated, thanks.

(and by the way, of course i meant "<3 fps"-- slow! halving the U/V subdivisions bumped me up to ~20fps-- good!)

gtoledo3's picture
Re: 3D math shapes + vars

You were at less that 3fps using Rinboku's example? That IS really slow. None of my business, but what are you using (graphics card)? I'm just surprised I guess. I use a frickin white macbook with a GMA X3100 (which isn't exactly the top of the line). On this laptop, it hovers between 20~30fps.

jersmi's picture
Re: 3D math shapes + vars

A slightly older MBP (2.16 core duo) with a stock ATI Radeon X1600. I guess that's the difference with the GMA cards? I really don't know, but i thought it was strangely slow, too. didn't seem like there was that much going on with that patch... but chris's suggestion worked out. i also don't get 32-bit processing, even though the specs say i should...

offonoll's picture
Re: 3D math shapes

Excellent!! I love your JS patch. Looks more clean in order to work. I still don't get some maths conversion. I am tring to make this one: http://local.wasp.uwa.edu.au/~pbourke/geometry/horn/ x = (2 + u cos(v)) sin(2 pi u) y = (2 + u cos(v)) cos(2 pi u) + 2 u z = u sin(v) 0 <= u <= 1, 0 <= v <= 2pi

this is java code :

//result.Xexpression = "("+a+" + 2 + (u * cos(v * 2 * 3.1415))) * sin(2 * 3.1415 * u)";

//result.Yexpression = "("+b+" +2 + (u * cos(v * 2 * 3.1415))) * cos(2 * 3.1415 * u) + 2 * u";

//result.Zexpression = " u * sin(v * 2 * 3.1415)";

also. A: How to include a PI funtion instead 3.1415?

B: Is possible to add a viariable V = (0 <= v <= 2pi) so cos(V)?

Thank's!

cwright's picture
Re: 3D math shapes + vars

Stop Everything.

Hold Option, open QC preferences.

Select the (Editor) tab.

Make sure the following are Disabled:

  • MultithreadedOpenGL
  • SoftwareCoreImage
  • SoftwareOpenGL

Those all give bad performance in QC -- the last two will actually use the CPU to do all rendering.

I'm on a GMA950 -- the generation before George's MacBook, and I get ~20fps too, so if you're not hitting that there's something terribly wrong.

cwright's picture
Re: 3D math shapes

offonoll wrote:
B: Is possible to add a variable V...

Not in the expressions

offonoll wrote:
A: How to include a PI function instead of 3.1415

Math.PI in Javascript will expand to 3.1415926..., but in the Expression stuff, you can just use the variable "pi" (set automagically, along with "e")

rinboku's picture
Re: 3D math shapes

Thank you.

In this case pi = 180 degree.

PreviewAttachmentSize
horn.qtz6.56 KB

gtoledo3's picture
Re: 3D math shapes

Cool posts Rinboku :o)

jersmi's picture
Re: 3D math shapes + vars

Thanks, Chris. All are disabled. Here's a screenshot of performance inspector.

PreviewAttachmentSize
param_surface_low_fps.png
param_surface_low_fps.png51.6 KB

gtoledo3's picture
Re: 3D math shapes + vars

zoinks...

This is a real stab in the dark... Chris, would it make any difference if someone isn't running the most recent build of QC?

cwright's picture
Re: 3D math shapes + vars

That's expected -- with a fast GPU (non-intel), the rendering of 96*64 (6144) polygons will take next to no time -- the only thing doing any work would be the surface generator (since it's making a new mesh _every frame_).

Even on a crap GPU (GMA95), here's what it looks like:

Rendering takes ~25% of the time, generation takes ~75%.

But it's taking almost half a second in your case, while it's taking much less on mine (~1/30th second). -- This is entirely CPU-bound stuff, so OpenGL/GPU won't affect this at all.

Possible reasons for this disparity:

  • Your machine is running Lots of stuff (this is not too likely -- I was running 2 protein folding simulations in the background at the time of my screenshot, so my both my cores were already maxed out and hot).
  • You have an older build of Kineme3D -- I'm running the latest 1.2 beta (not released even on kineme.net yet), which has had some performance improvements -- however, that's pretty dramatic.
    • Oh Yeah: Smooth Normals is Really Slow in some builds of Kineme3d -- make sure you're running the latest kineme3d 1.2 beta, and see if disabling smoothing helps -- if so, that's fixed in the next beta.
  • You've modified the composition (i.e. by enabling simplification, which is buggy and expensive)

I think that covers all our bases.

PreviewAttachmentSize
SurfacePI.png
SurfacePI.png95.43 KB

offonoll's picture
Re: 3D math shapes

Thank you so much!!!! I will have a look soon!!

jersmi's picture
Re: 3D math shapes + vars

Strange and a little frustrating-- thanks for looking into this.

Using kineme3d 1.2 beta, QC version 3.1 (63.2). Attached is a sample of QC from activity monitor running cwright's original klein bottle with a structure / variable / interpolator (thought i'd try to eliminate the javascript patch just to see).

btw, same issue with the horn.qtz posted below...

edit: to be clear, you mean it seems i should be able to run at >20fps with u subdivisions = 96, v subdivs = 64, right?

and let me know if there's anything else i can send you to help sort this out. the ~.44 sec processing time for Parametric Surface patch corresponds directly to 2.16 fps-- does the trouble lie within?

PreviewAttachmentSize
SAMPLE_slow_3Dparam_surf.txt33.53 KB
QCversion.png
QCversion.png45.39 KB

jersmi's picture
Re: 3D math shapes + vars

oh yeah-- i'm not running anything else heavy on my system and smooth normals made no difference.

cwright's picture
Re: 3D math shapes + vars

There are a couple 1.2 betas -- make sure you've got the latest. If it's still a problem, just wait for the next one (or try a previous one, or something).

The sample doesn't help at all -- Kineme3D doesn't associate symbols names with addresses, so you usually won't see meaningful names where it's taking time, just a number (0x4182ed64). Internally we can map these back, but it's time consuming when we've got different builds (the addresses don't match once the source code is changed).

George, can you post which beta version you're using? (not 1.2, but the actual beta date (200901blah))

jersmi's picture
Re: 3D math shapes + vars

ah-ha! i was running the 2/16 version and i just installed the latest beta and now it works!

thanks so much for your patience! ah, well... :oops:

gtoledo3's picture
Re: 3D math shapes + vars

cwright wrote:
George, can you post which beta version you're using? (not 1.2, but the actual beta date (200901blah))

20090219.... Looks like jersmi has that one now!

jersmi's picture
Re: 3D math shapes + vars

thanks, gt.

jersmi's picture
Re: 3D math shapes

thanks so much, Rinboku!

i'm still chasing this trying to understand a little more how the numbers work. i started from scratch with a sphere, but the lighting is reversed on half the sphere. any hints?

X expression: cos(u * 180) * cos((v * 360)-180)/2

Y expression: sin(u * 180) * cos((v * 360)-180)/2

Z expression: sin((v * 360)-180)/2

also, why do some expressions create "noise" across the surface? for ex., change the Z expression to: cos((v*360)-180)/2

PreviewAttachmentSize
parametric_sphere.qtz4.26 KB

jersmi's picture
Re: 3D math shapes

the kineme 3D parametric shape patch is cool, but either i'm not understanding something or it appears to have a couple glitches? like the reversed lighting mentioned above, and when i plug it into a 3D Noise patch, i lose lighting altogether?

gtoledo3's picture
Re: 3D math shapes

When you run through any deformer patch, it strips normals... so make sure that you select either faceted or smooth on the renderer. If you don't use a deformer and you have smooth selected on your loader, it will be smooth no matter what the renderer setting.

rinboku's picture
Re: 3D math shapes

I think the cause of the noise is that the surface has overlapped. Because sin and cos are periodic function, creating surface will be repeated depending on the value of u or v.

And the undesirable shadow is probably because the back of the surface is seen by your equations.

jersmi's picture
Re: 3D math shapes

thanks for the info-- i'm learning! no excuse for math mistakes, but i make lots of them. :) anyway, i figured out the sphere-- it was my math, of course.

here's a .qtz with a few more parametric surfaces, and an experiment with kineme 3D.

PreviewAttachmentSize
ParametricSurfaces2.qtz89.31 KB

rinboku's picture
Re: 3D math shapes

Hello! That's very interesting.

Now I downloaded Kineme Structure Tools. So I came to be able to make structure easily and understood that using this patch make equations more simpler.

PreviewAttachmentSize
horn02.qtz7.05 KB

jersmi's picture
Re: 3D math shapes

Thanks once again for the update. I like your javascript patch a lot.

gtoledo3's picture
Re: 3D math shapes

You can use javascript for the variables too... when this was in alpha/beta(?), I was using the structure patch too, and asked Chris about it, so that I wouldn't be using two plugins (my theory is, less plugins for stuff that doesn't strictly require plugs, the better)- he referred me to this technique. It's not exactly what he sent me, but modded for the occasion.

This is the same comp, w/ javascript instead of the structure plugin....

PreviewAttachmentSize
horn02gtcw.qtz7.26 KB

jersmi's picture
Re: 3D math shapes

That's a good example, makes sense. More questions:

For ex., say i want different versions of the horn animations. Makes sense to me to keep the basic surface patch intact with the first JS patch and use the other JS patch to animate the form. Is it possible / practical to insert an expression as a variable in the second patch? Say i wanted to now animate the pointy tip of the horn and make it swoosh around-- could i do this with the second patch without altering the basic surface?