-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBoatCode.m
More file actions
76 lines (47 loc) · 1.14 KB
/
BoatCode.m
File metadata and controls
76 lines (47 loc) · 1.14 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
%MatLab Code for Boat Project
%Boat Visualization
%Determination of COM
%Waterline Location
%Determination of Boat Displacement
%Determination of COB
%Determine Righting Arm
%Plot of RA vs. Angle
%Boat Design Input, global, localhull?
function res = BoatCode(nfunction, heelangle, COMpt,d, COBpt)
n = nfunction;
theta = heelangle;
waterline = d;
COMthing = COMpt;
COBthing = COBpt;
hold on;
boatvisual(n,waterline, theta, COMthing, COBthing);
%boat cross section
function res = boatvisual(n,d,theta, COMpt, COBpt)
y = @(x) (1/n^n)*abs(x).^n;
ydeck = @(x) 17;
boatdeck = @(x) y(x)-ydeck(x);
negboatdeck = fzero(boatdeck,-5);
posboatdeck = fzero(boatdeck,5);
%waterline
x1 = linspace(-20,20,100);
y1 = tand(theta)*x1+17-d;
%COM, COB
COM = COMpt;
COB = COBpt;
hold on;
%Plotting
fplot(y,[negboatdeck,posboatdeck],'b');
fplot(ydeck, [negboatdeck,posboatdeck], 'b');
plot(x1,y1);
plot(COM(1), COM(2),'r*');
plot(COB(1), COB(2),'g*');
axis([-20, 20, -5, 20]);
end
function res = boatvisual3D()
f1 = @(x) 1/3*abs(x).^3;
f2 = @(y) 1/6*abs(y).^6;
ftotal = @(x,y) -1.*(2500 - f1(x) - f2(y)).^(1/6);
ezsurf(ftotal,40)
axis([-20,20,-20,20])
end
end