-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
69 lines (44 loc) · 1.45 KB
/
utils.py
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
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 21 11:02:38 2017
@author: jazicoan
"""
import numpy as np
from math import cos, sin, atan2, hypot
import json
# ===== Angle-related functions ===== #
def degTorad(angle):
return((angle*np.pi/180))
def radTodeg(angle):
return(angle*180/np.pi)
def wrapTo2Pi(theta):
theta = 2.0*np.arctan(np.tan(theta/2.0))
return(float(theta))
def wrapAngle(theta):
if theta < 0:
theta = theta+360
if theta > 360:
theta = theta%360
return(theta)
# ===== Switch between Coordinate System ===== #
def apparentWindCoordinatesToMWCoordinates(FxW,FyW,alpha):
Fy = FyW*np.cos(alpha)-FxW*np.sin(alpha)
Fx = FyW*np.sin(alpha)+FxW*np.cos(alpha)
return (Fx,Fy)
def MWCoordinatesToBoatCoordinates(FxMW,FyMW,MWAngle):
Fx = FxMW*np.cos(MWAngle)+FyMW*np.sin(MWAngle)
Fy = FyMW*np.cos(MWAngle)-FxMW*np.sin(MWAngle)
return (Fx,Fy)
def apparentWindCoordinatesToBoatCoordinates(FxW,FyW,alpha,MWAngle):
FxMW,FyMW = apparentWindCoordinatesToMWCoordinates(FxW,FyW,alpha)
return(MWCoordinatesToBoatCoordinates(FxMW,FyMW,MWAngle))
# ===== Integration Schemes ===== #
def euler(x,xdot,dt):
return(x+xdot*dt)
# ===== loading a boat configuration ===== #
def loadConfigFile(configPath):
with open (configPath) as data_file:
config = json.load(data_file)
data_file.close()
return(config)
# Add new functions or sections if necessary