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.

# Parametric Surface from f(x,y)

Member, Developers Posts: 1,205 ✭✭✭✭✭
edited August 2016
I'm trying to build upon the Parametric Curve FS to create a Parametric Surface. The intention is to be able to input a function Z = f(#x,#y) and have that create a lofted surface. However, I'm running into problems getting the z equation to accept 2 inputs (x,y). @ilya_baran, @kevin_o_toole_1, maybe one of you can take a look at my code to see where it's getting hosed? I tested the rest of the code, and it seems to work well. It's just the part where I try to calculate Z as a function of X/Y that isn't working too well. Thanks.

• Onshape Employees, Developers, HDM Posts: 551
edited August 2016
The error you're getting (Cannot call a function that takes 1 arguments with 2) is because z in an Expression, and Ilya defined Expressions to be functions of a single input.

Since you want functions of two inputs, great. You'll just need to change all the overloads defined to use two arguments like (x, y) instead of (t), everywhere in the file (the "all" button in the ctrl-f find dialog may help you )

Then x_ should be `function(x, y) { return x; }`, and y_ should be `function(x, y) { return y; }`

Perhaps you'll want to rename Expression to something less generic like BiExpression to better communicate that it won't work with other numbers of parameters.

• Onshape Employees, Developers, HDM Posts: 1,118
edited August 2016
My original thought for multiple variables was to have the input be say a 2 element array and x_ be function(t) { return t[0]; } which lets the original Expression type be kept.  But Kevin's approach should also work.
Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
• Onshape Employees, Developers, HDM Posts: 551
Ooh, yes. Ilya's approach is better. Do that instead
• Member, Developers Posts: 1,205 ✭✭✭✭✭
Thanks for the input, guys. I implemented @ilya_baran's array method, and it worked perfectly
• Member, Developers Posts: 1,205 ✭✭✭✭✭
On a related note, I'm having trouble with order of operations when overloading the unary (-) minus operator. Right now, -#x^2 is evaluated as (-#x)^2 instead of -(#x^2). Not a big deal, but most people would assume PEMDAS would be followed without extra parentheses.
• Member, Developers Posts: 1,205 ✭✭✭✭✭
I retract. After a little research I realized that unary operators take precedence exponentiation. Live and learn.
• Member, Developers Posts: 1,205 ✭✭✭✭✭
• Member, Developers Posts: 216 EDU
Nice! There's some ripples from the interpolation between profiles, but that can't be avoided.
Arul Suresh
PhD, Mechanical Engineering, Stanford University
• Member, Developers Posts: 1,205 ✭✭✭✭✭
Yeah, you can increase the number of curves, but the computation time scales as O(n^2). Good enough for now, I suppose.