Learn R Programming

pcds (version 0.1.8)

funsCartBary: Converts of a point in Cartesian coordinates to Barycentric coordinates and vice versa

Description

Two functions: cart2bary and bary2cart.

cart2bary converts Cartesian coordinates of a given point P\(=(x,y)\) to barycentric coordinates (in the normalized form) with respect to the triangle tri\(=(v_1,v_2,v_3)\) with vertex labeling done row-wise in tri (i.e., row \(i\) corresponds to vertex \(v_i\) for \(i=1,2,3\)).

bary2cart converts barycentric coordinates of the point P\(=(t_1,t_2,t_3)\) (not necessarily normalized) to Cartesian coordinates according to the coordinates of the triangle, tri. For information on barycentric coordinates, see (weisstein-barycentric;textualpcds).

Usage

cart2bary(P, tri)

bary2cart(P, tri)

Value

cart2bary returns the barycentric coordinates of a given point P\(=(x,y)\) and bary2cart returns the Cartesian coordinates of the point P\(=(t_1,t_2,t_3)\)

(not necessarily normalized).

Arguments

P

A 2D point for cart2bary, and a vector of three numeric entries for bary2cart.

tri

A \(3 \times 2\) matrix with each row representing a vertex of the triangle.

Author

Elvan Ceyhan

References

Examples

Run this code
# \donttest{
#Examples for cart2bary
c1<-.4; c2<-.6
A<-c(0,0); B<-c(1,0); C<-c(c1,c2);
Tr<-rbind(A,B,C)

cart2bary(A,Tr)
cart2bary(c(.3,.2),Tr)
# }

# \donttest{
#Examples for bary2cart
c1<-.4; c2<-.6
A<-c(0,0); B<-c(1,0); C<-c(c1,c2);
Tr<-rbind(A,B,C)

bary2cart(c(.3,.2,.5),Tr)
bary2cart(c(6,2,4),Tr)
# }

Run the code above in your browser using DataLab