Formula example

DiomedeDiomede Posts: 9,938
edited September 2016 in Carrara Discussion

The following is a variation on an example formula found on pages 398-399 of the Carrara 1 Bible.

Insert a formula object

In the properties tray, delete the default formula.

Copy and paste the following to the formula box and click "parse" then play with the p1 and p2 parameters.

factor = 5;
a = (-PI/2) + ((PI/2 - (-PI/2)) * u);
b = 2 * PI * v;
x = tan(a);
y = ((p2 * 10) * x) + sin(2 * a) + sin(b);
z = (1 + ((p1 * 10) * x)) + sin(2 * a) + cos(b);
x = factor * x;
y = factor * y;
z  factor * z;

 

formula example.JPG
1198 x 722 - 89K
Post edited by Diomede on

Comments

  • DUDUDUDU Posts: 1,923

    Thanks for sharing, Diomède !

    Last Sunday, I downloaded all the HTML and all the objects from the French site, who know, it can close one day...

    http://gianpf.free.fr/indexzips.html

    Lot of surprises with these formulae !

    Cheers !

  • DUDUDUDU Posts: 1,923
    edited September 2016

    ...and last year, I played with formulae in the shader room : http://mhdproductions.be/Carrarators/Formules.zip

    Formules.jpg
    1000 x 480 - 194K
    Post edited by DUDU on
  • DiomedeDiomede Posts: 9,938

    That is geat, Dudu.  I have downloaded them as well.  I love that website.  I've amended a couple of them.  Probably most useful is the torus formula.  The French site has a great default formula, but it doesn't incorporate the adjustable p1 and p2 parameters.  I made a slight adjustment.  Try this.

    d=1+p1;e=1+p2;
     p=2*PI*(u-0.5);
     q=2*PI*(v-0.5);
     x=(d+e*cos(q))*cos(p);
     y=(d+e*cos(q))*sin(p);
     z=e*sin(q);

     

    Now, you can adjust the p1 and p2 parameters to make the torus bigger or smaller and thicker or thinner by using the p1 and p2 parameters.  Here are two examples.

     

     

    torus formula fat.JPG
    1026 x 723 - 68K
    torus formula thin.JPG
    980 x 698 - 72K
  • DartanbeckDartanbeck Posts: 14,776

    Very cool! I really like this shape:

    Cool Formula Shaders examples, and I really like the ammendment to the Torus!

    Bravo you two!!

  • HeadwaxHeadwax Posts: 7,758

    wonderful,! now tell me, when you adjust these parameters do you have an image in your head  of what it will look like ?

  • DiomedeDiomede Posts: 9,938
    edited September 2016

    Hi, Headwax.  When I was editing the default torus formula provided by that Great French Site, I did have an idea, but I also admit to some trial and error in other cases.  There are some basic concepts.

    1)  Often, you will need at least 5 lines.  One each specifying the x, y, and z coordinates and one each converting the u and v range to a range used by your formula. Each line must end in a semicolon.

    2)  The formula needs to be able to identify results for all of the u and v values from 0 to 1.  Your formula might have a different range rather than from 0 to 1.  For example, trigonometry functions are evaluated relative to pi (3.14) to -pi (-3.14) or from 0 to 2pi.  So, you would need lines converting u and v to something related to pi.  In the first example above, the lines for a and b convert u and v to ranges related to pi.  In the second example, it is the lines for p and q that convert u and v values to values related to pi.

    3)  Each u and v combination needs to result in a point for the x,y,z coordinates of the "batting cage" as I've seen the Carrara space referred to.  In the example above, the lines for x, y, and z specify each in terms of one or more trig functions (sine, cosine, tangent,...).  In the first example, the trig functions refer to a and b.  Recall that the first two lines specifying a and b convert between a pi-based world and a world of u and v from 0 to 1.  These don't have to be trig functions.  The formula editor can use logarithms, square root, power functions, absolute value, etc.  You can also use logical operators such as if/then or minimum/maximum.

    4)  The formula editor won't try to create the object until you click parse.

    5)  You can use the p1 and p2 parameters to make the object adjustable by modifying the lines for x,y,z,u,or v.

    6) Many of the formulas on "that great French site" are based on functions from trigonometry.  Trig funcitons need a uv conversion related to pi

    7) The trig functions sine and cosine tend to return results that look like a wave between 1 and -1.  Trig functions like tangent tend to include a division by zero and so approach infinity at some point.

    8) If you do searches on the web for a formula to get a topology in 3D space, it will need to be converted to the exact language used by Carrara.  For example, don't use pi for 3.14, instead use PI for 3.14 (capital letters).

    --------------------------------

    For example, you can find a formula for a torus by searching the web and finding a math forum.  http://mathforum.org/mathimages/index.php/Torus

    The math forum explains how a torus is described, quote

    "The parametric equations that describe this type of torus are:

    x(u, v) =  (R + r \cos{v}) \cos{u} \, y(u, v) =  (R + r \cos{v}) \sin{u} \, z(u, v) =  r \sin{v} \,

    where u and v both range between 0 and 2\pi."

     

    OUCH!!!!!!  Now what? 

    First, note that the torus formula from the math website says "where u and v range between 0 and 2pi."  But Carrara needs u and v to range between 0 and 1.  Also, this particular formula needs 2 radiuses, one for the whole torus (R) and one for a slice (r) of a ring. That French site uses d for the big torus and e for the slice of a ring fixed them at 1. It reads as d=1;e=1;  I made these adjustable by modifying the French site's lines for d and e by parameters p1 and p2.  They now read as d=1+p1;e=1+p2; See top of formula in post about the torus above.

    That French site solved the uv and pi conversion by providing the lines for new variables p and q, which are p=2*PI*(u-0.5); and  q=2*PI*(v-0.5);  See above.  If you put in numbers for u and v from 0 to 1, then p and q return numbers from -pi to pi.  Now, u and v over 0 to 1 will result in a complete cycle related to pi for a trig function.  Carrara uses capital letters for PI rather than pi.

    Here is how to translate a line for x.  The math website says that x is equal to (bigtorus plus (slice times cosine v)) times cosine u.  The French website translates that to x=(d+e*cos(q))*cos(p); so it can be read by Carrara.

    Apply same conversion technique for y and z.

     

    I suspect that wasn't very clear because it is hard to describe translating one language for a formula to another language of the same formula if you can't point at things and underline things.  However, there is method to the madness.

     

    (Initial post edited to better describe d and e).

     

     

     

    Post edited by Diomede on
  • HeadwaxHeadwax Posts: 7,758

    @diomede, wow, that's really very impressive, thank you,

    isnt it amazing that an object can be broken down into a formula - and vice versa

    thanks for taking the time to explain it - I grasp the concepts now.

    Though obviosuly a long way off from making useful things.

     PI... who would have thought :)

  • FifthElementFifthElement Posts: 569
    edited September 2016
    head wax said:

    @diomede, wow, that's really very impressive, thank you,

    isnt it amazing that an object can be broken down into a formula - and vice versa

    thanks for taking the time to explain it - I grasp the concepts now.

    Though obviosuly a long way off from making useful things.

     PI... who would have thought :)

    Not only an object, entire worlds can be described with relatively simple formulas ...smiley

    Fractal Lab 2015 Demo from subBlue on Vimeo.

    Post edited by FifthElement on
  • HeadwaxHeadwax Posts: 7,758

    ah yes, and great voice too, thanks for that link

  • diomede said:

    a = (-PI/2) + ((PI/2 - (-PI/2)) * u);

    Algebraically, this is a head-scratcher.

    a = (-π/2) + ((π/2 - ( -π/2 )) * u)

    a = (-π/2) + (( π/2+π/2 ) * u )

    a = (-π/2) + ( π * u )

    (Please excuse my mess...)

    2a = -π + ( π * u * 2)

    2a/π = -1 + (u * 2)

    2a/π = 2*u - 1

    (And now, some cleaning up.)

    2a = (2*u - 1) * π

    a = (u - 1/2) * π

    Double-checking with MathStudio... it coughed up a=-π/2 + πu, which is actually the same thing but a little less clear for these purposes.

    If you plug a=(u-1/2)*PI into that formula, you should get the same shape, right?

  • DiomedeDiomede Posts: 9,938

    Territan. The original expression is inelegant to say the least.  The base formula from which that was derived is found on page 399 of the Carrara 1 Bible by Doug Sahlin.  I just double checked to make sure I copied the equation for "a" correctly and it looks like I did.  When I modified the y and z equations to include the p1 and p2 parameters, I should have simplified the whole thing. I also modified the expression for x, switching it from a sine function to tangent.

  • DartanbeckDartanbeck Posts: 14,776

    Neat!

  • DiomedeDiomede Posts: 9,938

    Could this thread be merged with this other thread?

    http://www.daz3d.com/forums/discussion/30859/formula/p1

     

    Territan said

    Okay kids, here's a somewhat simplified formula to get you started:

     

    x=60*(u-0.5);
    y=p2*sin(x*20*p1);
    z=30*v;

    That'll produce a vertical plane. Move p1 and p2 off of zero, and you'll see it get wavy.

    Here's how to read what's going on here.

    First, you know how objects are UV-mapped, and how one corner is the 0,0 coordinate and the opposite corner is the 1,1 coordinate, and everything in between is some pair of decimals between those? That's what the u and v here are doing: Every value of U and V between 0 and 1 (in tiny increments) is plugged into the formulas. Whatever results come back, that's where Carrara puts a pixel, and that pixel will have that uv mapping.

    I flat-out multiplied v by 30 in order to get a vertical thing, running from z=0 to z=30.

    I subtracted 0.5 from u so it would go from -0.5 to 0.5 instead of 0 to 1. Then I multiplied that by how big I wanted the wall in the x axis, in this case 60. So the wall runs from x=-30 to x=30.

    y is admittedly a little more complicated, but much more interesting. I wanted a wavy quonset-hut type corrugated metal wall effect, so I want it to wave back and forth across the y-axis. So I set y to a value based on the sine of x (you know, like a sine wave?) so it would oscillate back and forth.

    Sorry, yeah, it does contain a little math. As the old saying goes, "Welcome to the Turing Tarpits, where anything is possible but nothing interesting is easy."

    I multiplied x by both 20 and p1 so I could control the rate of oscillation without changing the formula itself. After I had that number, I multiplied that by p2 so I could control how deep the waves were.

    You'll need to move both p1 and p2 off of zero, but when you do, you'll see it get wavy.

    Different formulas loop across different values using different variables, and use different variables for output. Again, the Carrara 7 manual has that information.

    Admittedly, the parser is a bit finicky (it doesn't like decimals that start with the period, for example), but this provides Carrara with the power to image any shape and effect you can define mathematically.

  • MystarraMystarra Posts: 32,628

    That is geat, Dudu.  I have downloaded them as well.  I love that website.  I've amended a couple of them.  Probably most useful is the torus formula.  The French site has a great default formula, but it doesn't incorporate the adjustable p1 and p2 parameters.  I made a slight adjustment.  Try this.

    d=1+p1;e=1+p2;
     p=2*PI*(u-0.5);
     q=2*PI*(v-0.5);
     x=(d+e*cos(q))*cos(p);
     y=(d+e*cos(q))*sin(p);
     z=e*sin(q);

     

    Now, you can adjust the p1 and p2 parameters to make the torus bigger or smaller and thicker or thinner by using the p1 and p2 parameters.  Here are two examples.

     

     

    donutz!

    just needs frosting and sprinkles cheeky

  • MystarraMystarra Posts: 32,628
    DUDU said:

    Thanks for sharing, Diomède !

    Last Sunday, I downloaded all the HTML and all the objects from the French site, who know, it can close one day...

    http://gianpf.free.fr/indexzips.html

    Lot of surprises with these formulae !

    Cheers !

    Haz the triquetra!!heart

    oh mann, i did that manually in wings 3d

  • DUDUDUDU Posts: 1,923

    Formula object+ jiggle deformer must be cool!

    Look here:https://www.daz3d.com/forums/discussion/comment/4513376/#Comment_4513376

  • FENgariFENgari Posts: 1,104

    Not formula object + jiggle DUDU, but formula object + follow polyline...

    ..Noeud de Trèfle - so cool! Yeah wink Other follow polyline example here.

  • mindsongmindsong Posts: 1,108

    wow - do that one in stereo-3D if you want to blow minds.

    way too cool!

    --ms

  • DiomedeDiomede Posts: 9,938
    Selinita said:

    Not formula object + jiggle DUDU, but formula object + follow polyline...

     

    ..Noeud de Trèfle - so cool! Yeah wink Other follow polyline example here.

     

    Magnificent!

  • FENgariFENgari Posts: 1,104

    Hi mindsong,

    Here's your stereoscopic pair - you'll need to click to enlarge and cross your eyes till the two images line up as one to see it!

  • FENgariFENgari Posts: 1,104

    Second method... as some might find crossing their eyes uncomfortable.

    Focus eyes between the two images and gaze deep into the distance until the two images slide over each other perfectly to see the stereoscopic effect.

  • mindsongmindsong Posts: 1,108

    oh yeah!

    :)

    oddly, I can do the 'cross-eye view' without a second thought, but I can only glimpse the 'infinity view' every-so-often. My brain doesn't do that...

    Thanks for doing that. very cool!

    --ms

  • https://sourceforge.net/projects/mathmod/                   

    MathMod

    MathMod is a mathematical modeling software

    Can any of the "formulas" in Mathmod work in Cararra, or do they have to be modified? I am interested in the Gyroid models. If they can be created in Carrara by just a formula that would be great.

     

    Mathmod screen snap.JPG
    1366 x 768 - 182K
  • DiomedeDiomede Posts: 9,938
    edited November 11

    Carrara evaluates U,V for X,Y,Z  over 0-1.  If the formulas you have use the same, then can use in Carrara without alteration (except minor like adding a semicolon).  If not, then must have lines translating.  For example, most Trigonometry is expressed as a function of Pi (3.14).  To use in Carrara, I believe there must be lines translating the range (-Pi to Pi) to (0-1).

    My quick look at MathMod makes me think a similar translation must occur.  In the pic you attached, the domain appears to be from -4 to 4.  In that pic, the forumla is expressed in terms of trig functions without translating -Pi-Pi to 0-1.   At a minimum, the Carrara formula modeler would need lines translating that to 0-1.

     

    On the other hand, Mathmod claims to have OBJ export, so can be used in any program capable of reading OBJ, including Carrara.

    Post edited by Diomede on
  • WendyLuvsCatzWendyLuvsCatz Posts: 22,626
    edited November 11

    I find it is often better to do something in a program designed to do it than to try and do everything in Carrara

    I mean Carrara rocks but it has awesome importing abilities too

    better than some popular programs on this site

    All my exportable Unreal Engine assets import for example with texture maps and rigging!

    try doing that in DAZ studio 

    the fractals from Mandelbulber 3D are a bit harder as so massive but done it too

    Post edited by WendyLuvsCatz on
  • FlashGarciaFlashGarcia Posts: 465
    edited November 11

    Diomede

    I used Mathmod's export function for one of the "gyroids" and then opened it up in Carrara, last year.  Worked fine. My goal at that time was to make a large cube model that resembled the inside of bone marrow, so that I could make an animation of a tiny medical nanobot moving through it. Something like the scenes in the old film "Fantastic Voyage" when the minaturized sub and crew were moving through the webbing of the patients heart.

    I was just curious if those Mathmod formulas could be used in Carrara somehow, too.

    bone marrow 1.jpg
    1600 x 1278 - 280K
    674x501_1802927_934633_1459324078.jpg
    674 x 501 - 89K
    images 3.jpg
    1000 x 750 - 160K
    off_export_wings3d.jpg
    800 x 640 - 127K
    Post edited by FlashGarcia on
Sign In or Register to comment.