Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.

Randomized Hexagon Using Model Methods ?

Please login with a confirmed email address before reporting spam

Hi, friends

There is a simple code for generating randomized spheres using model methods:

//************************************************ model.component("comp1").geom("geom1").create("sph"+ind, "Sphere"); model.component("comp1").geom("geom1").feature("sph"+ind).set("r", hr); model.component("comp1").geom("geom1").feature("sph"+ind).set("pos", new double[]{hx, hy, hz}); //************************************************* Ref: https://www.comsol.asia/blogs/how-to-create-a-randomized-geometry-using-model-methods/

In a 2D model, I simply modified "Sphere" to "Circle", but what about regular hexagon ?


3 Replies Last Post 17 ott 2017, 17:27 GMT-4
Jeff Hiller COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 6 years ago 17 ott 2017, 14:17 GMT-4
Updated: 6 years ago 17 ott 2017, 14:18 GMT-4

The simplest was to create a regular hexagon is to use the Polygon tool and to take advantage of the "range" operator and the "cos" and "sin" functions, as shown in the attached file, which also shows the corresponding model method. From there you just need to add the randomness (i.e. scaling, rotation, center location).

Best,

Jeff

-------------------
Jeff Hiller
The simplest was to create a regular hexagon is to use the Polygon tool and to take advantage of the "range" operator and the "cos" and "sin" functions, as shown in the attached file, which also shows the corresponding model method. From there you just need to add the randomness (i.e. scaling, rotation, center location). Best, Jeff


Please login with a confirmed email address before reporting spam

Posted: 6 years ago 17 ott 2017, 16:21 GMT-4

Dear Jeff,

Thanks a lot for your quick reply. I successfully created a polygon (pol1) and scaled it (sca1), But the code:

** model.component("comp1").geom("geom1").create("pol"+ind, "sca1") ** leads to error. How can I add randomness in center location ?

Dear Jeff, Thanks a lot for your quick reply. I successfully created a polygon (pol1) and scaled it (sca1), But the code: ** model.component("comp1").geom("geom1").create("pol"+ind, "sca1") ** leads to error. How can I add randomness in center location ?

Jeff Hiller COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 6 years ago 17 ott 2017, 17:27 GMT-4

You can change the location of the center of the polygon by modifying the expressions used for the x and y coordinates of its vertices.

It should be pretty straightforward but if you should need further assistance, please contact COMSOL's technical support team at support@comsol.com .

Best regards,

Jeff

-------------------
Jeff Hiller
You can change the location of the center of the polygon by modifying the expressions used for the x and y coordinates of its vertices. It should be pretty straightforward but if you should need further assistance, please contact COMSOL's technical support team at support@comsol.com . Best regards, Jeff

Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.