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.

Most efficient way to turn a curve into a list of numbers?

EvanReeseEvanReese Member, Mentor Posts: 2,135 ✭✭✭✭✭
This is for the Attractor Pattern feature. I want to add the ability for the user to draw a custom falloff curve for the pattern that will change the way the number range is distributed. Currently, the falloff is linear, as in the image on the right. I'd like to be able to draw an s-shaped spline on the top plane (or any arbitrary curve), and get the result on the left (which I've just faked here by using a different base surface). Since there are potentially so many instances, I'm looking for the most lightweight strategy to get these new numbers, while still giving the user full control over the curve shape. Anybody have any ideas about how to do it efficiently?
My initial thought was to use raycast to find the xy coordinate at each point on the curve, which I think could work, but it can take a few seconds when the point count gets into the thousands. Does someone know a more efficient way?
Evan Reese

Answers

  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    I think evDistance should be faster, and moreover it would resolve intersections in negative area.
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,683
    You could just use evEdgeTangentLines to get an array of points - the x values would not be equally spaced though. 
    Senior Director, Technical Services, EMEAI
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,683
    edited September 2020
    Or, like @konstantin_shiriazdanov says, you could use evDistance with an array of Line or Plane objects to get the intersection points at regular intervals.  It may be marginally slower, though probably not enough to worry about in comparison to the rest of the feature  :s
    Senior Director, Technical Services, EMEAI
  • EvanReeseEvanReese Member, Mentor Posts: 2,135 ✭✭✭✭✭
    NeilCooke said:
    Or, like @konstantin_shiriazdanov says, you could use evDistance with an array of Line or Plane objects to get the intersection points at regular intervals.  It may be marginally slower, though probably not enough to worry about in comparison to the rest of the feature  :s
    This sounds more like what I'm going for. I'd like the x values to be evenly spaced so curves behave more intuitively as they approach a vertical direction. I don't follow how evDistance would get me this though. Doesn't it find the min or max distance? I need to find the distance in a certain direction only (from a point on the x-axis to the curve in the y-direction)
    Evan Reese
  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    edited September 2020
    If law curve is on the XY plane you need to find intersection between the line with origin at (x,0,0) and direction (0,1,0) and the law curve. evDistance gives intersection point, and you extract its ordinate. For example take a look at Graphic dependency feature
  • mahirmahir Member, Developers Posts: 1,307 ✭✭✭✭✭
    edited September 2020
    I have a small suggestion. Using a separate sketch for the falloff curve would definitely give you more options, but perhaps there could be some canned options that could be calculated on the fly without a curve - linear, sine/spline, exponential decay, asymptotic decay, polynomial, etc. And those options could have one or more coefficients to play with, at the very list the falloff distance. Or you can just ignore this and go with a universal sketch based solution :)
  • EvanReeseEvanReese Member, Mentor Posts: 2,135 ✭✭✭✭✭
    mahir said:
    I have a small suggestion. Using a separate sketch for the falloff curve would definitely give you more options, but perhaps there could be some canned options that could be calculated on the fly without a curve - linear, exponential decay, asymptotic decay, polynomial, etc. And those options could have one or more coefficients to play with, at the very list the falloff distance. Or you can just ignore this and go with a universal sketch based solution :)
    I've also considered this, and it has advantages over the sketch-based solution, for example, to produce a sine wave with a decay, which could be tricky to sketch. Also much faster. I'm not really much of a math guy so I'm not sure what some of the ones you listed are, but will look them up. What are some others that you included in the "etc"?
    Evan Reese
  • mahirmahir Member, Developers Posts: 1,307 ✭✭✭✭✭
    edited September 2020
    Evan_Reese said:

    I'm not really much of a math guy so I'm not sure what some of the ones you listed are, but will look them up. What are some others that you included in the "etc"?
    Don't quote me on the specific names, but here's what I think some useful falloff functions would be, with "a,b,c" being misc coefficients to dial in the shape. There's a crapton more formulas (hyperbolic, logarithmic, etc) , but for practical X intervals they don't look appreciably different. And virtually any shape can be approximated via a general polynomial.

    Asymptotic decay
    y = e^(-ax)

    Exponential decay 
    y = 1-e^a(x-1)

    Sinusoidal
    y = .5(1+cos(πx))

    Circular/elliptical
    y = sqrt(1-x^2)

    Parabolic
    y = 1-ax^2

    General polynomial
    y = ax + bx^2 + cx^3...

  • EvanReeseEvanReese Member, Mentor Posts: 2,135 ✭✭✭✭✭
    mahir said:
    Evan_Reese said:

    I'm not really much of a math guy so I'm not sure what some of the ones you listed are, but will look them up. What are some others that you included in the "etc"?
    Don't quote me on the specific names, but here's what I think some useful falloff functions would be, with "a,b,c" being misc coefficients to dial in the shape. There's a crapton more formulas (hyperbolic, logarithmic, etc) , but for practical X intervals they don't look appreciably different. And virtually any shape can be approximated via a general polynomial.

    Asymptotic decay
    y = e^(-ax)

    Exponential decay 
    y = 1-e^a(x-1)

    Sinusoidal
    y = .5(1+cos(πx))

    Circular/elliptical
    y = sqrt(1-x^2)

    Parabolic
    y = 1-ax^2

    General polynomial
    y = ax + bx^2 + cx^3...

    Really went above and beyond with this reply. Thanks! I might go this route first, and just add "Custom curve" or something to the enum choices later. I think some kind of gaussian function is a good one too, so I'll hunt that equation down.
    Evan Reese
  • mahirmahir Member, Developers Posts: 1,307 ✭✭✭✭✭
    A custom equation option is another catch-all way to get what you want. You would have to accept an expression as input. Take a look at my Parametric Curve FS for details. Honestly, a lot of the dirty work was figured out by @ilya_baran back in the day, but it isn't too difficult to follow.
  • EvanReeseEvanReese Member, Mentor Posts: 2,135 ✭✭✭✭✭
    mahir said:
    A custom equation option is another catch-all way to get what you want. You would have to accept an expression as input. Take a look at my Parametric Curve FS for details. Honestly, a lot of the dirty work was figured out by @ilya_baran back in the day, but it isn't too difficult to follow.
    I might add something like that, but honestly, to me, this feature is not just about me being able to produce a certain result; it's about making this kind of patterning available to people who aren't comfortable with code and math, which is what I like about the custom sketch option, and some solid presets like sine, and gaussian.
    Evan Reese
  • S1monS1mon Member Posts: 2,986 PRO
    Interesting. I was starting to do some research on stuff like this. I haven't made any real progress, but these resources might be helpful:

    https://sighack.com/post/easing-functions-in-processing
    https://bitbucket.org/kluivers/jk-interpolation/src/master/JKInterpolationMath.m
  • EvanReeseEvanReese Member, Mentor Posts: 2,135 ✭✭✭✭✭
    S1mon said:
    Interesting. I was starting to do some research on stuff like this. I haven't made any real progress, but these resources might be helpful:

    https://sighack.com/post/easing-functions-in-processing
    https://bitbucket.org/kluivers/jk-interpolation/src/master/JKInterpolationMath.m
    wow! thanks for the timely links
    Evan Reese
Sign In or Register to comment.