Get n points along the ellipse, given the end points and the minor axis

I'm trying to draw an ellipse between two endpoints or that this drawing causes vertices:

enter image description here

In the function, I want to give the coordinates of two vertices and indicate the distance from the fact that the image causes the secondary axis (perpendicular to the line created by the vertices. I waved some kind of high school math, but am struggling with creating a function that gives me n values ​​along the ellipse. I looked at the ellipse package, but that seems to require correlation, however I want the function to return values ​​like ellipse .

I do not adhere to any specific approach, but would like to indicate the arguments in my attempt to function below. My search for the ellipse and R gave a lot of hits, but did not give the arguments I'm trying to use.

 elip <- function(vert1 = c(.25, .45), vert2 = c(.5, .35), minoraxis = .1, n =150) { majoraxis <- sqrt(((vert2[1] - vert1[1])^2) + ((vert2[2] - vert1[2])^2)) center <- c((vert2[1] + vert1[1])/2, (vert2[2] + vert1[2])/2) half_ma <- minoraxis/2 focci_dist <- sqrt(abs((majoraxis ^2) - (half_ma^2))) } 
+6
source share
1 answer

This takes two vertices on the major axis and half the length of the minor axis (like b) along with the number of points.

 halfEllipse <- function(v1, v2, b, n = 100){ x1 <- v1[1] y1 <- v1[2] x2 <- v2[1] y2 <- v2[2] xc <- mean(c(x1,x2)) yc <- mean(c(y1,y2)) A <- sqrt((xc-x1)^2 + (yc-y1)^2) myangle <- atan((yc-y1)/(xc-x1)) # Construct half ellipse with desired # major and minor axis length ts <- seq(0, pi, length.out = n) X <- A*cos(ts) Y <- b*sin(ts) # Rotate to get to desired angle Xp <- X*cos(myangle) - Y*sin(myangle) Yp <- X*sin(myangle) + Y*cos(myangle) # Shift back to desired center Xp <- Xp + xc Yp <- Yp + yc cbind(Xp,Yp) } 
+6
source

Source: https://habr.com/ru/post/953749/


All Articles