Close



Page 3 of 6 FirstFirst 12345 ... LastLast
Results 21 to 30 of 74

Hybrid View

  1. #1
    Super Moderator Roxy's Avatar
    Join Date
    Apr 2014
    Location
    Lone Star State
    Posts
    2,182
    Quote Originally Posted by old man emu View Post
    My question is:

    Can this formula
    http://paulbourke.net/geometry/torus/supertoroid3.gif

    be written in a way that OpenScad can produce an object from it?
    Quote Originally Posted by Mjolinor View Post
    Because you can only define variables to work on primatives the only way this can be done is to define a very small sphere (or cube) and then move that through the values of x y z that you want. I will give you any shape but it will take massive processing power to do anything complex.
    This is an interesting test of the powers of OpenScad. I think Mjolinor is right about it taking a lot of processing power. But I think it can be done very successfully. At the highest level, I would define a module that used a 'for' loop on n1 and n2 to send them through their range. (That way, you can generate each shape in your table up above.) I would have this module call the toriod() module that I wrote. And I would display this torroid and some suitable translate() based on n1 and n2 so I could generate the same table.

    In the toriod() module I would use a nested 'for' loop to vary theta and phi over their range. I would generate a small sphere at each of the (x,y,z) coordinates that got generated from these loops. And here is the difference from what Mjolinor suggests.

    All of that logic inside the toriod() module's loops would be inside a hull() statement. I think OpenScad will draw a hull around those points so you get a nice, smooth skin.

  2. #2
    Staff Engineer old man emu's Avatar
    Join Date
    Oct 2013
    Location
    Narellan, New South Wales, Australia
    Posts
    912
    What would happen if, instead of having the Origin at (0,0,0), which results in sin and cos being -ve in certain segments, you translate the centre of the object to (r0, r0 , r1 ) so that X, Y and Z are always positive?

    Alternatively, and probably the best way is to do the cheat that Roxy proposed:

    1. Restrict the ranges of theta and phi to between 0 an pi.
    2. Do three translations to put this quarter into the other three quadrants.
    3. Consecrate the Union.

    OME

  3. #3
    Super Moderator Roxy's Avatar
    Join Date
    Apr 2014
    Location
    Lone Star State
    Posts
    2,182
    Quote Originally Posted by old man emu View Post
    What would happen if, instead of having the Origin at (0,0,0), which results in sin and cos being -ve in certain segments, you translate the centre of the object to (r0, r0 , r1 ) so that X, Y and Z are always positive?
    I would love to hear a detailed analysis of this transformation by a resident Math Major. But my guess (just off the top of my head) is this doesn't work. Those equations are written using a spherical (3D Polar) coordinate system that produce a mapping into the Cartesian coordinate system. I would expect shifting its center isn't going to change the fact the equations lose the sign of cos() & sin() function when even powers are used for n1 and n2.
    Quote Originally Posted by old man emu View Post
    Alternatively, and probably the best way is to do the cheat that Roxy proposed:
    This is an example of where the OpenJScad language shines. From a computational perspective, only one quadrant of information would have to be generated (and be saved as a variable) and then it could be mirrored 3 times to fill out the entire solid.

    Maybe Dacb would know enough to convert the existing or next Toriod.scad to a J-Scad file? That would be interesting to see. Especially since J-Scad has cleaned up the syntax of the language so much.
    Quote Originally Posted by old man emu View Post
    1. Restrict the ranges of theta and phi to between 0 an pi.
    The way I understand it, we are dealing with both sin^2() and cos^2() functions losing the negative values. And we have all combinations of sin^n1() and cos^n1() and sin^n2() and cos^n2() of both theta and phi. The only place both of those functions are always positive is in the first quadrant. So we need to restrict theta to values of 0 to pi/2. You can not restrict phi to that range because you wont get the complete shape of the toroid. Phi needs to still vary from 0 to pi. What this means is there may still be some limitations on n2 being stuck at positive numbers because you can't be raising cos(phi) (with a negative value) to a fractional power. However, I think n1 is free to be both positive and negative with this technique.
    Quote Originally Posted by old man emu View Post
    2. Do three translations to put this quarter into the other three quadrants.
    Not translations... mirror() operations. We need to mirror() the positive portion ((x,y,z) all positive) into the other 7 areas. Probably doing the mirror() to the negative z area of the first quadrant makes sense. And then mirroring that to either the 2nd or 4th quadrant would be next to form a 1/2 toroid. And then mirror() that to get the whole thing.

    The big problem with doing this in OpenScad is you have to keep regenerating the base information you are going to mirror() even though you already have generated it. OpenJScad doesn't have this limitation.
    Quote Originally Posted by old man emu View Post
    3. Consecrate the Union.
    I would do the mirror() with an ever so slight transformation([,,]) towards the reflection... That way, you will end up with a manifold surface that is fully joined of the two halves. Without this, you might end up with errors in the .STL file.
    Last edited by Roxy; 12-05-2014 at 07:42 AM.

  4. #4
    Senior Engineer
    Join Date
    Jun 2014
    Location
    Burnley, UK
    Posts
    1,662
    That is what I did. A very small sphere redrawn for 1 degree movements and you do end up with a toroid but you had better have a Cray handy if you want to do anything with it other than grow your fingernails and hair while you wait.

  5. #5
    Super Moderator Roxy's Avatar
    Join Date
    Apr 2014
    Location
    Lone Star State
    Posts
    2,182
    Quote Originally Posted by Mjolinor View Post
    That is what I did. A very small sphere redrawn for 1 degree movements and you do end up with a toroid but you had better have a Cray handy if you want to do anything with it other than grow your fingernails and hair while you wait.
    Can you post the code? I would like to play with it.... (Without doing all the work to write it! )

  6. #6
    Staff Engineer old man emu's Avatar
    Join Date
    Oct 2013
    Location
    Narellan, New South Wales, Australia
    Posts
    912
    OK. Let's put this on hold for the weekend. I've sent an email to Dr Bourke asking for his help.

    OME

  7. #7
    Senior Engineer
    Join Date
    Jun 2014
    Location
    Burnley, UK
    Posts
    1,662
    You have a Cray then.



    r0 = 4;
    r1 = 2;


    for (v = [0:360])
    {
    for (u = [0:360])
    {
    assign (A = ((r0 + r1 * cos(v)) * cos (u)), B = ((r0 + r1 * cos(v)) * sin (u)), C = (r1 * sin(v)))
    {
    translate ([A,B,C])
    sphere (r=1);
    }
    }
    }

    I think it is right.
    AB and C are xy and z (I thought xyz maybe special within Openscad), your angles are u and v, radii are r0 and r1.

  8. #8
    Super Moderator Roxy's Avatar
    Join Date
    Apr 2014
    Location
    Lone Star State
    Posts
    2,182
    I wasn't able to leverage what you had... So I started with a blank screen in OpenScad.

    It turns out, you don't need a Cray Super Computer to do this. I just made 3 different toriods. I made the generic one with n1=1 and n2=1. And then I made a couple more just to make sure the code worked:

    Toriod.jpg

    UPDATE: Those equations might be flawed. Some of the possible toroids only generate 1 quadrant of the shape. For example, n1=2 and n2=1. You get the correct shape, but only 1/4 of the toroid. I think some of these toroid shapes are imaginary. The reason is this: You can't take a fractional power of a negative number. But X is defined by X= cos^n1(theta)*(r0+r1*cos^n2(phi)) The cosine function goes negative as theta and phi sweep through the circle. So some of the coordinates generated by the equations are meaningless. (You are not allowed to raise a negative number to a fractional power --- that is undefined)

    FURTHER UPDATE: The equations are wrong. Any time n1 or n2 is an even number, you are squaring the sin() and cos() functions. This causes any negative number they produce into a positive number. There is no way to generate points in the negative quadrants if you have n1^2 or n2^2 positive. n1 & n2 can only be 1,3,5,7,etc.
    Last edited by Roxy; 12-04-2014 at 05:09 PM.

  9. #9
    Super Moderator Roxy's Avatar
    Join Date
    Apr 2014
    Location
    Lone Star State
    Posts
    2,182
    OK... I'm done with Toroids for now... Here is an updated screen shot with various odd numbers for n1 & n2. Note that the 'round' toroid in the upper right is not a generic toroid. Its edges are curved kind of funny. But, you probably don't want that one anyway, because it is going to waste a lot of space in the doughnut box when you make donuts that shape.

    Toriod.jpg

    You might want to bump the resolution up to examine some of the shapes. Especially ones like the center one. But if you do that, you might want to comment out the generation of the other toroid's because this gets very expensive computationally (but still no need to run out and buy a Cray Super Computer!). You can do that by changing the:

    for (theta = [0:18:360])
    for (phi = [0:18:360])

    to what ever you can tolerate. Maybe something like:

    for (theta = [0:6:360])
    for (phi = [0:6:360])

    and by changing all the +18's to +6 in the hull() directive:

    Toriod.jpg

    And of course... If that is too 'thin' for all the doughnut eater's that are policing Australia, you can mess with the value for r1 so they only need one instead of the usual 2 or 3 doughnuts per session!
    Last edited by Roxy; 12-04-2014 at 04:48 PM.

  10. #10
    Senior Engineer
    Join Date
    Jun 2014
    Location
    Burnley, UK
    Posts
    1,662
    You are right. I only used mine in the first quadrant as it took too long. The shape needs translating wholly into the first quadrant before it is made in order to stop imaginary number problems.

Page 3 of 6 FirstFirst 12345 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •