I have an input data from Upstream calculation. A punch of triangles not arranged in a sequence. Well I would like to divide them into different regions using x-axis values.

Assume triangle vertex (v1, v2, v3) for which i have v1 (x1, y1, z1) likewise for other triangles too.

I want to categorise them into three regions

for (int i=1; i<=Numberoftriagles, i++)

{

// some calculation with triangles vertex

while (x1<L1){

cout<< triangle << "1";

}

while (L1<x1<L2){

cout<< triangle << "2";

}

while (x1>L2){

cout<< triangle << "3";

}

}

Here my difficult is, I need to write two text file, which i couldn't do it yet

The text file should look like !

File1.txt File2.txt

triangle 1

triangle 1

triangle 1

triangle 1

triangle 2

triangle 2

triangle 2

triangle 3

triangle 3

.....

....

....

The numbers in text file2 should be correspondent for triangles in File1. Imagine the input is random.

Any help?

With Regards

Game

Assume triangle vertex (v1, v2, v3) for which i have v1 (x1, y1, z1) likewise for other triangles too.

I want to categorise them into three regions

for (int i=1; i<=Numberoftriagles, i++)

{

// some calculation with triangles vertex

while (x1<L1){

cout<< triangle << "1";

}

while (L1<x1<L2){

cout<< triangle << "2";

}

while (x1>L2){

cout<< triangle << "3";

}

}

Here my difficult is, I need to write two text file, which i couldn't do it yet

The text file should look like !

File1.txt File2.txt

triangle 1

triangle 1

triangle 1

triangle 1

triangle 2

triangle 2

triangle 2

triangle 3

triangle 3

.....

....

....

The numbers in text file2 should be correspondent for triangles in File1. Imagine the input is random.

Any help?

With Regards

Game

no idea what you want to do, but here is a tutorial on how to read/write to files

http://www.cplusplus.com/doc/tutorial/files/

http://www.cplusplus.com/doc/tutorial/files/

Thanks Darkmaster!

That is okey, i can write text file. But i have to write it in explained way.

Please help, i attacked!

With Best Regards

Game

i dont understand your problem

can you maybe give an example or copy paste the task?

can you maybe give an example or copy paste the task?

Okey well,

First i have multiple surfaces! I triangulate this surfaces into triangles and then from triangles, i extracted the three vertices. Then i used this verticies to calculate normal and want to export to text file. The text file should be two (one: for triangle normals and second: for range label). Well the code is very large starting from beginning and i used some other libraries also.

But my specific problem is to write the two text files!

Here i will explain it by example!

say i have many triangles of an object, i want to write their normal and corresponding label (which shows the region based on x-value of the triangle)

Now the code should look like as follow!

for (int i=1; i<=Numberoftriagles, i++)

{

// calculation of normal

while (x1<L1){

out1<< trianglenormal ;

out2<< "1";

}

while (L1<x1<L2){

out1<< trianglenormal;

out2 << "2";

}

while (x1>L2){

out1<< trianglenormal;

out2 << "3";

}

}

I tried the above code! It works! I could create two separate text files which is not organized

For example

out1.txt

trianglenormal1

trianglenormal2

trianglenormal2

trianglenormal1

trianglenormal2

trianglenormal1

.

.

.

out2,txt

1

2

2

1

2

1

But I want an output which should look like!

out1.txt

trianglenormal1

trianglenormal1

trianglenormal1

trianglenormal2

trianglenormal2

trianglenormal2

.

.

.

out2,txt

1

1

1

2

2

2

Which should be arranged in ascending order.

Hope i make it clear now

Regards

you can either sort the output before you write to the files or you need to use stream pointers to tell where to write and flages to tell don't overwrite the already existing data.

to make that pointer/flag stuff clear:

lets say you have

and you want to add "1".

get the pointer after the "1"s, where the "2"s start, and set the flag, so the "2"s don't get overwritten.

to make that pointer/flag stuff clear:

lets say you have

1 1 2 2 |

and you want to add "1".

get the pointer after the "1"s, where the "2"s start, and set the flag, so the "2"s don't get overwritten.

Last edited on

Topic archived. No new replies allowed.