Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FORTRAN check particle distance to centre of an object.

Status
Not open for further replies.

Kututo

Materials
May 29, 2014
5
0
0
GB
Hi,

I am quite new to FORTRAN and am currently making programs to gain an understanding of it.

I have made a program in FORTRAN 90, this spawns particles in which then land on a plane. What I would like to do is to check to see if any of the particles are within any cylinders in a line. If they are then I would like to keep them, if not then I would like them to be deleted.

I have thought about how this could be achieved. I have the centre points of the cylinder and the radius (ie. xyz for centre of the top and xyz for centre of the bottom, and a radius value). I thought that the centre of the particle with the radius could be compared with each co-ordinate of the centre point through the cylinder, and then to see if it is within the radius of that point, thus within the cylinder.

Please could you point me in the direction of a tutorial which teaches how to code this, or give me some guidance of how I can achieve this?

Thank you for your time, I really appreciate it.
 
Replies continue below

Recommended for you

Sorry to post on the thread I made before other people have posted. I have worked out mostly what I need to do.

I have 3 co-ordinates for the top and base of the cylinder, such that the base is 1.00, 1.00, 1.00 and the top is 1.00, 3.00, 1.00, with a radius of 1.00

The generated particles have a co-ordinate for the centre as well as a radius value.

For the Y co-ordinate (yP(i)) it would be:
IF (yP(i) > 1.00 .and. yP(i) < 3.00) THEN
!Test the x and z values (with radius?) to work out if they are in a cylinder
IF ((xP(i)+r(i))) THEN
ELSE DELETE Particle (if not within the x or z range)
ElSE DELETE Particle (If not within the y range)

I have also come into a problem that if it is within a 1.00 radius of the x, then it is fine, and the same for z. But if taken in conjunction they will form a square and be wrongly accepted. What could I do to overcome this? Would an IF ((xP(i)+r(i))) AND IF ((zP(i)+r(i))) THEN (keep particle) work?

If anyone has a more elegant way to write this please let me know, or a better way rather than the convoluted route I am taking.

Many thanks.
 
Distance formula?

TTFN
faq731-376
7ofakss

Need help writing a question or understanding a reply? forum1529
 
Thank you for your help. I have come up with this, which I think might solve it: (xP(i) and zP(i) are the particle co-ordinates)

IF ((((xP(i)-cylinder_x)**2)+((zP(i)-cylinder_z)**2)) < (cylinder_radius**2)) THEN

what are your thoughts?
 
Thank you for your help.

This is going to sound like a really silly question. I have the statements to define if a particle is in the cylinder, how would I code to store the particle co-ordinates within the cylinder, and delete the particle if it is outside?

Many thanks,
 
Is this for school? Student posting is not allowed.

TTFN
faq731-376
7ofakss

Need help writing a question or understanding a reply? forum1529
 
No fear, this isn't for school. I'm trying to learn fortran and see what it can do. I have seen some simulations in conferences and was curious to see how it was achieved and if it can be used to help me. I don't have anyone I know who does fortran hence why I was asking here, I couldn't find it online by searching on google.
 
This problem is a lot trickier than it sounds at first.

Just checking simple distance formula's won't do the trick.... not even close!

If your starting goal is to learn fortran, you might experiment with less difficult geometry problems. The difficulty in this problem has only to do with understanding the geometry of 3D space. The fortran involved should be extremely simple.

You could look up the formula's for the shortest distance from a point to a line in 3D space. If the distance is within acceptable tolerances, your point "might" be within the cylinder. If the point is near the end of the cylinder (outside of it or in it), that will require more checking.

My gut reaction here is... you need to rotate your coordinate axes such that one of the x or y or z coordinate axes lines up with the centerline passing through the cylinder. After calculating the coordinates of your cyclinders centerline and your point in question based on the new reference axes, I believe the problem would be trivial to solve. The main difficulty here is doing the coordinate axes transformation in 3D space. 2D is easy. 3D may cause you some large headaches.

Dan

 
Status
Not open for further replies.
Back
Top