### Description

Computes the pairwise distance matrix between two sets of points

### Usage

`pairwise.dist(a, b, squared = TRUE, …)`

### Arguments

* a, b* matrices (NxD) and (MxD), respectively, where each row represents a D-dimensional point.

* squared* return containing squared Euclidean distance.

### Value

Euclidean distance matrix (NxM). An attribute “squared” set to the value of param squared is provided.

### See Also

*res.dist()*, *dist2closest()*, *ball()*

### Details

The continuous formation and rupture of non-covalent bonds (intra- and intermolecular), gives rise to dynamic molecular interactions, which are cosubstantial to life. These non-covalent interactions can adopt many forms, but all of them are fundamentally electrostatic in nature, and strongly influenced by distances.

Type of interaction | Energy dependence on the distance |
---|---|

Ion-ion | |

Ion-dipole | |

Dipole-dipole | |

Ion-induced dipole | |

Dipole-indiced dipole | |

Dispersion |

Therefore, computing spatial distances (in ångströms, Å), either between atoms or residues, is a useful task in many different contexts. A number of function from the package *ptm* will help us in these tasks:

- res.dist
- dist2closest
- ball
- pairwise.dist (the current document)

The most elementary of all these functions is, **pairwise.dist()**, which takes two sets of points (in the form of matrices) tailored by the user, and returns a distance matrix. Let’s just

```
a <- matrix(c(1,1,1,1,0,0,1,0,1), ncol = 3, byrow = TRUE)
rownames(a) <- c('point-1', 'point-2', 'point-3')
b <- matrix(c(0,0,0,1,1,1), ncol = 3, byrow = TRUE)
rownames(b) <- c('point-4', 'point-5')
a
```

## [,1] [,2] [,3] ## point-1 1 1 1 ## point-2 1 0 0 ## point-3 1 0 1

```
b
```

## [,1] [,2] [,3] ## point-4 0 0 0 ## point-5 1 1 1

and now let’s compute the distances between the two sets of points:

```
pairwise.dist(a, b, square = FALSE)
```

## point-4 point-5 ## point-1 1.732051 0.000000 ## point-2 1.000000 1.414214 ## point-3 1.414214 1.000000 ## attr(,"squared") ## [1] FALSE