This is embarassing, but however. My ellipse is defined by:
centerX
andcenterY
;majorAxis
andminorAxis
, lengths of both axis;orientation
, angle between the horizontal X axis and the major axis of the ellipse.
I started plotting the ellipse with its major axis parallel to the X axis:
theta = 0 : 0.05 : 2*pi;
orientation=orientation*pi/180;
xx = (majorAxis/2) * sin(theta) + centerX;
yy = (minorAxis/2) * cos(theta) + centerY;
%plot(xx,yy)
Now I only have to rotate this stuff by orientation
degrees or radiants. Any help? I tried a lot of stuff, e.g.:
- plotting and then
rotate
ing the object; - defining a rotation matrix
R = [cos(orientation), -sin(orientation); sin(orientation), cos(orientation)];
and applying it toxx-centerX
andyy-centerY
.
For some reason I can't get desired results. Of course I need points to be rotated around the center, not the origin.
Side note: if this is any help, I'm trying to plot ellipses defined by regionprops
, using the Centroid
,MajorAxisLength
,MinorAxisLength
and Orientation
properties.
To @Luis Mendo, here's what I get:
and this is another try:
For the bottom feature I'm getting orientation = 8
degrees, more or less, which is totally reasonable. But using your code, which I'm posting below, I get a -8
ellipse!
theta = 0 : 0.05 : 2*pi;
orientation=orientation*pi/180;
delta_x = (majorAxis/2) * sin(theta);
delta_y = (minorAxis/2) * cos(theta);
delta_x_ok = delta_x*cos(orientation) - delta_y*sin(orientation);
delta_y_ok = delta_x*sin(orientation) + delta_y*cos(orientation);
plot(delta_x_ok + centerX, delta_y_ok + centerY, 'r', 'LineWidth', 1.3);