-
Notifications
You must be signed in to change notification settings - Fork 0
/
Surfaces.R
46 lines (37 loc) · 999 Bytes
/
Surfaces.R
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
34
35
36
37
38
39
40
41
42
43
44
45
46
# clear everything
rm(list=ls())
# activate libs for plotting in 3D
library("scatterplot3d")
library("car")
library("rgl")
library('lattice')
source("C:/Users/Sven/Puu/Teaching-Files/DataMining/Practice2/mydistfun.R")
# let us prepare some data
x<- c(-50:50)
x<-x*0.1
y=x
#imagine 10 by 10 square with the center at origine
# compute the distance between the origin and each internal point ofthe square
elt1<-matrix(,2,1)
elt2<-matrix(,2,1)
elt1[1,1]=0
elt1[2,1]=0
z1<-matrix(,101,101)
z2<-matrix(,101,101)
z3<-matrix(,101,101)
for (i in 1:101){
elt2[1,1]=x[i]
for (j in 1:101){
elt2[2,1]=y[j]
z1[i,j]=mydistfun(elt1,elt2,"eucledean")
z2[i,j]=mydistfun(elt1,elt2,"manhattan")
z3[i,j]=mydistfun(elt1,elt2,"Chebyshev")
}
}
#persp(x,y,z1)
#par(new=TRUE)
#open3d()
#surface3d(x,y,z2)
persp3d(x, y, z1,alpha=0.5, col="skyblue")
persp3d(x, y, z2,alpha=0.5, col="brown3",add=T)
persp3d(x, y, z3,alpha=0.5, col="green",add=T)