Domanda

Calculating an elliptical orbit of a planet around the sun involves the formula:

e = c/a

where:

c is the distance from the center to a focus and

a is the distance from that focus to a vertex

How does one create a program to calculate this type of problem when elliptical shapes (namely in C++) do not use foci, but rather x and y max distances?

I currently have a function that creates an ellipse given an (x, y) center point and an x and y length.

I'm having issues converting a real elliptical orbit function e= c/a into a programs ellipse function ellipse(x, y, xDistance, yDistance).

Is there a system out there for this or how would I go about accomplishing this? The intent is to draw a scale model of the planets' orbit around the Sun using actual data for each planet.

IE: Mercury:

  • 0.39 AU from the sun (distance)
  • Orbital Eccentricity: 0.2056
È stato utile?

Soluzione

To be more precise:

Given a line L, called a directrix, a point F not on L, called a focus, and a positive number e. Let d(X,L) denote the distance from a point X to L, and let |X| denote the norm of X. The set C of points X satisfying

|X - F| = e d(X,L)

is called a conic section with eccentricity e. It is called an ellipse if e < 1, a parabola if e = 1, and a hyperbola if e > 1.

Now what you want is the Cartesian equation of the conic in standard form. If e < 1 or e > 1 and the directrix is parallel to the y-axis, the conic C is the set of points X = (x,y) satisfying

x^2 / a^2 + y^2 / [a^2 (1 - e^2)] = 1

where a = e d / (1 - e^2) and d = d(F,L) is the distance from the focus to the directrix.

If e < 1 (so that a > 0), let b = a sqrt(1 - e^2). We then obtain the equation of an ellipse in standard form

x^2 / a^2 + y^2 / b^2 = 1

where a,b are called the semi-major and semi-minor axis respectively. In this form,

  • the ellipse center is at the origin (0,0),
  • the directrix crosses the x-axis at point (d,0),
  • the two foci are at points (-c,0), (c,0) where c = a e and c^2 = a^2 - b^2,
  • the two vertices on the x-axis are at points (-a,0), (a,0), and
  • the two vertices on the y-axis are at points (0,-b), (0,b).

So your a is the distance from a x-vertex to the center and not to a focus. However, note that c is the distance from a y-vertex to a focus. This may be a source of confusion.

You can see that a, b are your missing xDistance, yDistance. It appears you are given a and e, so you only need to compute b as above.

Of course, you can always check ellipse @wikipedia. This figure will help visualize my previous descriptions, but note that my c is denoted as f there.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top