Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- 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.
Simple Question
billy2
Member, OS Professional, Mentor, Developers, User Group Leader Posts: 2,068 PRO
I figured geometry.fs would include a math library with sin() or cos(). Do I have to load an additional library?
FeatureScript 275;
FeatureScript 275;
import(path : "onshape/std/geometry.fs", version : "275.0");
//import(path : "onshape/std/units.fs", version : "275.0");
annotation { "Feature Type Name" : "Cylinders" }
export const myFeature = defineFeature(function(context is Context, id is Id, definition is map)
precondition
{
// Define the parameters of the function definition
annotation { "Name" : "Radius" }
isLength(definition.radius, LENGTH_BOUNDS);
annotation { "Name" : "Length" }
isLength(definition.length, LENGTH_BOUNDS);
}
{
// Define the function's action
const DEBUG = false;
if ( DEBUG ){
debug(context,"Test DEBUG");
}
var i = 1;
var j = 1;
var n = 4;
var pi = 4 * atan(1);
var ang= 360 / n;
//ang = 360 / 2 / pi / n;
for (var cnt = 1; cnt <= n; cnt += 1)
{
i=sin(ang*cnt);
j=cos(ang*cnt);
fCylinder(context, id + "cylinder" + cnt, {
"bottomCenter" : vector(-1*i, -1*j, 0) * definition.length,
"topCenter" : vector(1*i, 1*j, 0) * definition.length,
"radius" : definition.radius
});
}
}, { /* default parameters */ });
0
Comments
You can create a ValueWithUnits by multiplying by any unit. In your code you can either set ang to
360 * degree / n
, or to2 * PI * radian / n
(where PI is a constant set in math.fs). These will both behave identically.Importing the units module separately isn't necessary, since (essentially) all of the standard library is imported automatically when you import geometry.fs.