Added multibody support.
This commit is contained in:
parent
9325530778
commit
1a88ead7ab
|
@ -120,7 +120,7 @@ class Ship:
|
||||||
for j in range(0,nP):
|
for j in range(0,nP):
|
||||||
z = z0 + j*dz
|
z = z0 + j*dz
|
||||||
rX = x1 - x0
|
rX = x1 - x0
|
||||||
rY = y1 - y0
|
rY = max(y1 - y0, abs(y1), abs(y0))
|
||||||
planes.append(Part.makePlane(4*rX,4*rY,Base.Vector(-2*rX,-2*rY,z),Base.Vector(0,0,1)))
|
planes.append(Part.makePlane(4*rX,4*rY,Base.Vector(-2*rX,-2*rY,z),Base.Vector(0,0,1)))
|
||||||
# Division are performed at x axis
|
# Division are performed at x axis
|
||||||
dx = (x1 - x0) / (nS - 1.0)
|
dx = (x1 - x0) / (nS - 1.0)
|
||||||
|
@ -149,23 +149,23 @@ class Ship:
|
||||||
edges.append(wire[k])
|
edges.append(wire[k])
|
||||||
# Slice curves to get points (Length based)
|
# Slice curves to get points (Length based)
|
||||||
points = []
|
points = []
|
||||||
for j in range(0,len(edges)):
|
for k in range(0,nP):
|
||||||
for k in range(0,nP):
|
planePoints = []
|
||||||
|
for j in range(0,len(edges)):
|
||||||
aux = self.lineFaceSection(edges[j], planes[k])
|
aux = self.lineFaceSection(edges[j], planes[k])
|
||||||
if not aux: # No section
|
for l in range(0,len(aux)):
|
||||||
points.append(Vector(x,0,z0 + k*dz))
|
planePoints.append(Vector(aux[l].X, aux[l].Y, aux[l].Z))
|
||||||
if len(aux) == 1: # Single point section
|
if not planePoints: # No section found, symmetry plane point will used
|
||||||
points.append(Vector(aux[0].X, aux[0].Y, aux[0].Z))
|
planePoints.append(Vector(x,0,z0 + k*dz))
|
||||||
else: # Several points, so ship has more than one body
|
# Get Y coordinates
|
||||||
# Get Y coordinates
|
auxY = []
|
||||||
auxY = []
|
for l in range(0,len(planePoints)):
|
||||||
for l in range(0,len(aux)):
|
auxY.append(planePoints[l].y)
|
||||||
auxY.append(aux[l].Y)
|
# Sort them
|
||||||
# Sort them
|
auxY.sort()
|
||||||
auxY.sort()
|
# And store
|
||||||
# And store
|
for l in range(0,len(planePoints)):
|
||||||
for l in range(0,len(aux)):
|
points.append(Vector(planePoints[l].x, auxY[l], planePoints[l].z))
|
||||||
points.append(Vector(aux[l].X, auxY[l], aux[l].Z))
|
|
||||||
# Store points
|
# Store points
|
||||||
section = points[:]
|
section = points[:]
|
||||||
nPoints.append(len(section))
|
nPoints.append(len(section))
|
||||||
|
@ -177,6 +177,9 @@ class Ship:
|
||||||
self.obj.nPoints = nPoints[:]
|
self.obj.nPoints = nPoints[:]
|
||||||
self.obj.xSection = xSection[:]
|
self.obj.xSection = xSection[:]
|
||||||
self.obj.mSections = mSections[:]
|
self.obj.mSections = mSections[:]
|
||||||
|
msg = '%d Discretization points performed\n' % (len(mSections))
|
||||||
|
msg = Translator.translate(msg)
|
||||||
|
FreeCAD.Console.PrintMessage(msg)
|
||||||
|
|
||||||
class ViewProviderShip:
|
class ViewProviderShip:
|
||||||
def __init__(self, obj):
|
def __init__(self, obj):
|
||||||
|
|
|
@ -159,7 +159,7 @@ class TaskPanel:
|
||||||
if maxZ < bbox.ZMax:
|
if maxZ < bbox.ZMax:
|
||||||
maxZ = bbox.ZMax
|
maxZ = bbox.ZMax
|
||||||
bounds[0] = maxX - minX
|
bounds[0] = maxX - minX
|
||||||
bounds[1] = maxY - minY
|
bounds[1] = max(maxY - minY, abs(maxY), abs(minY))
|
||||||
bounds[2] = maxZ - minZ
|
bounds[2] = maxZ - minZ
|
||||||
# Set UI fields
|
# Set UI fields
|
||||||
self.form.length.setMaximum(bounds[0])
|
self.form.length.setMaximum(bounds[0])
|
||||||
|
|
|
@ -27,6 +27,7 @@ import FreeCAD as App
|
||||||
import FreeCADGui as Gui
|
import FreeCADGui as Gui
|
||||||
# Module
|
# Module
|
||||||
import Instance
|
import Instance
|
||||||
|
from shipUtils import Math
|
||||||
|
|
||||||
def Displacement(ship, draft, trim):
|
def Displacement(ship, draft, trim):
|
||||||
""" Calculate ship displacement.
|
""" Calculate ship displacement.
|
||||||
|
@ -75,20 +76,91 @@ def Displacement(ship, draft, trim):
|
||||||
z0 = section[n-1].z
|
z0 = section[n-1].z
|
||||||
y1 = section[n].y
|
y1 = section[n].y
|
||||||
z1 = section[n].z
|
z1 = section[n].z
|
||||||
factor = (Z - z0) / (z1 - z0)
|
if (Z > z0) and not (Math.isAprox(Z,z0)):
|
||||||
y = y0 + factor*(y1 - y0)
|
factor = (Z - z0) / (z1 - z0)
|
||||||
points.append(App.Base.Vector(x,y,Z))
|
y = y0 + factor*(y1 - y0)
|
||||||
|
points.append(App.Base.Vector(x,y,Z))
|
||||||
|
# Convert into array with n elements (Number of points by sections)
|
||||||
|
# with m elements into them (Number of points with the same height,
|
||||||
|
# typical of multibody)
|
||||||
|
section = []
|
||||||
|
nPoints = 0
|
||||||
|
j = 0
|
||||||
|
while j < len(points)-1:
|
||||||
|
section.append([points[j]])
|
||||||
|
k = j+1
|
||||||
|
while(Math.isAprox(points[j].z, points[k].z)):
|
||||||
|
section[nPoints].append(points[k])
|
||||||
|
k = k+1
|
||||||
|
nPoints = nPoints + 1
|
||||||
|
j = k
|
||||||
# Integrate area
|
# Integrate area
|
||||||
area = 0.0
|
area = 0.0
|
||||||
for j in range(0, len(points)-1):
|
for j in range(0, len(section)-1):
|
||||||
y0 = abs(points[j].y)
|
for k in range(0, min(len(section[j])-1, len(section[j+1])-1)):
|
||||||
z0 = points[j].z
|
# y11,z11 ------- y01,z01
|
||||||
y1 = abs(points[j+1].y)
|
# | |
|
||||||
z1 = points[j+1].z
|
# | |
|
||||||
y = 0.5 * (y0 + y1)
|
# | |
|
||||||
dz = z1 - z0
|
# y10,z10 ------- y00,z00
|
||||||
area = area + 2.0*y*dz # 2x because only half ship is represented
|
y00 = abs(section[j][k].y)
|
||||||
areas.append(area)
|
z00 = section[j][k].z
|
||||||
|
y10 = abs(section[j][k+1].y)
|
||||||
|
z10 = section[j][k+1].z
|
||||||
|
y01 = abs(section[j+1][k].y)
|
||||||
|
z01 = section[j+1][k].z
|
||||||
|
y11 = abs(section[j+1][k+1].y)
|
||||||
|
z11 = section[j+1][k+1].z
|
||||||
|
dy = 0.5*((y00 - y10) + (y01 - y11))
|
||||||
|
dz = 0.5*((z01 - z00) + (z11 - z10))
|
||||||
|
area = area + dy*dz
|
||||||
|
if(len(section[j]) < len(section[j+1])):
|
||||||
|
# y01,z01 ------- y11,z11
|
||||||
|
# | __/
|
||||||
|
# | __/
|
||||||
|
# | /
|
||||||
|
# y00,z00
|
||||||
|
k = len(section[j])-1
|
||||||
|
y00 = abs(section[j][k].y)
|
||||||
|
z00 = section[j][k].z
|
||||||
|
y01 = abs(section[j+1][k].y)
|
||||||
|
z01 = section[j+1][k].z
|
||||||
|
y11 = abs(section[j+1][k+1].y)
|
||||||
|
z11 = section[j+1][k+1].z
|
||||||
|
dy = y01 - y11
|
||||||
|
dz = z01 - z00
|
||||||
|
area = area + 0.5*dy*dz
|
||||||
|
elif(len(section[j]) > len(section[j+1])):
|
||||||
|
# y01,z01
|
||||||
|
# | \__
|
||||||
|
# | \__
|
||||||
|
# | \
|
||||||
|
# y00,z00 ------- y10,z10
|
||||||
|
k = len(section[j+1])-1
|
||||||
|
y00 = abs(section[j][k].y)
|
||||||
|
z00 = section[j][k].z
|
||||||
|
y10 = abs(section[j][k+1].y)
|
||||||
|
z10 = section[j][k+1].z
|
||||||
|
y01 = abs(section[j+1][k].y)
|
||||||
|
z01 = section[j+1][k].z
|
||||||
|
dy = y00 - y10
|
||||||
|
dz = z01 - z00
|
||||||
|
area = area + 0.5*dy*dz
|
||||||
|
elif(len(section[j]) == 1):
|
||||||
|
# y1,z1 -------
|
||||||
|
# |
|
||||||
|
# |
|
||||||
|
# |
|
||||||
|
# y0,z0 -------
|
||||||
|
k = 0
|
||||||
|
y0 = abs(section[j][k].y)
|
||||||
|
z0 = section[j][k].z
|
||||||
|
y1 = abs(section[j+1][k].y)
|
||||||
|
z1 = section[j+1][k].z
|
||||||
|
dy = 0.5 * (y0 + y1)
|
||||||
|
dz = z1 - z0
|
||||||
|
area = area + dy*dz
|
||||||
|
areas.append(2.0*area) # 2x because only half ship is represented
|
||||||
# Add volume & moment if proceed
|
# Add volume & moment if proceed
|
||||||
if i > 0:
|
if i > 0:
|
||||||
dx = xCoord[i] - xCoord[i-1]
|
dx = xCoord[i] - xCoord[i-1]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user