Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape, CAD, maker project and design.

First time visiting? Here are some places to start:

  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. Be respectful, on topic and if you see a problem, Flag it.

If you would like to contact our Community Manager personally, feel free to send a private message or an email.

Equation-driven curve

Edward_12Edward_12 Member Posts: 16 PRO
Hi, is there any way to create an equation-driven curve?  I've searched a bit on-line but can't seem to find something that does what I'd like. I'm looking to create a curve which follows a mathematical formula. It could be either polar or cartesian - doesn't matter which. 
All thoughts gratefully received
Edward

Comments

  • paul_chastellpaul_chastell Onshape Employees Posts: 75
    edited April 16
    I would suggest writing a custom feature using FeatureScript. Alternatively you could find and use an existing custom feature someone else already wrote. Or you could copy an existing feature and modify it to meet your needs. One example of what you can do this way is the "Parametric Curve" custom feature in https://cad.onshape.com/documents/578ff8b3e4b0e65410fcfda3/w/d33395f174e5b38f4abd6097/e/0c17de6a800d4aed83de417f
    Paul Chastell / VP of R&D / Onshape Inc.
  • Edward_12Edward_12 Member Posts: 16 PRO
    Hi Paul, thanks for the link. Hmmm. Right now I don't think I'm quite up to that. What I was hoping for is something like in SolidWorks whereby you can simply express y as a function of x and then specify a size range etc. Then, hey presto, you get the curve. You can then mirror etc. as necessary. 
    Is that a feature available in Onshape?
  • ilya_baranilya_baran Onshape Employees, Developers Posts: 760
    The parametric curve custom feature Paul linked to will let you do that -- no programming necessary.  Just read the instructions in the Info tab; while in that document, click the plus button in the toolbar to add it to your set of available custom features, then use it in your own document.
    Ilya Baran \ Director of FeatureScript \ Onshape Inc
  • paul_chastellpaul_chastell Onshape Employees Posts: 75
    You don't need to write any FeatureScript to use the custom feature I mentioned earlier, you could just use it like any other official Onshape feature, assuming it does what you need. If you add that custom feature to your toolbar (see documentation for help) then you can use it to do curves like I think you want, e.g. in this example doc I created the curve y = x*x with x in the range [-1,1] by defining 't' with the parameter feature and then setting x = #t and y = #t * #t. I also mirrored the resulting curve using the mirror feature.

    https://cad.onshape.com/documents/9f37c17aa964f1f4f3bc7bf1/w/dc8b4abdb015d5cc66bfd1f7/e/8622366028535ec6b660fd28



    Paul Chastell / VP of R&D / Onshape Inc.
  • Edward_12Edward_12 Member Posts: 16 PRO
    Thanks Ilya - I see it's your handiwork! One question - if I simply want to define x as a function of y, do I still have to use the independent parameter? Also, as I only want a 2d curve, I presume I simply make z=0mm (to draw on the top plane).
  • Edward_12Edward_12 Member Posts: 16 PRO
    Hi Paul and Ilya, Thanks for all the support. This is great and exactly what I'm after. Paul, sorry for misunderstanding your original post. When I see script like that I get worried! Edward
  • ilya_baranilya_baran Onshape Employees, Developers Posts: 760

     if I simply want to define x as a function of y, do I still have to use the independent parameter? Also, as I only want a 2d curve, I presume I simply make z=0mm (to draw on the top plane).

    Yes -- it is defined as a parametric curve to be more general.  For y=f(x), just set x to #t.
    Ilya Baran \ Director of FeatureScript \ Onshape Inc
  • mahirmahir Member, Developers Posts: 689 ✭✭✭✭
    @Edward_12, you should be able to replicate virtually any 1-to-1 (not self intersecting) curve function, including closed curves. Depending on the type of curve, don't forget you have the option to use cylindrical and spherical coordinate systems. They make rotating curves much easier to program.
  • Edward_12Edward_12 Member Posts: 16 PRO
    Thanks Mahir and Ilya. Right now, cylindrical and spherical co-ordinates might be a bit beyond me. I'll have to look into that when we don't have clients breathing down our necks! Ilya, you suggested using parametric equations preferably over y=f(x) approaches. At this stage, by way of a test, I'm simply trying to plot a circle. Hence: x=a(cos(#t)) and y=a(sin(#t)).  (let's say at this stage a=1). The parametric curve returns an error. For this feature is t specified in radians or degrees? It's not happy and I'm not sure why!
    Also, slightly unrelated to the (simple) maths that I'm failing to be do right now(!) is it possible to draw the parametric curve in a sketch as opposed to creating an independent curve? Or do I have to offset entities/use the curve within a new sketch? If so, the offset curve within the sketch doesn't appear to update if the parametric curve is modified. Is that correct?
    Next, in your examples for the parametric curve feature, the actual curve functions appear to be hidden - I can't simply double-click the feature within the document to understand how you've set up the functions. Is that something that I can access (i.e. am I doing something wrong?) or is it hidden on purpose?
    Finally, just so you know, Cartesian is spelt with an 'a' not an 'o' (you have 'Cartesion' in the feature script ;-)
    Thanks for all your help!
    Edward
  • ilya_baranilya_baran Onshape Employees, Developers Posts: 760
    A few answers:
    1. Not knowing if #t is in degrees or radians is precisely why it returns an error.  Use cos(#t deg) or cos(#t rad).  Also, you need to write out multiplication explicitly: a * cos(#t deg)
    2. You can't draw a parametric curve in a sketch, but once you have it separately, you can reference it from a sketch -- project it and then you can offset it.
    3. You can't see the functions in the example document because you don't have write access to the document (we're actually working on fixing that so you can see the expressions) -- for now, make a copy of the workspace for yourself and you'll be able to see the functions there.

    Ilya Baran \ Director of FeatureScript \ Onshape Inc
  • mahirmahir Member, Developers Posts: 689 ✭✭✭✭
    edited April 17
    For clarity, #t is a unitless parameter that steps incrementally from min_t to max_t. You can think of it as time, but without any time units. And thanks for pointing out the typo. I'll fix that :smile:

    As for spherical/cylindrical coordinate systems, they're very handy and intuitive once you know how to use them. Instead of linear XYZ positions, you can use one or more angles instead - R/Theta/Z for cylindrical and R/Theta/Phi for spherical. For example, your circle is much easier in cylindrical coordinates. No messy trig functions - at least not that you can see. All the trig happens behind the scenes.

    Cartesian             Cylindrical
    X=r*cos(#t deg)    R=2*r
    Y=r*sin(#t deg)     Th=#t
Sign In or Register to comment.