/* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator www.cs.sandia.gov/~sjplimp/lammps.html Steve Plimpton, sjplimp@sandia.gov, Sandia National Laboratories Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include "region_triangle.h" #include "stdlib.h" #include "string.h" #include "error.h" using namespace LAMMPS_NS; #define MIN(A,B) ((A) < (B) ? (A) : (B)) #define MAX(A,B) ((A) > (B) ? (A) : (B)) /* ---------------------------------------------------------------------- */ RegTriangle::RegTriangle(LAMMPS *lmp, int narg, char **arg) : Region(lmp, narg, arg) { options(narg-8,&arg[8]); x1 = xscale*atof(arg[2]); y1 = yscale*atof(arg[3]); x2 = xscale*atof(arg[4]); y2 = yscale*atof(arg[5]); x3 = xscale*atof(arg[6]); y3 = yscale*atof(arg[7]); // extent of 2d triangle extent_xlo = MIN(x1,x2); extent_xlo = MIN(extent_xlo,x3); extent_xhi = MAX(x1,x2); extent_xhi = MAX(extent_xhi,x3); extent_ylo = MIN(y1,y2); extent_ylo = MIN(extent_ylo,y3); extent_yhi = MAX(y1,y2); extent_yhi = MAX(extent_yhi,y3); extent_zlo = -0.5; extent_zhi = 0.5; } /* ---------------------------------------------------------------------- */ int RegTriangle::match(double x, double y, double z) { double side1 = (x-x1)*(y2-y1) - (y-y1)*(x2-x1); double side2 = (x-x2)*(y3-y2) - (y-y2)*(x3-x2); double side3 = (x-x3)*(y1-y3) - (y-y3)*(x1-x3); int inside; if (side1 > 0.0 && side2 > 0.0 && side3 > 0.0) inside = 1; else inside = 0; return !(inside ^ interior); // 1 if same, 0 if different }