Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inputting surface/spline functions? (SW 2007) 2

Status
Not open for further replies.

Nabla1

Electrical
Dec 26, 2007
32
0
0
GB
I have recently acquired access to Solidworks 2007, and through a growing interest in fluid dynamics, I have realized that in aerospace engineering it can often be necessary to design fairly complex 3D surfaces, for example in designing airfoils and compressor blades.

CFD aside, suppose I were to crunch some numbers, and arrive at a mathematical function, f(x,y), describing a surface in 3D space. This surface would have been derived to be the most optimal surface to use for a compressor blade, under a certain set of fluid flow conditions.

Is it possible to input such mathematical functions into Solidworks (specifying the range of the function) to produce certain 'function-specific' surfaces or splines, for use with construction?

e.g. something like f(x,y) = sinx cosy (0<x<5,0<y<3), specifying a temporary axis, which the inequalities would refer to.

Thank you.
 
Replies continue below

Recommended for you

"you won't always be using a simple rotationally symmetrical surface. For a more generalized case, you can create cross-sections at various plane offsets by plugging in different constants for X & Y that correspond to the cutting plane. For example,"

This is what I meant by a 'level set' of profiles. I understand setting a dimension (eg. X) constant to set a plane at that particular constant, and I'm also familiar with the form z=Ax^2+By^2 for an asymmetric paraboloid. Having opened up your surface, I can understand the setting of x, or y to equidistant constants, but the thing I don't understand is how you have use a parameterization with T in each curve. It seems to be done in such a way, that the set of 2D parabolas in one dimension, follow the set of parabolas in the other direction. Could you please elaborate on the functions you used? Thanks
 
T is just a parameter that goes from 0 to 1 in increments of 1/(#Points - 1). so setting Y = A*%T just means I want Y to go from 0 to A. You don't have to use T in every equation, but it needs to be in at least one of them in order to give the macro a range of values it iterate over.

For example,
X = f(T) = f1(T)
Y = g(X) = g(f(T)) = f2(T)
Z = h(X,Y) = h(f1(T),f2(T)) = f3(T)

It all comes back to T in the end. T gives you the flexibility to have XYZ move independently of each other, but you can easily make them dependent, as shown in this example.
 
I think I understand your question now about the curves "following" each other. The parabolas intersect each other because the the equation for Z is the same between curves. It was always Z = 2*%X^2 + %Y^2. The different parabolas were generated by varying X & Y only. In one direction, Y = %T - .5, but I used X = -.5, -.25, 0, .25, .5. Similarly, in the other direction I set X = %T - .5 and Y = .5, .25, 0, -.25, -.5. That's how I created the grid of of parabolic cross-sections.
 
"I think I understand your question now about the curves "following" each other. The parabolas intersect each other because the the equation for Z is the same between curves. It was always Z = 2*%X^2 + %Y^2. The different parabolas were generated by varying X & Y only. In one direction, Y = %T - .5, but I used X = -.5, -.25, 0, .25, .5. Similarly, in the other direction I set X = %T - .5 and Y = .5, .25, 0, -.25, -.5. That's how I created the grid of of parabolic cross-sections."

Ah, of course that really is incredibly helpful! So the 'X-set' of curves is just the surface function where the X-planes cross it (each at some constant value of X), and the 'Y-set' of curves is where the Y-planes cross the surface, when Y is set at some constant value. Thanks alot for the macro and the help...I can now do what I originally set out to do, without the added hassle of creating extra planes etc.

As for the bounds, A will set the upper bound, because when %T=1, A*%T = A?

So basically the process is:

Create 2 adjacent sets of planar profiles
For each curve:
-Set one variable constant (value of planar position)
-Set another to A*%T, to set the upper bound (and hence the domain where the function is evaluated)
-Set the final variable equal to the surface function, in terms of the other two variables.

Now would I be right in saying that it wouldn't matter what the surface function was, the above method will still work (providing smoothness?)? And that it doesn't matter which variable X, Y, or Z is assigned which step above, so long as no two are given the same step?...It seems reasonable that it should still work, but maybe I'm missing something?

Cheers!




 
Actually a couple more questions too:

How can I set a lower bound for the function to be evaluated on? e.g. If I wanted a function evaluated between -5 and 5?

How can I get a shortcut button for the macro?

I inputted:

X=0
Y= (6*PI)*%T
Z=cos(%X)*cos(%Y)

...to evaluate z=cos(x)cos(y) on the plane x=0, between 0 and 6PI (3 repeats), and it didn't work. I got the message, "please correct the errors in Y". Is there something worng with my entering of PI? Can't this be entered as a known constant, or does it have to be entered manually? e.g. 3.14...?

Thanks
 
Nabla,
I'm glad you've got it working. Here are the answers to your questions.

Now would I be right in saying that it wouldn't matter what the surface function was, the above method will still work (providing smoothness?)?
Yes, as long as it is a well posed surface equation that can be evaluated by Excel as a function of the other two coordinates and T, it should work.

And that it doesn't matter which variable X, Y, or Z is assigned which step above, so long as no two are given the same step?
Yes, you can mix and match XYZ (or RThZ, RThPh).

How can I set a lower bound for the function to be evaluated on? e.g. If I wanted a function evaluated between -5 and 5?
Instead of using A*%T, use A*(%T-.5). I mentioned earlier in the thread that this yields a range of -A/2 to +A/2.

How can I get a shortcut button for the macro?
-With any file open, go to Tools>Customize.
-In the Commands tab, select Macros.
-Drag the New Macro button to any toolbar (it looks like a guy with a green shirt).
-Right-click the button you just placed.
-In the window that comes up, proceed to fill in Tooltip (macro name), Macro (location of the macro), Method (FuncPlot1.main).
-If you want a shortcut key, enter that as well. Also, any reasonably sized bitmap can be used as the button image.
-Click OK and you're done.

If you want a keyboard shortcut, but without a button:
-First, the SWP file must be in a directory identified in the system options as being a macro folder. To do this go to Tools>Options, System Options tab, File Locations page, Macros dropdown selection. Then add whatever location you want to use for macros. The default is C:\Program Files\SolidWorks\macros, but you can use any local or network location.
-Restart SW so it detects the macros the directory specified in the previous step.
-With any file open, go to Tools>Customize.
-Go to the Keyboard tab.
-Under the Macros heading you should see the macro name available to assign a shortcut.

Is there something worng with my entering of PI?
Actually, yes. Remember, the macro uses Excel for it's calculation engine. In Excel, Pi is treated like a function with no input parameters. You must use the syntax PI(). No parentheses, no go.


I hope this helps:)
 
Thanks again. So with PI all I'm missing is the parentheses then.

Got the shortcuts running, thanks for that.

"Instead of using A*%T, use A*(%T-.5). I mentioned earlier in the thread that this yields a range of -A/2 to +A/2."

Ok, thats simple enough. Any remedy for evaluating across something like -3, and 5, or 4 and 10?

For 4 and 10, maybe:

4+6*(%T) ?

and for -3 and 5, maybe:

-3+8*(%T) ?

That should work I think.

Also, I had a suggestion for you. After using the macro a little, I realized that the process could be quicker still if you could input:

1.) A set of constants B1, B2, B3... where each B sets the position of some plane. For example, instead of X=B, have X={B1,B2,B3...}. Basically, so you can create a set of planes/curves in one go, meaning you could do it once for X, once for Y, then create a boundary layer.

OR (for the same purpose)

2.) Set an upper and lower bound (for where you want the first plane to start, and the last to end), and tell it the number of planes you want to create, within those bounds. (Of course in this case, the planes would be equidistant).

I can't say I'm experienced with making API's, but from what programming I have done, I can't see it being that much harder to add these in. Of course, I'll let you be the judge of that, but I would love to see these functions added in. What d'ya reckon?

Cheers!
 
Nabla,
Glad I could help

Any remedy for evaluating across something like -3, and 5, or 4 and 10?
Yes, what you have there should work fine. As a Generalization, your range should be set to A + (B-A)*%T, where A is the minimum value in your range, and B is the maximum.

The ability to input a set of constants B1, B2, B3 or an upper and lower bound
This is definitely possible, but it isn't a trivial feature to add. Currently the macro depends completely on Excel for parsing the equation strings. To do what you're asking would require that the macro detect when to override Excel's handling of equations, and parse certain types equation inputs differently. Either that or all the calculation must be enclosed in an additional loop that iterates over the various constants. To be honest, I probably would not put that much effort into it unless I was either being paid to do it, or it would save me a lot of time in my work. Since neither of those is true, the macro will likely stay the way it is. However, feel free to make modifications yourself, as long as I'm given credit for the original macro:)

when I have created a surface, or a set of surfaces/boundaries, then how can I make it into a solid?
I'm not a surfacing expert, but here are two of the simpler methods with which I'm familiar.

Insert>Boss/Base>Thicken
This will create a thick skinned version of your surface.

Insert>Surface>Knit
To do this you have to to create a closed volume using another surface. After trimming the extra portions of each surface, Knit will then attempt to merge the separate surfaces into a single solid body.

I've attached an example that creates a solid from an asymmetrical paraboloid surface and a flat surface. It also has a suppressed Thicken feature to show you the result of using that method as well.


Good luck
 
 http://files.engineering.com/getfile.aspx?folder=18b34dd8-bfde-4ae6-ab3a-dad9687ead2c&file=Asymmetrical_Paraboloid.SLDPRT
Although I said I wouldn't be adding to my macro the ability to plot multiple curve sets, I ended up doing it anyway for fun. I also added surface creation. Below are the two macros - FuncPlot creates 3D curves, SurfPlot creates 3D surfaces or curve sets/grids. Currently, implicit functions (f(x,y,z)=0) are not supported. Also, the surfaces and curves must be something producible in SW. Curves can't intersect themselves, and surfaces must be something constructable via boundary surface. The concept of using Excel for calculation was gleaned from Matt Lombard's eqcurve macro. I hope somebody finds these useful or at least educational.

 
Status
Not open for further replies.
Back
Top