[R] distances from points to line
Tord Snall
tord.snall at ebc.uu.se
Fri Nov 23 13:21:37 CET 2001
Hi,
Thanks! Adrian Baddeley have also answered my question directly to me and
he told me that there he will soon submit a library, spatstat, including
this kind of fuctions.
See
http://www.maths.uwa.edu.au/~adrian/spatstat.html
All the best,
Tord
I have At 22:21 2001-11-23 +0900, you wrote:
>Hi.
>
>>
>> I now wonder, is there a function to create a line object like a
>> watercourse and then calculate the distances between many points in space
>> and this line?
>>
>
> I've tried to port a fortran code of a distance from a line segment in
>Bowyer, A. and Woodwark, J. (1983):"a programmer's geometry", Butterworth,
>47-48, to R function. But I know your request was calculating points
>between polyline. So this function is not too enough. Just try this, if you
>are interested.
>
>#
># a function that returns a distance from a line
>#
># a point coordinate: xj, yj
>#
># a line segment coordinates: xk, yk, xl, yl
>#
>p2linedist<-function(xj, yj, xk, yk, xl, yl){
> xkj<- xk - xj
> ykj<- yk - yj
> xlk<- xl - xk
> ylk<- yl - yk
>
> denom <- xlk * xlk + ylk * ylk
>
> distance <- 0
>
> if(denom < 1.0e-6){
> sqrt(xkj*xkj + ykj*ykj) # segments ends coinside
> }else{
> t <- -(xkj*xlk + ykj*ylk)/denom
> t <- min(max(t,0),1)
> xfac <- xkj + t * xlk
> yfac <- ykj + t * ylk
> sqrt(xfac*xfac + yfac*yfac)
> }
>}
>
>
>
>
>
-----------------------------------------------------------------------
Tord Snäll
Avd. f växtekologi, Evolutionsbiologiskt centrum, Uppsala universitet
Dept. of Plant Ecology, Evolutionary Biology Centre, Uppsala University
Villavägen 14
SE-752 36 Uppsala, Sweden
Tel: 018-471 28 82 (int +46 18 471 28 82) (work)
Tel: 018-25 71 33 (int +46 18 25 71 33) (home)
Fax: 018-55 34 19 (int +46 18 55 34 19) (work)
E-mail: Tord.Snall at ebc.uu.se
http://www.vaxtbio.uu.se/resfold/snall.htm
------------------------------------------------------------------------
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list