Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

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_GoodwinEdward_Goodwin Member Posts: 25 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: 126
    edited April 2018
    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
    TVP, Onshape R&D
  • Edward_GoodwinEdward_Goodwin Member Posts: 25 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, HDM Posts: 1,210
    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 \ VP, Architecture and FeatureScript \ Onshape Inc
  • paul_chastellpaul_chastell Onshape Employees Posts: 126
    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
    TVP, Onshape R&D
  • Edward_GoodwinEdward_Goodwin Member Posts: 25 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_GoodwinEdward_Goodwin Member Posts: 25 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, HDM Posts: 1,210

     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 \ VP, Architecture and FeatureScript \ Onshape Inc
  • mahirmahir Member, Developers Posts: 1,304 ✭✭✭✭✭
    @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_GoodwinEdward_Goodwin Member Posts: 25 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, HDM Posts: 1,210
    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 \ VP, Architecture and FeatureScript \ Onshape Inc
  • mahirmahir Member, Developers Posts: 1,304 ✭✭✭✭✭
    edited April 2018
    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
  • Nickolas_LockardNickolas_Lockard OS Professional Posts: 36 ✭✭
    edited December 2018
    I've tried to make a hyperbolic cosine curve in a copy of Paul_Chastell's example file using this:

    x = #t
    y= (e^#t+e^-#t)/2
    z= null (blank)

    It says I don't have a valid expression for y. Is there another entry for e besides 'e'?

    EDIT update--Thank you Paul for the example file! This was a helpful contribution :) I was able to get a coshx curve using

    x = #t
    y = (2.71828^#t + 2.71828^-#t)/2
    z = 1

    However; now I can't seem to get this curve into my part studio. I'm not familiar with working with curves. Can I copy it into a sketch and then transform/scale it?

    The purpose of my question is--I am designing an enclosed trailer and want it to use minimal metal, minimal weldments, and max strength/weight ratio in z direction.



  • mahirmahir Member, Developers Posts: 1,304 ✭✭✭✭✭
    @nick_lockard, Z can’t be blank. Even if you’re plotting a 2D curve, you have to pick which Z plane it sits on. Try setting Z = 0. 
  • calvin_bakercalvin_baker Member Posts: 1
    I'm having a hard time getting the cylindrical curves to work. I'm trying to draw a curve with the equation R=(5*theta/360)+5, where 0=<theta=<360 (a graphing calculator confirms that function is valid). When placing this formula in the "R" field of the Onshape feature, I replace "theta" with "#t" (I have a parameter defined as "t"). The "Theta" field of the feature has "#t" in it, so that the function defining R is variable upon Theta. Not sure what else to do beyond that. Any suggestions?
  • mahirmahir Member, Developers Posts: 1,304 ✭✭✭✭✭
    edited June 2020
    @calvin_baker
    Try this. #t by itself is unitless. OS might assume a unit, but it won't necessarily be the right unit (rad vs deg).

    R = 5*#t/360+5
    Theta = #t deg
  • soubhik_sarkar868soubhik_sarkar868 Member Posts: 1
    Thanks for the feature script  :)
  • joseph_shaffjoseph_shaff Member Posts: 2
    Made a Hyperbolic Primary Mirror Blank plotting points from a graphing program.
    When we are talking about the wavelength of light though ... and 3D printing the mirror and coating it ...
    I'm concerned about the accuracy that it will not be enough being for a Telescope.
    It will need a Foucault Test as well.  Or something better like it.

    Moving to equations now.
    So excuse me for asking with such ambiguity as I take Integrals are we able to do much of the stuff with curves we are learning about ?

    (There is currently a Telescope Lawsuit on China for price gouging and monopoly)


  • joseph_shaffjoseph_shaff Member Posts: 2
    Gawd, I wonder if we can rethink the print layering process.
    I mean you don't want jagged edges on mirrors reflecting telescope light back.
  • EvanReeseEvanReese Member, Mentor Posts: 2,081 ✭✭✭✭✭
    Made a Hyperbolic Primary Mirror Blank plotting points from a graphing program.
    When we are talking about the wavelength of light though ... and 3D printing the mirror and coating it ...
    I'm concerned about the accuracy that it will not be enough being for a Telescope.
    It will need a Foucault Test as well.  Or something better like it.

    Moving to equations now.
    So excuse me for asking with such ambiguity as I take Integrals are we able to do much of the stuff with curves we are learning about ?

    (There is currently a Telescope Lawsuit on China for price gouging and monopoly)


    At the risk of highjacking this thread for my own curiosity, how are you finishing the 3D prints to make mirrors? Sounds interesting
    Evan Reese
  • sebastian_ramos_rouxsebastian_ramos_roux Member Posts: 2
    Hi there, trying to use the Parametric Curve feature script to generate a desired curve. I've checked that the parametric functions I'm entering plot the desire result using Matlab, however when I enter them into the feature script they produce the error "Parametric curve did not regenerate properly: error regenerating." I am not getting a syntax error from the feature script before attempting to plot the curve. The equations as I entered them into Parametric Curve feature script are pictured below:

    The only difference with the function for Y is a sin in place of a cosine. I have tried with and without the inch unit callout at the end, as well as putting the rad unit callout inside the parentheses of the parameter (#t*rad), and getting rid of the rad unit callouts next to the parameter callouts that aren't inside the cos, all without success. Any help would be appreciated, thank you!
  • mahirmahir Member, Developers Posts: 1,304 ✭✭✭✭✭
    Got it to work using the following equations. I think maybe it was having issues with your 2*PI not having a unit but the -#t*rad does.

    X: (cos((2*PI-#t)*rad)*(1-.00024964*#t)^6-.0047*#t^5-.0296*#t^4+.0619*#t^3)*in
    Y: (sin((2*PI-#t)*rad)*(1-.00024964*#t)^6-.0047*#t^5-.0296*#t^4+.0619*#t^3)*in

    https://cad.onshape.com/documents/305f97b18fef3b69ced065d7/w/a808a34d0b2cf12d791796ab/e/8a3c082a96807eda9e2f54f3

  • cfraytetcfraytet Member Posts: 3 EDU
    I'm doing some simple cams with 9th grade engineering students and one of the examples we use is a heart shaped cam. 
    Student: "What's a heart shaped cam for" 
    Me:"Let's see what we find... oh, Google says it's to create uniform velocity. Which means we need a cardioid function!"
    I don't see a Polar coordinate system (unless that's what Cylindrical is).
    Otherwise, how would I enter the Cartesian version into the Parametric curve function?

  • mahirmahir Member, Developers Posts: 1,304 ✭✭✭✭✭
    edited December 2023
    Cylindrical is just polar with Z. And spherical is also like polar, but with a second angle phi.
Sign In or Register to comment.