Skip to content

Commit f857671

Browse files
Optimized source code
1 parent f5f0f37 commit f857671

14 files changed

+113
-79
lines changed

M.png

10.1 KB
Loading

N.png

671 Bytes
Loading

Q.png

9.31 KB
Loading

Readme.md

+51-35
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
Beam Calc
2-
=========
31
Calculates the supporting forces of a simply supported beam.
42

53
Beam and acting loads
@@ -10,39 +8,57 @@ Beam and acting loads
108
Sample output
119
-------------
1210
Beam:
13-
Length=4.0
14-
Supports sorted by distance from left end of beam:
15-
Support A (Left) xn=0.0
16-
Support B (Right) xn=4.0
17-
18-
Number of Loads:2
19-
Loads sorted by distance from left end of beam:
20-
Name:q1 Magnitute at start:-5.0 Point Load:-5.0 distance from left end:0.0 Lengtht:4.0 Force at end:-5.0 Resulting force:-20.0 is acting 2.0 m from left end of beam.
21-
Name:F1 Magnitute at start:-2.0 Point Load:-2.0 distance from left end:2.0 Lengtht:0.0 Force at end:-2.0 Resulting force:-2.0 is acting 2.0 m from left end of beam.
22-
23-
RESULT:
24-
Left support:10.707106781186548 N. Right bearing:10.707106781186548 N.
25-
Horizontal force at right support:1.414213562373095
26-
Term:N=2.0 N x sin(45.0) = 1.41N
27-
Term:B (Right)=5.0N x 4.0m + 2.0N x cos(45.0) + (-10.71N) = 10.71N
28-
Term:A (Left)=(5.0 N/m x 4.0m x 2.0m+2.0N x cos(45.0) x 2.0m)/4.0m = 10.71N
29-
30-
=== Shearing forces => Q ===
31-
Local maxi-/ minima
32-
Points of disconuity in Q
33-
x=0.0 m Q=10.706106781186547 N
34-
x=2.0 m Q=-0.7081067811881641 N
35-
x=4.0 m Q=-5.000000032335805E-4 N
36-
37-
=== Bending moment => M ===
38-
Local maxi-/ minima
39-
x=1.9998999999997962 m M=11.410643101686322 Nm
40-
Points of disconuity in M
41-
x=0.0 m M=0.0 Nm
42-
x=1.9999999999997962 m M=11.410289362442864 Nm
43-
44-
=== Normal forces => N ===
45-
x=2.0 m N[N]=-1.414213562373095 N
11+
Length=4.0
12+
Supports sorted by distance from left end of beam:
13+
Support A (Left) xn=1.0
14+
Support B (Right) xn=3.0
15+
16+
Number of Loads:2
17+
Loads sorted by distance from left end of beam:
18+
Name:q1 Magnitute at start:-5.0 Point Load:-5.0 distance from left end:0.0 Lengtht:4.0 Force at end:-5.0 Resulting force:-20.0 is acting 2.0 m from left end of beam.
19+
Name:F1 Magnitute at start:-2.0 Point Load:-2.0 distance from left end:2.0 Lengtht:0.0 Force at end:-2.0 Resulting force:-2.0 is acting 2.0 m from left end of beam.
20+
21+
RESULT:
22+
Left support:11.0 N. Right bearing:11.0 N.
23+
Horizontal force at right support:0.0
24+
Term:N=0.00N
25+
Term:B (Right)=5.0N x 4.0m + 2.0N + (-11.00N) = 11.00N
26+
Term:A (Left)=(5.0 N/m x 4.0m x 1.0m+2.0N x 1.0m)/2.0m = 11.00N
27+
28+
=== Shearing forces => Q ===
29+
Local maxi-/ minima
30+
Points of disconuity in Q
31+
x=0.0 m Q=-0.01 N
32+
x=1.0 m Q=5.995000000000084 N
33+
x=2.0 m Q=-1.0099999999998097 N
34+
x=3.0 m Q=4.990000000000296 N
35+
x=3.9999999999996705 m Q=-0.009999999999619792 N
36+
Zero points in Q
37+
x=0.9980000000000008 m
38+
x=1.9989999999998906 m
39+
x=2.9989999999997807 m
40+
x=3.9979999999996707 m
41+
42+
=== Bending moment => M ===
43+
Local maxi-/ minima
44+
x=0.0 m M=0.0 Nm
45+
x=0.9980000000000008 m M=-2.5049725149999653 Nm
46+
x=1.9989999999998906 m M=0.9970029950001726 Nm
47+
x=2.9989999999997807 m M=-2.5269875049995836 Nm
48+
x=3.9979999999996707 m M=-0.018966014999237325 Nm
49+
Points of disconuity in M
50+
x=0.9990000000000008 m M=-2.488004504999965 Nm
51+
x=1.9999999999998905 m M=0.991985000000173 Nm
52+
x=2.9999999999997806 m M=-2.4890234999995826 Nm
53+
Zero points in M
54+
x=0.0 m
55+
x=1.5339999999999419 m
56+
x=2.4569999999998404 m
57+
x=3.9999999999996705 m
58+
59+
=== Normal forces => N ===
60+
x=2.0 m N[N]=0.0 NBeam Calc
61+
4662

4763
![](LeadingSigns.png)
4864

Readme.md~

+34-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,40 @@ Beam and acting loads
99

1010
Sample output
1111
-------------
12-
![](Shot_1.png)
12+
Beam:
13+
Length=4.0
14+
Supports sorted by distance from left end of beam:
15+
Support A (Left) xn=0.0
16+
Support B (Right) xn=4.0
17+
18+
Number of Loads:2
19+
Loads sorted by distance from left end of beam:
20+
Name:q1 Magnitute at start:-5.0 Point Load:-5.0 distance from left end:0.0 Lengtht:4.0 Force at end:-5.0 Resulting force:-20.0 is acting 2.0 m from left end of beam.
21+
Name:F1 Magnitute at start:-2.0 Point Load:-2.0 distance from left end:2.0 Lengtht:0.0 Force at end:-2.0 Resulting force:-2.0 is acting 2.0 m from left end of beam.
22+
23+
RESULT:
24+
Left support:10.707106781186548 N. Right bearing:10.707106781186548 N.
25+
Horizontal force at right support:1.414213562373095
26+
Term:N=2.0 N x sin(45.0) = 1.41N
27+
Term:B (Right)=5.0N x 4.0m + 2.0N x cos(45.0) + (-10.71N) = 10.71N
28+
Term:A (Left)=(5.0 N/m x 4.0m x 2.0m+2.0N x cos(45.0) x 2.0m)/4.0m = 10.71N
29+
30+
=== Shearing forces => Q ===
31+
Local maxi-/ minima
32+
Points of disconuity in Q
33+
x=0.0 m Q=10.706106781186547 N
34+
x=2.0 m Q=-0.7081067811881641 N
35+
x=4.0 m Q=-5.000000032335805E-4 N
36+
37+
=== Bending moment => M ===
38+
Local maxi-/ minima
39+
x=1.9998999999997962 m M=11.410643101686322 Nm
40+
Points of disconuity in M
41+
x=0.0 m M=0.0 Nm
42+
x=1.9999999999997962 m M=11.410289362442864 Nm
43+
44+
=== Normal forces => N ===
45+
x=2.0 m N[N]=-1.414213562373095 N
1346

1447
![](LeadingSigns.png)
1548

Shot_0.png

-572 Bytes
Loading

bin/MainBeamCalculator.class

411 Bytes
Binary file not shown.
104 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
Binary file not shown.

src/MainBeamCalculator.java

+15-3
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ public static void main(String[] args) {
1919

2020
// Create a new beam
2121
Beam myBeam = new Beam(4);
22-
myBeam.addBearing(new Support("A (Left)", 0, Support.ROLLER_SUPPORT));
23-
myBeam.addBearing(new Support("B (Right)", 4, Support.PIN_SUPPORT));
22+
myBeam.addBearing(new Support("A (Left)", 1, Support.ROLLER_SUPPORT));
23+
myBeam.addBearing(new Support("B (Right)", 3, Support.PIN_SUPPORT));
2424

2525
// Add load
2626
// NAME/ Force/ Distance/ Angle /Length
27-
myBeam.addLoad(new Load("F1", -2.0, 1.5, 0, 0));
27+
myBeam.addLoad(new Load("F1", -2.0, 2, 0, 0));
2828
myBeam.addLoad(new Load("q1", -5, 0, 0,4));
2929

3030

@@ -89,6 +89,12 @@ public static void main(String[] args) {
8989
for (StressResultant r:dis)
9090
System.out.println("x=" + r.getX_m() + " m Q=" + r.getShearingForce()+" "+r.getUnit());
9191

92+
List <StressResultant> zero=new ArrayList<>();
93+
zero=qTable.getZeroPoints();
94+
System.out.println("Zero points in Q");
95+
for (StressResultant r:zero)
96+
System.out.println("x=" + r.getX_m() + " m");
97+
9298
StressResultantDraw d=new StressResultantDraw("Q",myBeam,qTable,600,1200,10,10,"%.2f");
9399
d.draw();
94100

@@ -110,6 +116,12 @@ public static void main(String[] args) {
110116
for (StressResultant r:dis)
111117
System.out.println("x=" + r.getX_m() + " m M=" + r.getShearingForce()+" "+r.getUnit());
112118

119+
zero=new ArrayList<>();
120+
zero=mTable.getZeroPoints();
121+
System.out.println("Zero points in M");
122+
for (StressResultant r:zero)
123+
System.out.println("x=" + r.getX_m() + " m");
124+
113125
StressResultantDraw m=new StressResultantDraw("M",myBeam,mTable,600,1200,10,10,"%.2f");
114126
m.draw();
115127

src/org/berthold/beamCalc/MSolver.java

+12-15
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,21 @@ public static StressResultantTable solve(StressResultantTable qTable, Beam beam,
4444
double sectionLength_m = mTable.getSectionLength_m();
4545
double x = 0;
4646

47+
mTable.getShearingForceAtIndex(0).setMaxima(true);
48+
4749
for (int n = 0; n <= qTable.getLength() - 2; n++) {
4850

4951
q_N = qTable.getShearingForceAtIndex(n).getShearingForce();
5052

5153
q1_N = qTable.getShearingForceAtIndex(n + 1).getShearingForce();
5254
double deltaQ_N = q1_N - q_N;
5355

54-
// Checks if leading sign changes or if there is an discontiunuity
55-
// if so, disregard....
56-
// if (Math.signum(q_N) == Math.signum(q1_N) && Math.abs(deltaQ_N)
57-
// <= DISCONTIUNUITY_THRESHOLD) {
5856
m_Nm = q_N * x;
5957
m1_Nm = q1_N * (x + sectionLength_m);
6058
deltaM_Nm = m1_Nm - m_Nm;
61-
// } else {
62-
63-
// }
6459

6560
m_Nm = mTable.getShearingForceAtIndex(n).getShearingForce();
66-
mTable.getShearingForceAtIndex(n+1).setShearingForce(m_Nm + deltaM_Nm);
61+
mTable.getShearingForceAtIndex(n + 1).setShearingForce(m_Nm + deltaM_Nm);
6762

6863
// Check for zero points in Q(x). Zero points are local
6964
// maxima in M(x).
@@ -72,18 +67,20 @@ public static StressResultantTable solve(StressResultantTable qTable, Beam beam,
7267

7368
// Check for disconuinity in Q(x) because
7469
// M(x) must also be a diconuinity or a local maxima/ minima
75-
if (qTable.getShearingForceAtIndex(n).isDiscontiunuity()) {
76-
if (!mTable.getShearingForceAtIndex(n).isMaxima()){
77-
mTable.getShearingForceAtIndex(n).setDiscontiunuity(true);
70+
if (qTable.getShearingForceAtIndex(n).isDiscontiunuity() && !mTable.getShearingForceAtIndex(n).isMaxima()) {
71+
mTable.getShearingForceAtIndex(n).setDiscontiunuity(true);
7872
mTable.getShearingForceAtIndex(n).setShearingForceDeltaBy(m_Nm + deltaM_Nm);
79-
}
8073
}
74+
75+
if (Math.signum(mTable.getShearingForceAtIndex(n).getShearingForce()) != Math.signum(mTable.getShearingForceAtIndex(n+1).getShearingForce()))
76+
mTable.getShearingForceAtIndex(n).setZeroPoint(true);
77+
8178
// Next
8279
x = x + sectionLength_m / (1 / sectionLength_m);
8380
}
84-
85-
mTable.getShearingForceAtIndex(mTable.getLength()-1).setShearingForce(0);
86-
mTable.getShearingForceAtIndex(mTable.getLength()-1).setZeroPoint(true);
81+
82+
mTable.getShearingForceAtIndex(mTable.getLength() - 1).setShearingForce(0);
83+
mTable.getShearingForceAtIndex(mTable.getLength() - 1).setZeroPoint(true);
8784
return mTable;
8885
}
8986
}

src/org/berthold/beamCalc/QSolver.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class QSolver {
4242
*
4343
*/
4444
public static StressResultantTable solve(Beam beam, String unit) {
45-
double sectionLength_m = .0001; // Small values lead to more precise results.
45+
double sectionLength_m = .001; // Small values lead to more precise results.
4646

4747
BeamResult result = BeamSolver.getResults(beam, "2f");
4848

src/org/berthold/beamCalc/StressResultantDraw.java

-24
Original file line numberDiff line numberDiff line change
@@ -168,35 +168,11 @@ public void draw() {
168168

169169
String shFormated;
170170

171-
/*
172-
if (r.isDiscontiunuity() && r.isMaxima()) {
173-
graphics.setColor(Color.GRAY);
174-
graphics.drawLine((int) getXT(x), padY_px, (int) getXT(x),
175-
height_px - padY_px + PADDING_TOP_PX);
176-
graphics.setColor(Color.RED);
177-
shFormated = String.format(numberFormat, r.getShearingForce());
178-
graphics.drawString(shFormated + " " + r.getUnit(), (int) getXT(x), (int) getYT(y));
179-
} else {
180-
if (r.isMaxima()) {
181-
graphics.setColor(Color.BLUE);
182-
graphics.drawLine((int) getXT(x), padY_px, (int) getXT(x), height_px - padY_px + PADDING_TOP_PX);
183-
shFormated = String.format(numberFormat, r.getShearingForce());
184-
graphics.drawString(shFormated + " " + r.getUnit(), (int) getXT(x), (int) getYT(y));
185-
}
186-
}
187-
*/
188171
if (r.isDiscontiunuity()|| r.isMaxima() || r.isZeroPoint()) {
189-
/*
190-
graphics.setColor(Color.GRAY);
191-
graphics.drawLine((int) getXT(x), padY_px, (int) getXT(x),
192-
height_px - padY_px + PADDING_TOP_PX);
193-
*/
194172
graphics.setColor(Color.RED);
195173
shFormated = String.format(numberFormat, r.getShearingForce());
196174
graphics.drawString(shFormated + " " + r.getUnit(), (int) getXT(x), (int) getYT(y));
197175
}
198-
199-
200176
yLast = y;
201177
xLast = x;
202178
}

0 commit comments

Comments
 (0)