MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: How to select only points which are inside a domain

  • To: mathgroup at smc.vnet.net
  • Subject: [mg124988] Re: How to select only points which are inside a domain
  • From: Bob Hanlon <hanlonr357 at gmail.com>
  • Date: Thu, 16 Feb 2012 03:27:46 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201202091034.FAA18221@smc.vnet.net>

It is more efficient to keep a list of the coordinates rather than a
list of Point graphic primitives.

n = 10000;

pts1 = RandomReal[{-5, 5}, {n, 3}]; (* list of coordinates *)

pts2 = Point /@ pts1; (* list of corresponding Point graphic primitives *)

pts3 = Point[pts1]; (* Point graphic primitive of list of coordinates *)

Graphics3D[Point[pts1]] (* output is very rapid *)

Graphics3D[pts2] (* significant delay prior to output *)

Graphics3D[pts3] (* output is very rapid *)

Define filter to work with multiple forms of input; output is same form as input

filterPoints3D[pts : {{_, _, _} ..},
  {xmin_, xmax_, ymin_, ymax_, zmin_, zmax_}] :=
 Select[pts,
  xmin <= #[[1]] <= xmax &&
    ymin <= #[[2]] <= ymax &&
    zmin <= #[[3]] <= zmax &]
(* filtered list of 3D coordinates *)

filterPoints3D[pts : {Point[{_, _, _}] ..},
  {xmin_, xmax_, ymin_, ymax_, zmin_, zmax_}] :=
 Select[pts,
  xmin <= #[[1, 1]] <= xmax &&
    ymin <= #[[1, 2]] <= ymax &&
    zmin <= #[[1, 3]] <= zmax &]
(* filtered list of Point graphic primitives *)

filterPoints3D[Point[pts : {{_, _, _} ..}],
  {xmin_, xmax_, ymin_, ymax_, zmin_, zmax_}] :=
 Point[Select[pts,
   xmin <= #[[1]] <= xmax &&
     ymin <= #[[2]] <= ymax &&
     zmin <= #[[3]] <= zmax &]]
(* filtered Point graphic primitive of list of coordinates *)

fp1 = filterPoints3D[pts1, {-1, 1, -1, 1, -1, 1}];

fp2 = filterPoints3D[pts2, {-1, 1, -1, 1, -1, 1}];

fp3 = filterPoints3D[pts3, {-1, 1, -1, 1, -1, 1}];

(Point /@ fp1) === fp2

True

Point[fp1] === fp3

True


Bob Hanlon


On Wed, Feb 15, 2012 at 4:41 AM, Ted Sariyski <tsariysk at craft-tech.com> wrote:
> Hi,
> I have a list of points: pntL={Point[x1,y1,z1],...}. How to select only
> points which are inside a domain {xmin,xmax,ymin,ymax,zmin,zmax}?
> Thanks in advance,
> --Ted
>



  • Prev by Date: Re: simple question on DSolve
  • Next by Date: Re: Running MathematicaScript in Mac Terminal
  • Previous by thread: Re: ListInterpolate and missing values
  • Next by thread: Re: ListInterpolate and missing values