MoI discussion forum
MoI discussion forum

Full Version: Nodebundle for playing with nodes

Show messages:  1-11  …  1372-1391  1392-1411  1412-1431  1432-1451  1452-1471  1472-1491  1492-1511  …  1852-1859

Thread Split: Some posts in this thread have been moved here

From: Frenchy Pilou (PILOU)
3 Apr 2019   [#1432]
That is missing is a little image for each script posted! ;)
not the script itself but the result!
From: Michael Gibson
3 Apr 2019   [#1433] In reply to [#1430]
Hi James,

re:
> Is there a script property that returns the center point of polygons (regular & nonregular)
> and ellipses, just as does “Center” Object Snap?

For an ellipse see the isEllipse and conicFrame properties listed above. You'd do something like:

 if ( crv.isEllipse )
 {
      var center = crv.conicFrame.origin;
      ...

For a polygon there is not any single property for that but it can be computed the same way MoI does by the centroid of the polygon vertices.

You'd do something like look at .isClosed and .isPlanar and if both of those are true get the curve segments by crv.getSubObjects() then go through all segments testing .isLine on each one, if all are lines go through them and add together all the segment start point coordinates and divide by the number of points to get the centroid.

- Michael
From: James (JFH)
4 Apr 2019   [#1434] In reply to [#1433]
Hi All,

Here's a macro for calculating centroid of polygons (reg & nonReg) & ellipses (incl circles),
based on Michael suggestion above. (thanks Michael, it seems so obvious now)

However, it is of limited use, because it is not multi-processing; which is to say,
that it could not be wired to a faceted surface; outputting the centroid of each individual facet.

For that a dedicated node is required.
Any takers?
James
https://www.instagram.com/nodeology/
From: bemfarmer
4 Apr 2019   [#1435] In reply to [#1434]
I'm missing extractPts node...
I'll have to check your (James') recent posts...
(or maybe it was recently moved...
- Brian
From: James (JFH)
4 Apr 2019   [#1436] In reply to [#1435]
Brian,

Try extension folder attached here:
http://moi3d.com/forum/index.php?webtag=MOI&msg=7777.1404

It is the most up-to-date.

James
From: bemfarmer
4 Apr 2019   [#1437] In reply to [#1436]
Thank you James. Extensions are now updated.
I'll take a look at doing a mutiprocess, but am quite busy now, with limited play time, so no promises :-)

- Brian
From: James (JFH)
4 Apr 2019   [#1438] In reply to [#1437]
Thanks Brian,
If you can, it would be greatly appreciated
Have a great weekend,
James
https://www.instagram.com/nodeology/
From: bemfarmer
5 Apr 2019   [#1439] In reply to [#1434]
Hi James,

After some thought, it seems that the Input objects to a centroid node need to be defined.
It is necessary to "parse" the Input object into Cases, which should be possible with multiple IF statements.

I do not think that a node multiprocess sub function is required, (?), just sequential processing of the input objects, with For loops.

So far the centroid is being sought for Circles, Ellipses, and Closed Planar polygons consisting of line edges.
I've re-read Wikipedia centroid topic, and the centroid also applies to a closed planar polygon with a circular hole in it.

A faceted surface, (possibly 3D), would be broken down into Faces, inside or outside of the node, and each face tested to see if a centroid applies.

What about wireframe objects? Maybe planarize them?

At present, the centroid only applies to planar objects, or planar faces of 3D objects.

Example objects: Cube, open cube, cuboid, tapered cuboid, tetrahedron, icosahedron, nonRegular solid with planar faces,
cylinder, rounded off tetrahedron with a circular faces, and edges rounded off...

A look at scripts which handle faces might be helpful.

- Brian

Wikipedia also describes centroids for regions bounded by two continuoiu functions. Are NURBS curves continous functions, that would qualify? (Integration required...)

Centroids of NURBS bounded areas are possible to calculate. There is one Chinese article, but it was not downloadable...
Maybe for MoI version 6, Michael will create a factory for centroids... :-)

This is another link:
https://www.intmath.com/applications-integration/5-centroid-area.php
http://web.mst.edu/~ide50-3/schedule/lessons/21_Centroids.pdf
From: speedy (AL2000)
5 Apr 2019   [#1440]
Hi James and Friends
I did this exercise, before loading the New Extensions
and in particular (extractPt ...) ;
but the result is similar to your ...
The real problem is that you can't get it to flow together
multiinput ... (Grasshopper with its branching, it could be
an inspiration to be able to reach this milestone in the future)

the file at this link:
http://www.mediafire.com/file/8d3b6uwm1a6455y/Baricenter_and_BBox_Center.zip/file
Have a nice Week-end to all
alberto
From: James (JFH)
5 Apr 2019   [#1441] In reply to [#1439]
Hi Brian,

>> centroid also applies to a closed planar polygon with a circular hole in it <<.

I think, for the sake of simplicity, we need only concern ourselves with planar, closed polygons.
We can disregard for now compound surfaces and even ellipses for that matter.

>> A faceted surface, (possibly 3D), would be broken down into Faces, inside or outside of the node, and each face tested to see if a centroid applies. <<.

Again for simplicity, we need only concern ourselves with faces i.e. "broken down ....outside of the node"

In this way node need only be limited to Michael's second case steps
http://moi3d.com/forum/index.php?webtag=MOI&msg=7777.1433

>> You'd do something like look at .isClosed and .isPlanar and if both of those are true get the curve segments by crv.getSubObjects() then go through all segments testing .isLine on each one, <<

So we now know that all faces are indeed polygons, then

>> if all are lines go through them and add together all the segment start point coordinates and divide by the number of points to get the centroid. <<

>>I do not think that a node multiprocess sub function is required, (?), just sequential processing of the input objects, with For loops.<<.

If a for loop satisfies the requirement of determining the centroid of multiple faces, all the better.

Thanks for looking at this
Have a great weekend
James
From: Michael Gibson
5 Apr 2019   [#1442] In reply to [#1441]
Hi James & Brian - in James' post here: http://moi3d.com/forum/index.php?webtag=MOI&msg=7777.1428 it looked like you were asking about polygon curve objects. Polygon surface objects would be a little different, currently there aren't properties like .isPlanar exposed for surfaces like there are for curves.

- Michael
From: James (JFH)
5 Apr 2019   [#1443] In reply to [#1442]
Michael,

Would the additional step of getEdges (or getJoinedEdges ) method at the start, applied to input faces resolve this?

James
From: Michael Gibson
5 Apr 2019   [#1444] In reply to [#1443]
Hi James,

re:
> Would the additional step of getEdges (or getJoinedEdges ) method at the start, applied to input faces resolve this?

It will work for getting the centroid of a face that you already know is planar but it won't work for determining if a face is planar or not. It is possible to have a face where the surface is not planar even though all its edge curves are on one plane.

The edge curves of a face are not necessarily ordered start to end like the segments of a curve are, so you'd need to gather the points a little differently. Probably the easiest is to accumulate both the start and the end point of each curve.

- Michael
From: Michael Gibson
6 Apr 2019   [#1445] In reply to [#1443]
Hi James, for the next v4 beta I've added in some new script properties and functions for faces that should help with this. There will be an .isPlanar property for faces then and also support for evaluating points, normals and derivatives on faces.

- Michael
From: James (JFH)
6 Apr 2019   [#1446] In reply to [#1445]
Hi Michael,

Was this always on the cards, or is it in response to my enquiries regarding face centroids?
If it is the latter, I don't know what to say.....but thank you.

Well, either way
thank you.

James
https://www.instagram.com/nodeology/
From: Michael Gibson
6 Apr 2019   [#1447] In reply to [#1446]
Hi James, well it's been something I've been planning on adding for some time now but your particular request about it bumped it up!

One thing that tends to make me hesitate in this area is that once script interfaces are added it becomes pretty difficult to change them since there gets to be various things depending on it. So if I mess it up it's something that easily stays messed up for kind of a long time... But here the equivalent is already in there for curves so I can follow the same structure for faces too.

- Michael
From: bemfarmer
6 Apr 2019   [#1448]
It is a rain day, so from 6:30 AM to 8 AM, some initial centroid work was done.
A break is now required, so here is some non-functional code :-)

The task is so easy to understand, yet so hard for this slow amateur programmer to code... :-)

The non functional draft node can be copied to the nodeeditor extension folder, to add it to the construct2 menu.
The node may then be selected from the construct2 menu, and the node is displayed, but does not function further.

- Brian

Bogging down again, so 2nd break...got to go do some work...
From: bemfarmer
7 Apr 2019   [#1449] In reply to [#1448]
Draft3, non functional, but getting closer
(completely untested)

Using both start and end points of each subobject, so length *= 2.
Planar poly, but with z coordinates, needs zsum/(length*2)

- Brian
From: bemfarmer
7 Apr 2019   [#1450] In reply to [#1449]
Draft4, a little progress made, but node is still broken.
From: bemfarmer
8 Apr 2019   [#1451] In reply to [#1450]
Alert messages were added to see what is going on, or not going on.
I left off the () for getStartPt()...
 
- Brian

Show messages:  1-11  …  1372-1391  1392-1411  1412-1431  1432-1451  1452-1471  1472-1491  1492-1511  …  1852-1859