20/10/01 13:39:44.47 bOWhBrvT.net
>>231
作図できれば角度は計測できるので
数値を変えても計算できるように関数化してみた。
f <- function(
# URLリンク(pbs.twimg.com)
DAB=3,
DAC=6,
DBA=51,
DBC=24){
# return the intersection point of two lines
# y=tan(A)(x-a1)+a2 & y=tan(B)(x-b1)+b2
koten <- function(a1,a2,a,b1,b2,b){
A=a*pi/180
B=b*pi/180
if(tan(A)==tan(B)) return(NA)
else
x = (a1* tan(A) - a2 - b1 *tan(B) + b2)/(tan(A) - tan(B))
y = (a1* tan(A)* tan(B) - b1 *tan(A)* tan(B) + b2 *tan(A) - a2* tan(B))/(tan(A) - tan(B))
c(x,y)
}
# coordinates of B,A,C-> angle BAC
BAC <- function(B,A,C){
if(is.complex(B)|is.complex(A)|is.complex(C)){
a=c(Re(A),Im(A)); b=c(Re(B),Im(B)); c=c(Re(C),Im(C))
}else{a=A;b=B;c=C}
ab=b-a
ac=c-a
dot=sum(ab*ac)
bac=acos(dot/sqrt(sum(ab^2))/sqrt(sum(ac^2)))
return(c(degree=bac*180/pi))
}
A=0i
C=koten(0,0,DAB+DAC, 1,0,180-(DBA+DBC))
D=koten(0,0,DAB, 1,0,180-DBA)
B=c(1,0)
c(x=BAC(D,C,B),y=BAC(D,C,A))
}
f()
> f()
x.degree y.degree
15 81