Nodebundle for playing with nodes
 1-11  …  1392-1411  1412-1431  1432-1451  1452-1471  1472-1491  …  1852-1859
Thread Split: Some posts in this thread have been moved here

Previous
Next
 From:  Frenchy Pilou (PILOU)
7777.1432 
That is missing is a little image for each script posted! ;)
not the script itself but the result!
---
Pilou
Is beautiful that please without concept!
My Moi French Site My Gallery My MagicaVoxel Gallery
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
7777.1433 In reply to 7777.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
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  James (JFH)
7777.1434 In reply to 7777.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/

EDITED: 14 May 2019 by JFH

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
7777.1435 In reply to 7777.1434 
I'm missing extractPts node...
I'll have to check your (James') recent posts...
(or maybe it was recently moved...
- Brian
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  James (JFH)
7777.1436 In reply to 7777.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
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
7777.1437 In reply to 7777.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
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  James (JFH)
7777.1438 In reply to 7777.1437 
Thanks Brian,
If you can, it would be greatly appreciated
Have a great weekend,
James
https://www.instagram.com/nodeology/

EDITED: 4 Apr 2019 by JFH

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
7777.1439 In reply to 7777.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

EDITED: 5 Apr 2019 by BEMFARMER

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  speedy (AL2000)
7777.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
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  James (JFH)
7777.1441 In reply to 7777.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
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
7777.1442 In reply to 7777.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
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  James (JFH)
7777.1443 In reply to 7777.1442 
Michael,

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

James

EDITED: 5 Apr 2019 by JFH

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
7777.1444 In reply to 7777.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
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
7777.1445 In reply to 7777.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
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  James (JFH)
7777.1446 In reply to 7777.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/
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
7777.1447 In reply to 7777.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
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
7777.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...

EDITED: 7 Apr 2019 by BEMFARMER

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
7777.1449 In reply to 7777.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

EDITED: 7 Apr 2019 by BEMFARMER

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
7777.1450 In reply to 7777.1449 
Draft4, a little progress made, but node is still broken.

EDITED: 8 Apr 2019 by BEMFARMER

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
7777.1451 In reply to 7777.1450 
Alert messages were added to see what is going on, or not going on.
I left off the () for getStartPt()...
 
- Brian

EDITED: 8 Apr 2019 by BEMFARMER

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged
 

Reply to All Reply to All

 

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