2012-08-14 2 views
1

R에서 다음 정의 (eigenvalue 대신)를 기반으로 간단한 타원을 그리는 방법이 있습니까?초점을 기반으로 타원을 그립니다.

I 사용할 정의 타원 두 개의 고정 점 F 1 및 F 2까지의 거리의 합이 일정하게되는 평면의 점들의 집합이라는 것이다.

극좌표를 사용해야합니까?

이것은 더 알고리즘적인 질문 일 수 있습니다.

+0

. 어떤 수색을 했니? –

+0

문제는 타원의 속성을 보여주는 것입니다. 그래서 알고리즘을 정의를 따르기 바란다. – Ikuyasu

+0

당신은'sqrt ((x-xf1)^2 + (y-yf1)^2) + sqrt ((x-xf2)^2 + y2) = k '? – plannapus

답변

11

@DWin이 제안했듯이 타원을 그리기위한 몇 가지 구현이 있습니다 (예 : draw.ellipse 패키지 plotrix에 있음). 그들을 찾으려면 조금 형상을 알고있는 경우

말했다되고 그건
RSiteSearch("ellipse", restrict="functions") 

가 자신의 기능을 구현하는 것은 매우 간단하다. 여기에 시도는 다음과 같습니다

ellipse <- function(xf1, yf1, xf2, yf2, k, new=TRUE,...){ 
    # xf1 and yf1 are the coordinates of your focus F1 
    # xf2 and yf2 are the coordinates of your focus F2 
    # k is your constant (sum of distances to F1 and F2 of any points on the ellipse) 
    # new is a logical saying if the function needs to create a new plot or add an ellipse to an existing plot. 
    # ... is any arguments you can pass to functions plot or lines (col, lwd, lty, etc.) 
    t <- seq(0, 2*pi, by=pi/100) # Change the by parameters to change resolution 
    k/2 -> a # Major axis 
    xc <- (xf1+xf2)/2 
    yc <- (yf1+yf2)/2 # Coordinates of the center 
    dc <- sqrt((xf1-xf2)^2 + (yf1-yf2)^2)/2 # Distance of the foci to the center 
    b <- sqrt(a^2 - dc^2) # Minor axis 
    phi <- atan(abs(yf1-yf2)/abs(xf1-xf2)) # Angle between the major axis and the x-axis 
    xt <- xc + a*cos(t)*cos(phi) - b*sin(t)*sin(phi) 
    yt <- yc + a*cos(t)*sin(phi) + b*sin(t)*cos(phi) 
    if(new){ plot(xt,yt,type="l",...) } 
    if(!new){ lines(xt,yt,...) } 
    } 

예 : 타원 플롯 루틴의 여러 구현이 있습니다

F1 <- c(2,3) 
F2 <- c(1,2) 
plot(rbind(F1, F2), xlim=c(-1,5), ylim=c(-1, 5), pch=19) 
abline(h=0, v=0, col="grey90") 
ellipse(F1[1], F1[2], F2[1], F2[2], k=2, new=FALSE, col="red", lwd=2) 
points((F1[1]+F2[1])/2, (F1[2]+F2[2])/2, pch=3) 

enter image description here

+0

극좌표로 그릴 수 있다는 것을 알고 있습니다. 하지만 고맙습니다. 나는 아직도 너의 대답에서 무언가를 배운다. – Ikuyasu

관련 문제