Im trying to write a program which is computing surface area of a 3D geometry by using Newell Methods.
Geometry data should be reading from a text file. The lines which has 3 columns point out coordinates of geometry's vertices. The lines which has 2 columns point out connectivities of edges by vertices. And other lines point out loops compositons by edges. So The text file defines the geometry. When I change the file, the geometry will change e.x: cube, rectangular prism...

I can create arrays to use in formulas of Newell Methods and I can compute the area of geometry surface by writing the data in program as hardcode.Also I can make line read from text file.But I cant create arrays and store datas from reading text file. I need to combine those.

The program is in below and attached which can calculate by hard code. I need help this to compute the area by reading from text file. Thanks for all suggestions.

import javax.swing.*;
import java.util.*;

class surfaces_area
public static void main(String args[])
double edges[][][]={ 
//	  V1		   V2
	{{0.0,0.0,0.0},{5.0,0.0,0.0}},    // E1
//	  V2		   V3		
	{{5.0,0.0,0.0},{5.0,4.0,0.0}},    // E2
//	  V4		   V3		   
         {{0.0,4.0,0.0},{5.0,4.0,0.0}},    // E3
//	  V1		   V4
	{{0.0,0.0,0.0},{0.0,4.0,0.0}},    // E4
//	  V5		   V4
	{{0.0,4.0,3.0},{0.0,4.0,0.0}},    // E5
//	  V6	            V5
	{{5.0,4.0,3.0},{0.0,4.0,3.0}},    // E6
//	  V7	            V6
	{{5.0,0.0,3.0},{5.0,4.0,3.0}},    // E7
//	  V7		   V8
	{{5.0,0.0,3.0},{0.0,0.0,3.0}},    // E8
//	  V8		   V5
	{{0.0,0.0,3.0},{0.0,4.0,3.0}},    // E9
//	  V2		   V7	
	{{5.0,0.0,0.0},{5.0,0.0,3.0}},    // E10
//	  V8	            V1	
	{{0.0,0.0,3.0},{0.0,0.0,0.0}},    // E11
//         V3          	   V6	
	{{5.0,4.0,0.0},{5.0,4.0,3.0}},    // E12	

		double Nx=0;
	         int j=0;
	         int k;
	for (j=0;j<4;j++)
	    for (k=0;k<2;k++)
	if (k==1)
Nx = Nx+ 0.5*((edges[j][k][1]-edges[j][k+1][1])*(edges[j][k][2]+edges[j][k+1][2]));         //Newell Methods's Formula
System.out.println("sonuc = "+Nx);
//  I can compute  Ny and Nz as above. So total surface equals as


Are you looking for help with this program? If so could you explain in more detail what your problem is.

But I cant create arrays and store datas from reading text file

Can you explain this better?

Thanks for your interest. you find information about program how works.

you can find the formula, photo and commnent file in attach.

The text file :

#cordinates of vertices
0.0 0.0 0.0 (this line should define V[0][c] array)
5.0 0.0 0.0
5.0 4.0 0.0
0.0 4.0 0.0
0.0 4.0 3.0
5.0 4.0 3.0
5.0 0.0 3.0
0.0 0.0 3.0
. . . (this line should define V[n][c] array)

#Edges compositions
0 1 (this line should define E[0][m] array)
1 2 (this line should define E[1][m] array)
3 2
0 3
4 3
5 4
6 5
6 7
7 4
1 6
7 0
2 5
. .
. . (this line should define E[k][m] array)

# Loops compositions
7 8 -5 -6 (this line should define L[0][j] array)
9 6 -11 -1 (this line should define L[1][j] array)
8 4 -3 -10
-0 -10 -7 -9
2 11 5 4
. . . . . (this line should define L[j] array)

# Faces compositions

I wanna compute area and normals of surfaces of 3D geometry by using newell formula.
First I need the read datas of geometry from a text file. This datas should be read into arrays.
The program which I sent in below reads datas from hard codes. ( Which I wrote in "edges" array.) This array should be stored from text file.
For newell formula, The variables should be read from faces composition array. And It should be calculated for each surfaces and sum of all by using " nested for loops" .
the text file defines a rectangular prism.
For each surfaces I need to calculate newell formula. Serie's upper limit,m is number of surfaces. This serie will calculate in "for loop" ( i=0 ,i<6, i++). While "for loop" is calculating formula, it needs to y_i and z_i variables. The main point for me is begening here.
It should reach to y_i and z_i. they are compenents of vertices coordinates. For renctangular prism. Each surfaces has four edges. An edge has two vertices. A vertice has a coordinate( x,y and z compenent value)
I need to read x,y and z values connectivited eachother by edges and surfaces. And I made read these values in "nested for loops " by reading from hardcode(from line10 to line34) . But I need to read the values from text file in "nested for loops". Coz when I change the geometry ( when I create the new text file belong to different geometry) I can calculate the area of surfaces. By reading from text file , The upper limtits of series and loops will be independent.

The arrays in below should be read from edge compositions part in text file

To reach ‘y_i’ value of first surface,

• i=0. (i<number of loops, i++)
L[0][j]={7 8 -5 -6}
• j=0 ( j< size of each loop, j++)
L[0][0]=7=k this should be index of E(k) array. So it is E[7][m]={6,7}
• m=0 (m<2, m++)
E[7][0]=6=n this should be index of V(n). So it is V[6][c]={ 5.0 ,0.0 ,3.0}
V[6][c]={ 5.0 ,0.0 ,3.0}
• c=1 (n<3,n++)
V[6][1]=0.0 this should be ‘y’ component of the vertice’s coordinate . So it is value of ‘y_i’ variable in formula.( )

total area of surfaces :


Can you show the code you are having the problems with?
Your first post said:

I cant create arrays and store datas from reading text file

I have no idea what your program is supposed to do, but I might be able to help you read data from a file and store it in arrays in your code.

I sent the codes in attach by first message. And Im writng new one. I will send it again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.