Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6598547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:21:51+00:00 2026-05-25T18:21:51+00:00

I am interfacing an external program with Mathematica. I am creating an input file

  • 0

I am interfacing an external program with Mathematica. I am creating an input file for the external program. Its about converting geometry data from a Mathematica generated graphics into a predefined format. Here is an example Geometry.

Figure 1

Figure 1

The geometry can be described in many ways in Mathematica. One laborious way is the following.

dat={{1.,-1.,0.},{0.,-1.,0.5},{0.,-1.,-0.5},{1.,-0.3333,0.},{0.,-0.3333,0.5},
{0.,-0.3333,-0.5},{1.,0.3333,0.},{0.,0.3333,0.5},{0.,0.3333,-0.5},{1.,1.,0.},
{0.,1.,0.5},{0.,1.,-0.5},{10.,-1.,0.},{10.,-0.3333,0.},{10.,0.3333,0.},{10.,1.,0.}};

Show[ListPointPlot3D[dat,PlotStyle->{{Red,PointSize[Large]}}],Graphics3D[{Opacity[.8],
Cyan,GraphicsComplex[dat,Polygon[{{1,2,5,4},{1,3,6,4},{2,3,6,5},{4,5,8,7},{4,6,9,7},
{5,6,9,8},{7,8,11,10},{7,9,12,10},{8,9,12,11},{1,2,3},{10,12,11},{1,4,14,13},
{4,7,15,14},{7,10,16,15}}]]}],AspectRatio->GoldenRatio]

This generates the required 3D geometry in GraphicsComplex format of MMA.
enter image description here

This geometry is described as the following input file for my external program.

# GEOMETRY
# x y z [m]
NODES 16
1. -1. 0.
0. -1. 0.5
0. -1. -0.5
1. -0.3333 0.
0. -0.3333 0.50. -0.3333 -0.5
1. 0.3333 0.
0. 0.3333 0.5
0. 0.3333 -0.5
1. 1. 0.
0. 1. 0.5
0. 1. -0.5
10. -1. 0.
10. -0.3333 0.
10. 0.3333 0.
10. 1. -0.
# type node_id1 node_id2 node_id3 node_id4  elem_id1 elem_id2 elem_id3 elem_id4
PANELS 14
1 1 4 5 2 4 2 10 0
1 2 5 6 3 1 5 3 10
1 3 6 4 1 2 6 10 0
1 4 7 8 5 7 5 1 0
1 5 8 9 6 4 8 6 2
1 6 9 7 4 5 9 3 0
1 7 10 11 8 8 4 11 0
1 8 11 12 9 7 9 5 11
1 9 12 10 7 8 6 11 0
2 1 2 3 1 2 3
2 10 12 11 9 8 7
10 4 1 13 14 1 3
10 7 4 14 15 4 6
10 10 7 15 16 7 9
# end of input file

Now the description I have from the documentation of this external program is pretty short. I am quoting it here.


  1. First keyword NODES states total number of
    nodes. After this line there should be no comment or empty lines. Next lines consist of
    three values x, y and z node coordinates and number of lines must be the same as number
    of nodes.
  2. Next keyword is PANEL and states how many panels we have. After that we have lines
    defining each panel. First integer defines panel type
  3. ID 1 – quadrilateral panel – is defined by four nodes and four neighboring panels.
    Neighboring panels are panels that share same sides (pair of nodes) and is needed for
    velocity and pressure calculation (methods 1 and 2). Missing neighbors (for example for
    panels near the trailing edge) are filled with value 0 (see Figure 1).
  4. ID 2 – triangular panel – is defined by three nodes and three neighboring panels.
  5. ID 10 – wake panel – is quadrilateral panel defined with four nodes and with two
    (neighboring) panels which are located on the trailing edge (panels to which wake panel is
    applying Kutta condition).
  6. Panel types 1 and 2 must be defined before type 10 in input file.
    Important to notice is the surface normal; order of nodes defining panels should be
    counter clockwise. By the right-hand rule if fingers are bended to follow numbering,
    thumb will show normal vector that should point “outwards” geometry.

Challenge!!

We are given with a 3D CAD model in a file called One.obj and it is exported fine in MMA.

cd = Import["One.obj"]

The output is a MMA Graphics3D object
enter image description here

Now I can get easily access the geometry data as MMA internally reads them.

{ver1, pol1} = cd[[1]][[2]] /. GraphicsComplex -> List;
MyPol = pol1 // First // First;
Graphics3D[GraphicsComplex[ver1,MyPol],Axes-> True]

enter image description here

  1. How we can use the vertices and polygon information contained in ver1 and pol1 and write them in a text file as described in the input file example above. In this case we will only have ID2 type (triangular) panels.
  2. Using the Mathematica triangulation how to find the surface area of this 3D object. Is there any inbuilt function that can compute surface area in MMA?
  3. No need to create the wake panel or ID10 type elements right now. A input file with only triangular elements will be fine.

Sorry for such a long post but its a puzzle that I am trying to solve for a long time. Hope some of you expert may have the right insight to crack it.

BR

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:21:52+00:00Added an answer on May 25, 2026 at 6:21 pm

    Q1 and Q2 are easy enough that you could drop the “challenge” labels in your question. Q3 could use some clarification.

    Q1

    edges = cd[[1, 2, 1]];
    
    polygons = cd[[1, 2, 2, 1, 1, 1]];
    

    Update Q1

    The main problem is to find the neighbor of each polygon. The following does this:

    (* Split every triangle in 3 edges, with nodes in each edge sorted *)
    triangleEdges = (Sort /@ Subsets[#, {2}]) & /@ polygons;
    
    (* Generate a list of edges *)
    singleEdges = Union[Flatten[triangleEdges, 1]];
    
    (* Define a function which, given an edge (node number list), returns the bordering  *)
    (* triangle numbers. It's done by working through each of the triangles' edges       *)
    ClearAll[edgesNeighbors]
    edgesNeighbors[_] = {};
    MapIndexed[(
       edgesNeighbors[#1[[1]]] = Flatten[{edgesNeighbors[#1[[1]]], #2[[1]]}];
       edgesNeighbors[#1[[2]]] = Flatten[{edgesNeighbors[#1[[2]]], #2[[1]]}];
       edgesNeighbors[#1[[3]]] = Flatten[{edgesNeighbors[#1[[3]]], #2[[1]]}];
       ) &, triangleEdges
    ];
    
    (* Build a triangle relation table. Each '1' indicates a triangle relation *)
    relations = ConstantArray[0, {triangleEdges // Length, triangleEdges // Length}];
    Scan[
      (n = edgesNeighbors[##]; 
         If[Length[n] == 2, 
            {n1, n2} = n; 
            relations[[n1, n2]] = 1;  relations[[n2, n1]] = 1];
       ) &, singleEdges
    ]
    
    MatrixPlot[relations]
    

    triangle relationships

    (* Build a neighborhood list *)
    triangleNeigbours = 
        Table[Flatten[Position[relations[[i]], 1]], {i,triangleEdges // Length}];
    
    (* Test: Which triangles border on triangle number 1? *)
    triangleNeigbours[[1]]
    
    (* ==> {32, 61, 83} *)
    
    (* Check this *)
    polygons[[{1, 32, 61, 83}]]
    
    (* ==> {{1, 2, 3}, {3, 2, 52}, {1, 3, 50}, {19, 2, 1}} *)
    (* Indeed, they all share an edge with #1 *)
    

    You can use the low level output functions described here to output these. I’ll leave the details to you (that’s my challenge to you).

    Q2
    The area of the wing is the summed area of the individual polygons. The individual areas can be calculated as follows:

    ClearAll[polygonArea];
    polygonArea[pts_List] :=
     Module[{dtpts = Append[pts, pts[[1]]]},
       If[Length[pts] < 3, 
          0, 
          1/2 Sum[Det[{dtpts[[i]], dtpts[[i + 1]]}], {i, 1, Length[dtpts] - 1}]
       ]
     ]
    

    based on this Mathworld page.

    The area is signed BTW, so you may want to use Abs.

    CORRECTION
    The above area function is only usable for general polygons in 2D. For the area of a triangle in 3D the following can be used:

    ClearAll[polygonArea];
    polygonArea[pts_List?(Length[#] == 3 &)] := 
        Norm[Cross[pts[[2]] - pts[[1]], pts[[3]] - pts[[1]]]]/2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am interfacing with an external device which is sending data in hex format.
There are many types of external dependencies. Interfacing with external applications, components or services
I am interfacing with a server that requires that data sent to it is
In our current project we are interfacing with a third party data provider. They
I'm writing tests that check that an external service is providing inventory data (on
I am writing a program in OpenGL and I need some sort of interfacing
Anyone has experiences about interfacing with multimedia [or Fn Function] keys in Java? There
I am looking at ways of interfacing to specific hardware I/O addresses from various
I am creating a ajax utility for interfacing with my server methods. I would
I'm interfacing with an application that's sending a raw printer file to the default

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.