-
Notifications
You must be signed in to change notification settings - Fork 0
/
EllipseFit.m
47 lines (41 loc) · 1.39 KB
/
EllipseFit.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
%%%%%%% Generate noisy points around a rotated ellipse %%%%%%%
% Parameters for the rotated ellipse
centreX = 25;
centreY = -10;
lengthX = 20;
lengthY = 18;
angle = 30;
% Rotation matrix to rotate ellipse parametric equations
RotationMatrix = [cosd(angle), -sind(angle); sind(angle), cosd(angle)];
% Generate noisy data points
pts.x = zeros(length(0:0.1:2*pi),1);
pts.y = zeros(length(0:0.1:2*pi),1);
i = 1;
for t = 0:0.1:2*pi
point = [lengthX*cos(t); lengthY*sin(t)];
rotatedPoint = RotationMatrix*point;
translatedPoint = rotatedPoint + [centreX; centreY];
pts.x(i) = translatedPoint(1) + (centreX + centreY)/20 * randn(1);
pts.y(i) = translatedPoint(2) + (centreX + centreY)/20 * randn(1);
i = i+1;
end
% Plot noisy data points and underlying curve
close all
plot(pts.x,pts.y,'ro');
hold on
drawRotatedElipse(centreX, centreY, lengthX, lengthY, angle);
% Focal length and foci of reference elipse shape
focalLength = sqrt(lengthX^2 - lengthY^2);
if (lengthX > lengthY)
circToFociDist = 2*lengthX;
foci(:,1) = RotationMatrix*[focalLength; 0]+ [centreX;centreY];
foci(:,2) = RotationMatrix*[-focalLength; 0]+ [centreX;centreY];
else
circToFociDist = 2*yLength;
foci(:,1) = RotationMatrix*[0; focalLength] + [centreX;centreY];
foci(:,2) = RotationMatrix*[0; - focalLength]+ [centreX;centreY];
end
plot(foci(1,1),foci(2,1),'go');
plot(foci(1,2),foci(2,2),'go');
axis equal
%