维基百科上的椭圆文章有一个简单的JavaScript代码来绘制椭圆。
它使用参数forms:
x(theta) = a0 + ax*sin(theta) + bx*cos(theta) y(theta) = b0 + ay*sin(theta) + by*cos(theta)
哪里
(a0,b0) is the center of the ellipse (ax,ay) vector representing the major axis (bx,by) vector representing the minor axis
我将代码翻译成MATLAB函数:
calculateEllipse.m
function [X,Y] = calculateEllipse(x, y, a, b, angle, steps) %# This functions returns points to draw an ellipse %# %# @param x X coordinate %# @param y Y coordinate %# @param a Semimajor axis %# @param b Semiminor axis %# @param angle Angle of the ellipse (in degrees) %# narginchk(5, 6); if nargin<6, steps = 36; end beta = -angle * (pi / 180); sinbeta = sin(beta); cosbeta = cos(beta); alpha = linspace(0, 360, steps)' .* (pi / 180); sinalpha = sin(alpha); cosalpha = cos(alpha); X = x + (a * c