# TODO: Add comment
# 
# Author: E.Korsching  2023
###############################################################################



## graph triangle
# install.packages("calibrate")  ->  circle()


triang.coordinates <- function(a, b, c){
	# given the three sides of a triangle -> get the coordinates of the vertices , foremost the third vertex
	# a,b,c: triangle edge lengths
	require(calibrate)
	# check if the triangle inequality is satisfied
	if(a+b >= c){ cat("\n a+b >= c  ok") }else{ stop("\n a+b >= c  false") }
	if(b+c >= a){ cat("\n b+c >= a  ok") }else{ stop("\n b+c >= a  false") }
	if(c+a >= b){ cat("\n c+a >= b  ok") }else{ stop("\n c+a >= b  false") }
	
	plot(0,0, type="n", xlim=c(-2,5), ylim=c(-3,4), xlab="x", ylab="y")
	abline(h=0, v=0)
	polygon(x=c(0,a,2,0), y=c(0,0,2,0), density=NULL, angle=45, border="chocolate1", lwd=3)		# a 3  A 0,0  B 3,0  C x,y ? 
	lines(x=c(2,2), y=c(0,2), type="l", col="chocolate1", lwd=3)
	lines(x=c(2,2), y=c(0,-2), type="l", col="chocolate1", lwd=2, lty=1100)
	par(fg="gray")
	circle(c, c(0,0))		# c  for example pre-calculated form sqrt(2^2+2^2)
	circle(b, c(a,0))		# b  pre-calculated form sqrt(2^2+1^2)
	par(fg="black")
	text(x=c(0,3,2), y=c(0,0,2), labels=c("A","B","C"), pos=c(2,1,3), offset=0.8, cex=1.3, col=c("red","blue","chartreuse3"))
	text(x=c(1.5,2.8,0.7), y=c(-0.3,1.2,1.3), labels=c("a","b","c"), pos=c(1,4,3), offset=0, cex=1.3, col=c("black"))
	text(x=c(-1,3.9), y=c(2.1,-1.5), labels=c("C1","C2"), pos=c(3,1), offset=0, cex=1.3, col=c("gray"))
}


#triang.coordinates(a=3, b=2.2360, c=2.8284)


# move triangle by centroid
# rotate triangle coordinates



