2016-09-18 94 views
1

我有三個參考矢量中的R笛卡爾轉換座標重心那些

a (0, 0, 1) 
b (0, 1, 0) 
c (1, 0, 0) 

並且將具有測量值,例如

x(0, 0.5, 0.3) 

,我想在一個二維圖形繪製如三角形,誰邊將對應於a,b和c。

在Matlab中有一個簡單明瞭的功能做

http://fr.mathworks.com/help/matlab/ref/triangulation.cartesiantobarycentric.html?s_tid=gn_loc_drop 

沒有人知道R中的等價或我應該實現數學?

回答

4

當然,你可以在笛卡兒和重心之間來回走動。

巴里購物車:

library(geometry) 

## Define simplex in 2D (i.e. a triangle) 
X <- rbind(
      c(0, 0, 1), 
      c(0, 1, 0), 
      c(1, 0, 0)) 

## Cartesian cooridinates of points 
beta <- rbind(c(0, 0.5, 0.3), 
       c(0.1, 0.8, 0.1), 
       c(0.1, 0.8, 0.1)) 

## Plot triangle and points 
trimesh(rbind(1:3), X) 
text(X[,1], X[,2], 1:3) # Label vertices 
P <- bary2cart(X, beta) 

enter image description here

車到巴里:

## Define simplex in 2D (i.e. a triangle) 
X <- rbind(c(0, 0), 
      c(0, 1), 
      c(1, 0)) 
## Cartesian cooridinates of points 
P <- rbind(c(0.5, 0.5), 
      c(0.1, 0.8)) 
## Plot triangle and points 
trimesh(rbind(1:3), X) 
text(X[,1], X[,2], 1:3) # Label vertices 
points(P) 
cart2bary(X, P) 
相關問題