Skip to main content
added 1619 characters in body
Source Link
Level River St
  • 28.8k
  • 4
  • 40
  • 112

Ruby, Golfed version 313 bytes

->e,a,i,w,u,l,t{s="<svg viewBox='0-90 358 180'style='background:tan'>" v=d=0.01 (t+=d*((a-a*e*e)**3/u)**0.5/(1+e*Math.cos(v+=d))**2 x,q=(1i**((v+w)/n=1i.arg)).rect y,z=(q*1i**(i/n)).rect s<<"<circle r='1'cx='#{j=((-x-y*1i).arg-t/l*n*=4)%n*57}'cy='#{Math.asin(z)*-57}'/>" v>2*d||K=j)until v%6.29<d&&(j-K).abs<20 s} 

Try it online!

This golfed version has 2 differences with respect to the ungolfed version: the formulas that generate and use the radius r have been combined, saving 12 bytes; and the code for rounding the numbers in the output has been removed.

The lack of rounding means the output is larger, therefore the output of the last 2 test cases (with 5 and 6 orbits each) exceeds the byte limit on TIO.run. The other test cases (with less orbits) run to completion.

Ruby, ungolfed version 322 347 345 bytes

Ruby, ungolfed version 322 347 345 bytes

Ruby, Golfed version 313 bytes

->e,a,i,w,u,l,t{s="<svg viewBox='0-90 358 180'style='background:tan'>" v=d=0.01 (t+=d*((a-a*e*e)**3/u)**0.5/(1+e*Math.cos(v+=d))**2 x,q=(1i**((v+w)/n=1i.arg)).rect y,z=(q*1i**(i/n)).rect s<<"<circle r='1'cx='#{j=((-x-y*1i).arg-t/l*n*=4)%n*57}'cy='#{Math.asin(z)*-57}'/>" v>2*d||K=j)until v%6.29<d&&(j-K).abs<20 s} 

Try it online!

This golfed version has 2 differences with respect to the ungolfed version: the formulas that generate and use the radius r have been combined, saving 12 bytes; and the code for rounding the numbers in the output has been removed.

The lack of rounding means the output is larger, therefore the output of the last 2 test cases (with 5 and 6 orbits each) exceeds the byte limit on TIO.run. The other test cases (with less orbits) run to completion.

Ruby, ungolfed version 322 347 345 bytes

added 281 characters in body
Source Link
Level River St
  • 28.8k
  • 4
  • 40
  • 112

Ruby, ungolfed version 322 347 347345 bytes

->e,a,i,w,u,l,t{s="<svg viewBox='0-90 358 180'style='background:tan'>" k=v=d=0v=d=0.01 (r=(a-a*e*e)/(1+e*Math.cos(v+=d)) t+=r*r/(u*(a-a*e*e))**0.5*d x,q=(1i**((v+w)/n=1i.arg)).rect y,z=(q*1i**(i/n)).rect s<<"<circle r='1'cx='#{(j=((-x-y*1i).arg-t/l*n*=4)%n*57).round(1)}'cy='#{(Math.asin(z)*-57).round(1)}'/>" v>2*d||k=jv>2*d||K=j)until v%6.29<d&&(j-kK).abs<20 s} 

Try it online!Try it online!

Initialise s with an SVG header, and set d and v to the step size. Step size is 0.01 radians. The Ruby preprocessor likes to be sure that a variable will be initialised before it is used and does not like the fact that k is only assigned in a conditional. Therefore we conveniently initialise k to the same value as d to avoid an error. We open a bracket to start looping.

s="<svg viewBox='0-90 358 180'style='background:tan'>" k=v=d=0v=d=0.01 ( 
  • Record the longitude on the 1st iteration (at the start of the 1st orbit): v>2*d||k=jv>2*d||K=j

  • Keep iterating until the start of an orbit where the longitude is within 20 degrees of the 1st orbit: )until v%6.29<d&&(j-kK).abs<20

  • Return from function with SVG image in string s}

    v>2*d||k=jv>2*d||K=j)until v%6.29<d&&(j-kK).abs<20 s} 

Note the use of uppercase K here. The Ruby preprocessor likes to know that all variables will be assigned before they are used, and if lowercase k is used it insists that k be initialised outside the loop to guarantee it will be assigned before it is used, as the assignment in the code shown occurs in a conditional. 2 bytes were saved by switching to uppercase K which represents a constant, since the preprocessor does not check constants in the same way and the assignment can be avoided.

Ruby, 322 347 bytes

->e,a,i,w,u,l,t{s="<svg viewBox='0-90 358 180'style='background:tan'>" k=v=d=0.01 (r=(a-a*e*e)/(1+e*Math.cos(v+=d)) t+=r*r/(u*(a-a*e*e))**0.5*d x,q=(1i**((v+w)/n=1i.arg)).rect y,z=(q*1i**(i/n)).rect s<<"<circle r='1'cx='#{(j=((-x-y*1i).arg-t/l*n*=4)%n*57).round(1)}'cy='#{(Math.asin(z)*-57).round(1)}'/>" v>2*d||k=j)until v%6.29<d&&(j-k).abs<20 s} 

Try it online!

Initialise s with an SVG header, and set d and v to the step size. Step size is 0.01 radians. The Ruby preprocessor likes to be sure that a variable will be initialised before it is used and does not like the fact that k is only assigned in a conditional. Therefore we conveniently initialise k to the same value as d to avoid an error. We open a bracket to start looping.

s="<svg viewBox='0-90 358 180'style='background:tan'>" k=v=d=0.01 ( 
  • Record the longitude on the 1st iteration (at the start of the 1st orbit): v>2*d||k=j

  • Keep iterating until the start of an orbit where the longitude is within 20 degrees of the 1st orbit: )until v%6.29<d&&(j-k).abs<20

  • Return from function with SVG image in string s}

    v>2*d||k=j)until v%6.29<d&&(j-k).abs<20 s} 

Ruby, ungolfed version 322 347 345 bytes

->e,a,i,w,u,l,t{s="<svg viewBox='0-90 358 180'style='background:tan'>" v=d=0.01 (r=(a-a*e*e)/(1+e*Math.cos(v+=d)) t+=r*r/(u*(a-a*e*e))**0.5*d x,q=(1i**((v+w)/n=1i.arg)).rect y,z=(q*1i**(i/n)).rect s<<"<circle r='1'cx='#{(j=((-x-y*1i).arg-t/l*n*=4)%n*57).round(1)}'cy='#{(Math.asin(z)*-57).round(1)}'/>" v>2*d||K=j)until v%6.29<d&&(j-K).abs<20 s} 

Try it online!

Initialise s with an SVG header, and set d and v to the step size. Step size is 0.01 radians. We open a bracket to start looping.

s="<svg viewBox='0-90 358 180'style='background:tan'>" v=d=0.01 ( 
  • Record the longitude on the 1st iteration (at the start of the 1st orbit): v>2*d||K=j

  • Keep iterating until the start of an orbit where the longitude is within 20 degrees of the 1st orbit: )until v%6.29<d&&(j-K).abs<20

  • Return from function with SVG image in string s}

    v>2*d||K=j)until v%6.29<d&&(j-K).abs<20 s} 

Note the use of uppercase K here. The Ruby preprocessor likes to know that all variables will be assigned before they are used, and if lowercase k is used it insists that k be initialised outside the loop to guarantee it will be assigned before it is used, as the assignment in the code shown occurs in a conditional. 2 bytes were saved by switching to uppercase K which represents a constant, since the preprocessor does not check constants in the same way and the assignment can be avoided.

added 6250 characters in body
Source Link
Level River St
  • 28.8k
  • 4
  • 40
  • 112

This is consistent with an observation made by Kepler (who first described the orbit of the planets) that the orbit sweeps out equal area in equal time. He attempted to explain the reason for this (but his reasoning was incorrect since he knew only Aristotlean mechanics.) Newton later explained the reason correctly. There were however anomalies in the orbit of Mercury which were later shown to be due to relativistic effects (and not a postulated additional planet, that had been given the provisional name Vulcan.)

  • Record the longitude at the start of the 1st orbit: v>2*d||k=j

    Record the longitude on the 1st iteration (at the start of the 1st orbit): v>2*d||k=j

  • Keep iterating until the start of an orbit where the longitude is within 20 degrees fo the 1st orbit: )until v%6.29<d&&(j-k).abs<20

    Keep iterating until the start of an orbit where the longitude is within 20 degrees of the 1st orbit: )until v%6.29<d&&(j-k).abs<20

  • Return from function with SVG image in string s}

    Return from function with SVG image in string s}

    v>2*d||k=j)until v%6.29<d&&(j-k).abs<20 s} 

On the 1st iteration,

 v>2*d||k=j)until v%6.29<d&&(j-k).abs<20 s} 

This is consistent with an observation made by Kepler (who first described the orbit of the planets) that the orbit sweeps out equal area in equal time. He attempted to explain the reason for this (but his reasoning was incorrect since he knew only Aristotlean mechanics.) Newton later explained the reason correctly. There were however anomalies in the orbit of Mercury which were later shown to be due to relativistic effects (and not a postulated additional planet, given the provisional name Vulcan.)

  • Record the longitude at the start of the 1st orbit: v>2*d||k=j
  • Keep iterating until the start of an orbit where the longitude is within 20 degrees fo the 1st orbit: )until v%6.29<d&&(j-k).abs<20
  • Return from function with SVG image in string s}

On the 1st iteration,

 v>2*d||k=j)until v%6.29<d&&(j-k).abs<20 s} 

This is consistent with an observation made by Kepler (who first described the orbit of the planets) that the orbit sweeps out equal area in equal time. He attempted to explain the reason for this (but his reasoning was incorrect since he knew only Aristotlean mechanics.) Newton later explained the reason correctly. There were however anomalies in the orbit of Mercury which were later shown to be due to relativistic effects (and not a postulated additional planet, that had been given the provisional name Vulcan.)

  • Record the longitude on the 1st iteration (at the start of the 1st orbit): v>2*d||k=j

  • Keep iterating until the start of an orbit where the longitude is within 20 degrees of the 1st orbit: )until v%6.29<d&&(j-k).abs<20

  • Return from function with SVG image in string s}

    v>2*d||k=j)until v%6.29<d&&(j-k).abs<20 s} 
added 6250 characters in body
Source Link
Level River St
  • 28.8k
  • 4
  • 40
  • 112
Loading
deleted 27638 characters in body
Source Link
Level River St
  • 28.8k
  • 4
  • 40
  • 112
Loading
added 299 characters in body
Source Link
Level River St
  • 28.8k
  • 4
  • 40
  • 112
Loading
Source Link
Level River St
  • 28.8k
  • 4
  • 40
  • 112
Loading