Message Boards Message Boards

0
|
6440 Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Applying a Function to a Matrix/List?

Posted 8 years ago

Hello,

I want to calculate the centroids of a quadrilateral moving in space using

RegionCentroid[Polygon[{{p1x,p1y,p1z,},{p2x,p2y,p2z,},{p3x,p3y,p3z,},{p4x,p4y,p4z,}}]

p1...p4 are the corners of the quadrilateral. The coordinates are given in a excel spreadsheet with p1x p1y ... p4z in the columns. every row gives the coordinate at a different moment. Has someone an advice how to apply this RegionCentroid function to the spreadsheet giving me the list of the centroids at the different moments.

I hope you can help me :)

POSTED BY: Mr Pink
2 Replies
Posted 8 years ago

Thank your very much for this answer! Your code fixed my issue :). I am going to learn this partition, and # @ stuff!

Grateful Greetings!

POSTED BY: Mr Pink
Posted 8 years ago

First import:

data = Import["myfile.xls"]

where the table in each Excel file sheet becomes a matrix in data's outermost list.

Then slice and feed:

RegionCentroid[Polygon[Partition[#, 3]]] & /@ First[data]

where I assumed that your data of interest is on the first sheet. $Partition[#, 3]&$ slices lists into chunks of length 3. You may want to read up on anonymous aka pure functions for the '#' and '&' in this and on Map (short notation /@ ).

Hope this helps, Peter

POSTED BY: Peter Fleck
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract