aboutsummaryrefslogtreecommitdiff
path: root/R/tools.R
diff options
context:
space:
mode:
authorVotre Nom <git-account@loicguegan.fr>2017-08-30 13:57:44 +0400
committerVotre Nom <git-account@loicguegan.fr>2017-08-30 13:57:44 +0400
commit19b26672103903556ae014732b169146d2e6a5a1 (patch)
treebeab53853a4f7e15672b13d11a5face1918e158a /R/tools.R
parentf37f200792444fee2f74e807acfd5be7c9180cd7 (diff)
Add R
Diffstat (limited to 'R/tools.R')
-rwxr-xr-xR/tools.R33
1 files changed, 33 insertions, 0 deletions
diff --git a/R/tools.R b/R/tools.R
new file mode 100755
index 0000000..6eaec75
--- /dev/null
+++ b/R/tools.R
@@ -0,0 +1,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));
+}
+