[R] Function to locate points in 3d octants or points on two axes

Bryan Hanson hanson at depauw.edu
Wed Feb 2 14:23:15 CET 2011


Thanks Petr, the sign function will be of help.  I was not aware of  
it.  Bryan

On Feb 2, 2011, at 3:21 AM, Petr Savicky wrote:

> On Tue, Feb 01, 2011 at 08:30:22PM -0500, Bryan Hanson wrote:
>> [Sorry, resending with a proper subject line!]
>>
>> Hi Guru's...
>>
>> I have a set of points that may lie along any of the x, y and z axes
>> in a Cartesian coordinate system.  I am hoping that a function exists
>> which will determine if any two selected points are on different  
>> axes,
>> i.e, if the one of the points is on x and the other on y or z, not
>> elsewhere on the x axis.  Put another way, I need to determine if the
>> triangle formed by the two points and the origin lies in the xy, xz  
>> or
>> yz planes.  This might be as simple as testing if any particular  
>> value
>> is zero, i.e. if the x coordinate is zero, then the points must be on
>> the z and y axes and the triangle in the yz plane.  But, I'm looking
>> for a fairly general solution, one that also returns the appropriate
>> plane as the answer.  Very closely related to this, I could use a
>> function that determines which of the 8 octants a point lies in.  
>> Seems
>> like the cross product might be part of this, but I'm a little rusty
>> on how to apply it.
>>
>> I hope this is clear enough, and someone has a suggestion to point me
>> in the right direction.  Before writing my own klunky version, I
>> thought I'd ask.
>
> Hi.
>
> I think that for suggesting an appropriate solution it may be needed
> to know, which data structure is used for the input pairs of points.  
> For
> example, it may a single matrix n times 3 with points as rows and a  
> pair
> is represented by two indices of the points. Alternatively, the input
> may be a single matrix n times 6, where rows are pairs of points.
>
> In any case, the input may be simplified using sign() function. For  
> example
>
>  a <- as.matrix(expand.grid(x=c(-1.1, 0, 1.1), y=c(0, 1.2), z=c(0,  
> 1.3)))
>  a
>
>           x   y   z
>   [1,] -1.1 0.0 0.0
>   [2,]  0.0 0.0 0.0
>   [3,]  1.1 0.0 0.0
>   [4,] -1.1 1.2 0.0
>   [5,]  0.0 1.2 0.0
>   [6,]  1.1 1.2 0.0
>   [7,] -1.1 0.0 1.3
>   [8,]  0.0 0.0 1.3
>   [9,]  1.1 0.0 1.3
>  [10,] -1.1 1.2 1.3
>  [11,]  0.0 1.2 1.3
>  [12,]  1.1 1.2 1.3
>
>  sign(a)
>
>         x y z
>   [1,] -1 0 0
>   [2,]  0 0 0
>   [3,]  1 0 0
>   [4,] -1 1 0
>   [5,]  0 1 0
>   [6,]  1 1 0
>   [7,] -1 0 1
>   [8,]  0 0 1
>   [9,]  1 0 1
>  [10,] -1 1 1
>  [11,]  0 1 1
>  [12,]  1 1 1
>
> This output represents a classification of the points into a finite
> number of regions and keeps the information needed for any of the
> tasks, which you mention.
>
> Hope this helps.
>
> Petr Savicky.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list