schochastics / signnet
1
#include <Rcpp.h>
2
using namespace Rcpp;
3

4

5
// [[Rcpp::export]]
6 1
double arcDist(NumericVector x,NumericVector y, double r) {
7
  static const double pi = 3.14159265;
8 1
  double c = sqrt((x[0]-y[0])*(x[0]-y[0])+(x[1]-y[1])*(x[1]-y[1]));
9 1
  double theta = acos((2*r*r-c*c)/(2*r*r));
10 1
  return 2*pi*r*theta/(2*pi);
11
}
12

13

14
// [[Rcpp::export]]
15 1
NumericMatrix arcDistMat(NumericMatrix X,double r) {
16 1
  int n = X.nrow();
17 1
  NumericMatrix D(n,n);
18 1
  for(int i=0;i<n;i++){
19 1
    for(int j=0;j<n;j++){
20 1
      D(i,j)=arcDist(X(i,_),X(j,_),r);
21
    }
22
  }
23 1
  return D;
24
}

Read our documentation on viewing source code .

Loading