> From: PackRat
> 
> However, my math skills from 45 years ago aren't enough to figure out
> what the cos2 routine should look like for an ellipse instead of a
> circle.  (I don't even know exactly what the cyclical curve would look
> like!)  I'm sure the two semidiameters somehow would have to come into
> play in the formula (and in the arguments to the verb).  I'm presuming
> a "vertical" or "horizontal" orientation of the ellipse should make no
> difference; if it does, I'll need to know how to deal with both.
> Thanks in advance for your assistance!
> 

Here's a simple (rather than concise) solution for plotting an ellipse, does 
that help?

load 'plot'
require 'numeric trig'

NB.*getEllipsePoints v Returns X,:Y coords for ellipse
NB. eg: getEllipsePoints 0 0 8 2 90
NB. y is: 5-item numeric list
NB.     0 1{ x and y coords of ellipse center
NB.     2 3{ lengths of semimajor and semiminor axes
NB.       4{ Angle (degrees) of the semimajor axis from horizontal
NB. x is: optional number of points to plot (default 36)
getEllipsePoints=: verb define
  36 getEllipsePoints y
:
  'Xc Yc a b angle'=. y
  nsteps=. x
  'sinbeta cosbeta'=. (sin , cos) rfd - angle
  alpha=. rfd steps 0 360 , nsteps
  'sinalpha cosalpha'=. (sin ,: cos) alpha
  X=. Xc + (a * cosbeta * cosalpha) - b * sinbeta * sinalpha
  Y=. Yc + (a * sinbeta * cosalpha) + b * cosbeta * sinalpha
  X,:Y
)

Note 'Usage'
 plot ;/ getEllipsePoints 0 0 8 2 0    NB. horizontal ellipse
 plot ;/ getEllipsePoints 0 0 8 2 30   NB. ellipse on angle
 plot ;/ getEllipsePoints 2 3 8 2 30   NB. ellipse on angle, center 2 3
 plot ;/ getEllipsePoints 0 0 10 10 0  NB. circle
 plot ;/ 1 0 2|:(getEllipsePoints 0 0 10 10 0) ,: getEllipsePoints 2 2 8 2 20
)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to