aboutsummaryrefslogtreecommitdiff
path: root/R/tools.R
blob: 6eaec75d5b7a78c1215e70826cd0349f64002588 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Compute cartesian distance of two points
computeCartDist=function(x1,y1,x2,y2){
  return(sqrt((x2-x1)^2+(y2-y1)^2));
}

# Get line equation from two of his points y=ax+b
getLineEquation=function(x1,y1,x2,y2){
  eq=NULL;
  if(x1!=x2){
    a=(y1-y2)/(x1-x2)
    b=y1-a*x1
    eq=c(a,b)
  }
  return(eq)
}

# Get the middle point of a segment
getMiddleOfSegment=function(x1,y1,x2,y2){
  x=(x1+x2)/2;
  y=(y1+y2)/2;
  return(c(x,y));
}

# Convert dBm to Watt
dBm2W=function(pdBm){
  return((10^(pdBm/10))/1000);
}

# Convert Watt to dBm
W2dBm=function(pW){
  return(10*log10(1000*pW));
}