design, construction, and testing of a truss structure · 2020. 1. 8. · design, construction, and...

37
Design, Construction, and Testing of a Truss Structure ASEN 2001 Statics, Structures, and Materials Experimentation Lab Group 7, Section 014 - November 06, 2017 Jacob Siegel, * Jarrod Puseman, Alec Bosshart, Caleb Sytner § University of Colorado - Boulder * 105675030 104003252 107045778 § 106105221 ASEN 2001 Section 014 1 of 37 Fall 2017

Upload: others

Post on 25-Jan-2021

6 views

Category:

Documents


0 download

TRANSCRIPT

  • Design, Construction, and Testing of a TrussStructure

    ASEN 2001 Statics, Structures, and MaterialsExperimentation Lab

    Group 7, Section 014 - November 06, 2017

    Jacob Siegel, ∗ Jarrod Puseman, † Alec Bosshart, ‡ Caleb Sytner §

    University of Colorado - Boulder

    ∗105675030†104003252‡107045778§106105221

    ASEN 2001 Section 014 1 of 37 Fall 2017

  • This lab explored the statics and engineering that goes into designing a truss. Teamsin this lab were required to design, fabricate, integrate and test a truss structure. Thetrusses then entered competition with trusses built by peers to see which trusses could spanthe farthest distance and hold the most weight. The lab incorporated code to calculatethe forces in members of a truss, uncertainty analysis, and sensitivity analysis. The riskof truss failure and performance of truss design was also balanced by teams. Trusseswere additionally required to meet specific design requirements and follow strict materialsbudgeting.

    Nomenclature

    A = Matrix of coefficients for all unknown forces in a trussk = Safety Factor -

    FbreakingFallow

    I. Introduction

    For this lab, a competitive environment was created between peers for the design and building of atruss structure. The objective was to apply analysis methods and the product development cycle to theconstruction of a truss. The analysis methods include computational tool development using MATLAB,analysis of uncertainty and sensitivity of a structure, and balancing risk and performance of a design. Thecomputation tool development included creating MATLAB code to examine the forces on the joints of atruss in 3-dimensions. Then, the team split into two sub-teams to create two different virtual truss designs.The forces were analyzed on each design and the more adequate design was chosen to be the final design.This final design was constructed and tested on the day of the competition. The following report willelaborate on the details involved in the design, fabrication, and testing of the truss structure. Analyses,design information, and validation will be presented to explain the entire process.

    II. Design Analyses

    II.A. Concept Models

    Before any trusses were designed or built, we explored some simpler models to get a feel for how the trussesbehave and what needs to be accomplished. For example, trusses built with the practice kits explored squarebases, triangular bases, trying to extend the structure, and where to add diagonal bars for support acrosssquare faces. When designing these concept models, the regions of the truss that take the largest loadswhere often joints with many bars connected and bars near the support reactions. Overall the best planwas discovered to be using a design based on triangles and avoiding designs where a truss can pivot abouta point or axis.

    II.B. Detailed Design and Computational Analyses

    Once the basic ideas for designing a truss is understood, a more thorough design and process is necessary.Using some provided truss-analysis code provided [1] as a base, a system of code was developed to analyzetrusses in 3D. This analysis tool uses the method of joints to solve the bar forces in each member.

    For this analysis, the group split into two subgroups to each develop an analysis tool. Both subgroupsused the provided code as a base to work from and use an overall similar structure. The codes start witha parent-function wherein several sub-functions do separate tasks of the analysis process. Both subgroupsstart with converting an argument input file into a system of matrices and vectors that can be used toactually calculate forces in a truss. Essentially, this function goes line by line through the input file and addswhatever information is on that line to the appropriate storage variable. Each code does this a similar waybased on the provided base code.

    To design an effective truss analysis tool, the weight of the truss itself must also be considered andthis was handled this by adding these weights right before the variables are passed back to the calculation

    ASEN 2001 Section 014 2 of 37 Fall 2017

  • function. Essentially, the weight of each bar is found using a measured linear density and calculating thelength and multiplying these. Half the weight of the bar is then added as an external load at each joint towhich the bar is connects. The weight of a magnet is also added at each end of a bar and each joint getsthe additional load of one of the steel bearings used. Once these loads have been considered, all the data ispassed back to the main function.

    The next step in the analysis process is actually calculating the forces in the beams; this is accomplishedin a sub-function designed specifically for it. The methodology to actually calculate the forces is based on themethod of joints. Essentially the x, y, and z equilibrium equations for forces acting at every joint are all onebig system of equations. To solve this massive system, the simple matrix method is used. In linear algebra,a common problem has the form Ax = b where A is a matrix and x and b are vectors. In this applicationto trusses, A is a matrix of the coefficients to each unknown force, x is the vector of each unknown force,and b is the resultant force each of the other forces sum to. This system can be solved by left-multiplyingeach side of the equation by A−1 to get x = A−1 ∗b. The vector x now has the magnitude of each reactionforce in the truss.

    After the forces in the truss are calculated, the results are printed to an output file and plotted by twomore sub-functions respectively.

    Using this setup to analyze any trusses we design, both subgroups experimented with the small details oftruss design such as joint location and where exactly the members of a truss would go. For example, jointswere moved closer together when tension forces in the bottom became too large. Another instance may beraising the uppermost joints to ease some of the compressive forces in the truss. This process is describedfurther in section III of the report.

    II.C. Sensitivity Analysis

    The design process also included handling uncertainty and sensitivity. Since the truss is actually to beconstructed, it will not be the exact same as the design. There are variation in joint strength, joint location,member strength, and many other factors such as just being uncertain how to model certain phenomena.

    It is quite necessary then to consider these variations and uncertainties in the design process. A safetyfactor is chosen to provide a ratio of the maximum allowable force to the actual expected breaking force.By designing a truss using a safety factor, we give the truss a margin of safety for these variations to occurand not cause the truss to fail. The process for choosing a safety factor in this lab began with choosing anarbitrary acceptable percent chance of failure. For example, the selected truss used a 1% chance of failureto be acceptable. From here, a maximum allowable force is calculated using a normal distribution statisticcalculator. The MATLAB function icdf handles this calculation considering the mean joint strength, thestandard deviation of that strength, and our desired failure probability. Once it has calculated the force withonly 1% of the distribution below that force, this becomes the highest force we will allow to be present in ourtruss during the design process. To calculate the safety factor k itself, the breaking strength is divided bythe allowable force we calculated. This safety factor is typically between 1.2 and 3 for common engineeringapplications depending on what is being built and how much risk it gives to human life. To maximize thedistance spanned by the designs, the safety factor used in this lab was on the lower end of engineeringsafety factors. Using the 1% chance of failure from above, the calculated safety factor was 1.24, very low forcommon engineering but acceptable for this lab since the consequences of structure failure are minimal.

    To address the sensitivity of the truss designs to these general variations, a MATLAB script was modifiedto run a Monte Carlo simulation on the truss. In this script, the joint strength and joint location are allowedto vary and the effect of such is observed. In the scripts developed by the two subgroups, each follows asimilar pattern. Initially, the truss baseline data is read into matrices from the same input file passed intothe analysis function. Once the truss base line is read into MATLAB, the Monte Carlo simulation slightlyalters the joint strength and the location of the joints. Then the simulation runs the analysis on this slightlyaltered truss, recording the maximum bar force in the truss and whether this would cause the truss to fail.Doing this 10,000 times, the simulation tracks each truss variation’s success and failure. It then plots themaximum bar force in a histogram and reports the failure percentage. If the truss was designed such thatthe maximum force is normally about the allowable maximum force from the safety factor, then the failurepercentage should be around the chosen percentage for the safety factor.

    Joint SensitivityFor Jacob Siegel and Jarrod Puseman’s truss, the Monte Carlo simulation revealed that the failure

    percentage was very small (about .001 or .1%). This is because the bar length was the limiting factor to

    ASEN 2001 Section 014 3 of 37 Fall 2017

  • this truss instead of the joint strength. This truss is also very sensitive to the joint location. In figure 1a,the histogram looks very unusual. The histogram shows many occurrences of a maximum force close to 0,but there are also a few maximum forces in the realm of hundreds of newtons. This is discussed more insection V, but this reveals how sensitive this design was to the joint location. When the truss would fail, itwas often by a large margin over the standard 4.8 N joint strength.

    Caleb Sytner and Alec Bosshart’s truss, however, was much more resistant to variation in joint location.The Monte Carlo simulation for their truss looks much more like a standard distribution, indicating theforces are similar despite joint location variation. This is shown in Fig. 1b.

    (a) Monte Carlo Simulation, Siegel and Puseman ThisMonte Carlo simulation demonstrates the sensitivity of thistruss to joint location. See how the simulation occasionallycalculated maximum forces of hundreds of Newtons.

    (b) Monte Carlo Simulation, Bosshart and SytnerThis truss is much less sensitive to joint location. See how theforces are more evenly distributed. They are not dependenton joint location like the first truss.

    Figure 1: Monte Carlo Simulation for Sensitivity Analysis

    III. Truss Design

    Two different trusses were designed in this lab. The first truss was designed by Jacob Siegel and JarrodPuseman. As can be seen in the diagram below, it utilized a more abstract design.

    Figure 2: First Truss Design

    This truss design had seven joints and fifteen bars, and used a three-point base. It spanned a base-to-basedistance of 30 inches. Using the truss analysis tool developed in MATLAB, we were able to see that themaximum tensile load in the bars was 0.559 Newtons and the maximum compressive load was 0.735 Newtons.

    ASEN 2001 Section 014 4 of 37 Fall 2017

  • A desired failure probability of 10 percent was chosen for this design, and with this failure probability a factorof safety of 1.11 was calculated. We used this factor of safety to calculate the maximum desired memberforce for this truss design, which was 4.28 Newtons. We also used a Monte Carlo simulation, which wasdesigned in MATLAB, to find the true probability of failure, which was 0.13 percent. The critical joints inthis design were joints 4, 5, and 6 (see Fig. 2), as these were the joints connected to the members in themost tension.

    The second truss was designed by Alec Bosshart and Caleb Sytner. This truss was based on a moretraditional truss design.

    Figure 3: Second Truss Design

    Note that the back of the truss starts at an x-coordinate of -5 instead of 0. This design had 13 joints and33 bars, and had a three-point base. It spanned a base-to-base distance of 42.8 inches. Having selected adesired failure probability of one percent, a factor of safety of 1.25 was selected. From this factor of safety amaximum desired member force of 3.87 Newtons was calculated. Using the truss analysis tool, the maximumtensile force in the members was seen to be 2.165 Newtons and the maximum compressive force was 3.940Newtons. Although the maximum compressive member force is greater than the maximum desired force, wedecided it was allowable for three reasons, the first of which being that the maximum member compressiveforce was not greater than the maximum desired force by a large margin. The second reason is that themaximum force in the magnets connecting the members was tested to be 4.8 Newtons with a standarddeviation of 0.4 Newtons. This means that the minimum strength in the magnets can be expected to be 4.4Newtons, and the maximum member force is a fair amount smaller than this. The final reason for allowingthis design to go through is that the maximum member force of 3.940 Newtons was in compression. Magnetsare typically much stronger in compression than in tension, and the maximum magnet force of 4.8 Newtonswas measured in tension. The maximum tensile force in the truss was only 2.165 Newtons, and this wasunder the maximum desired force by a large margin. When this design was put through a Monte Carlosimulation, the true failure probability was shown to be 7.21 percent. The critical joints in this design werejoints 10 and 3, as joint 10 had the highest compressive force member attached to it, and joint three had thehighest tensile force members attached to it.

    The design we chose to construct was the second truss. The first reason for this was that it spanned agreater distance and could be scaled up easier than the first truss. While the first truss could have beenscaled up to span a greater distance, it was limited by the number of bars in the size class, and because ofthis it could never span a greater distance than the second truss. The other reason we chose to build thesecond truss was that the first truss had a strange distribution in the Monte Carlo simulation, as can be seenin Fig. 1(a). In some of the random variations in the Monte Carlo simulation, members had extraordinarilyhigh forces in them. The combination of this and the greater length of the second truss were the driving

    ASEN 2001 Section 014 5 of 37 Fall 2017

  • force behind our decision to select it as the truss to be constructed. When this truss was built and tested,it spanned a base-to-base distance of 43.5 inches and held a maximum external load of 650 grams.

    IV. Model Validation

    A critical process in the development of structures is the verification of the modeling assumptions. Intypical engineering process, multiple rounds of testing are performed to validate assumptions as the de-velopment process occurs, but in this case, only the final design was used for testing. This increased theimportance of the prefabrication process. The MATLAB code that was developed was often examined forcorrectness to ensure a valid design.

    Throughout this lab, the team’s main focus was ensuring the truss held it’s own weight over the 43.5inches that it was designed to span. Assuming the truss would remain stable, the team looked into addingweight to the truss as part of the competition against other trusses entered into the contest. This was donein MATLAB by adding external forces to the strongest joints of the truss. The team found that there was apossibility of the bridge holding a max of 400 grams of weight at the strongest joint and 100 grams of weightat the rest of the joints on the top of the truss.

    On test day, as mentioned in a previous section, the truss spanned 43.5 inches supporting its own weight.Weight was slowly added to the truss to validate the code. The truss ended up holding an additional 650grams. It held less than what was inputted into the code, but this is likely because the probability offailure increased as weight was added and the truss failed because of it. Although the truss did not hold theadditional weight that was predicted, it did pass the requirement of holding it’s own weight while spanningthe anticipated length of 43.5 inches. This validates the assumptions that were made based off of the codein the design process.

    V. Discussion

    One key issue with the theoretical portion of the lab was that the safety factor and maximum loadaround were designed around the largest force present in any member. However, as mentioned previously,the failure in the design does not necessarily come from the largest force present. It should come from thelargest tension force present. Failure will always occur at the joints in this lab because the carbon fiber rodsare considerably stronger than the magnets used to hold it together. These magnetic joints are also quitestrong in compression, but not in tension. The magnets are pulling the members together, so a compressiveforce aids them in doing this. Tension opposes the force of the magnets, which will cause failure more easily.Therefore a member in compression that is experiencing a large force will not necessarily fail, but a memberexperiencing a large tension force will fail. We have designed the maximum force our truss can handle aroundthe maximum tension force experienced.

    As stated, we chose Design 2 as our implemented truss design. This is largely because Design 1 hadunnecessary weight leaning behind the locations of the supports on the ground. It was extra weight thatdid not contribute to the length the design was able to span. Any effects on easing the compression onthe opposite side of the truss were considered not worth the weight cost to get. Design 2 looks more likea traditional truss present in actual buildings/structures, and this is because these designs work well. Anactual bridge is going to be designed as efficiently as possible, and able to handle large loads, so we used themas inspiration. Another key reason we chose Design 2 was that Design 1 had a very unusual Monte-Carlosimulation. It showed extreme forces (in the magnitude of hundreds of Newtons), and this likely due tothe fact that it had few members and few joints. So, even a slight variance in a couple of joints could leadto massive differences in the forces in each member. Consultation with TA’s verified that the Monte-Carlosimulation results was due to the small number of joints and members.

    Overall, we feel that our truss preformed well. Our calculated maximum external weight was larger thanthe weight we were able to add, but this was due to the fact that we could not add the weight at our desiredlocations because it would not fit inside of our truss. We found that our upper members were able to supportthe most weight, which makes sense. Our design would be able to distribute the load on the upper membersamong multiple lower members, reducing the overall load on each lower member (where our failure wouldalways occur). Because the upper members were all in compression, they never failed. Although fabricationimperfections could have contributed to the failure of our design, we are not able to know because ourmaximum calculated weight was not applied at the locations we wanted, but our truss was able to support

    ASEN 2001 Section 014 6 of 37 Fall 2017

  • its own weight easily.We decided that the factor of safety depends largely on the application. Here, we kept a relatively small

    factor of safety, so our design would fail around 7% of the time. This is prioritizing safety over performance,but an actual bridge would want to prioritize safety much more. Because no human life was involved, andthe cost of the truss isn’t very large, failure isn’t a terrible thing. In an actual bridge, where failure couldcost lives and millions of dollars, failure is a much bigger deal. So, we pushed performance over safety.

    VI. Conclusion

    In conclusion, our truss was able to span 43.5 inches, and handled a maximum load of 650 grams. Thisdesign was the product of multiple steps of calculations, beginning with developing a code to determinethe maximum force within a truss design. Next, tests were conducted with some scale members to beginfiguring out conceptual design elements to incorporate into our actual truss. Once this was completed, wedeveloped two trusses independently, and chose the more traditional truss design. We then had to scale allof our members so that all of the forces in the members were below our maximum force allowed, which wascalculated using a safety factor. Also, the design had to fit within limitations of the lengths of members wehad at hand. Once the theoretical portion was completed, the truss was constructed. The physical truss thenwent through an experimental process, where it supported its own weight and an external load. Although theexternal load was not quite as large as the calculated maximum external force, it still supported a respectableamount of weight for its length. It likely could have supported its calculated maximum weight, but logisticalspace issues limited our load at the calculated points. Overall, we consider our truss experiment a success.

    ASEN 2001 Section 014 7 of 37 Fall 2017

  • References

    1Jackson, Jellife. Design, Construction, and Testing of a Truss Structure. CU, 2017. PDF.

    Appendix A: MATLAB Code

    Below is the compilation of code created by Jacob Siegel and Jarrod Puseman.

    1 func t i on truss3dmcs ( i n p u t f i l e , o u t p u t f i l e )2 % func t i on t rus s3d ( i n p u t f i l e )3 %4 % S t o c h a s t i c a n a l y s i s o f 3−D s t a t i c a l l y determinate t r u s s by5 % Monte Carlo Simulat ion . Only p o s i t i o n s and s t r ength o f j o i n t s6 % tr ea t ed as random v a r i a b l e s .7 %8 % This a l s o w i l l c r e a t e an image o f what the t r u s s l ooks l i k e in i t s i d e a l9 % s t a t e .

    10 %11 % Assumption : v a r i a t i o n o f j o i n t s t r ength and p o s i t i o n s de s c r ibed12 % via Gaussian d i s t r i b u t i o n s13 %14 % j o i n t s t r ength : mean = 1515 % c o e f f i c i e n t o f vara t i on = 0 .116 % j o i n t p o s i t i o n :17 % c o e f f i c i e n t o f vara t i on = 0.0118 % ( de f ined wrt to maximum dimension o f t r u s s )19 %20 % number o f samples i s s e t to 1e421 %22 % Input : i n p u t f i l e − name o f input f i l e23 %24 % Author : Kurt Maute f o r ASEN 2001 , Oct 13 201225 % Modif ied by Jacob S i e g e l and Jarrod Puseman f o r the t r u s s des ign lab in26 % ASEN 2001 at the Un ive r s i ty o f Colorado Boulder2728 % parameters29 jstrmean = 4 . 8 ; % mean o f j o i n t strength , sigma = . 430 j s t r c o v = 0 . 0 9 ; % c o e f f i c i e n t o f v a r i a t i o n o f j o i n t s t r ength31 jposcov = 0 . 0 1 ; % c o e f f i c i e n t o f v a r i a t i o n o f j o i n t p o s i t i o n32 numsamples = 1e4 ; % number o f samples33343536 % read input f i l e37 [ j o i n t s , connec t i v i ty , r e a c j o i n t s , reacvecs , l o a d j o i n t s , l oadvecs ]= readinput3D (

    i n p u t f i l e ) ;3839 % Compute f o r c e s in bars and r e a c t i o n s40 [ ba r f o r c e s , r e a c f o r c e s ]= f o r c e an a l y s i s 3 D ( j o i n t s , connec t i v i ty , r e a c j o i n t s , reacvecs

    , l o a d j o i n t s , l oadvecs ) ;4142 % Write output f i l e43 writeoutput3D ( o u t p u t f i l e , i n p u t f i l e , ba r f o r c e s , r e a c f o r c e s , j o i n t s , connec t i v i ty ,

    r e a c j o i n t s , reacvecs , l o a d j o i n t s , l oadvecs ) ;4445 % Plot t r u s s

    ASEN 2001 Section 014 8 of 37 Fall 2017

  • 46 p lot t rus s3D ( j o i n t s , connec t i v i ty , ba r f o r c e s , loadvecs , r e a c j o i n t s , r e a c f o r c e s ,reacvecs , 3 ∗ [ 0 . 0 2 5 , 0 . 0 4 , 0 . 0 5 ] , [ 1 1 0 0 ] )

    474849 % determine extens i on o f t r u s s50 ext x=max( j o i n t s ( : , 1 ) )−min ( j o i n t s ( : , 1 ) ) ; % extens i on in x−d i r e c t i o n51 ext y=max( j o i n t s ( : , 2 ) )−min ( j o i n t s ( : , 2 ) ) ; % extens i on in y−d i r e c t i o n52 e x t z=max( j o i n t s ( : , 3 ) )−min ( j o i n t s ( : , 3 ) ) ; % extens i on in z−d i r e c t i o n53 ext =max ( [ ext x , ext y , e x t z ] ) ;5455 % loop o v e r a l l samples56 numjoints=s i z e ( j o i n t s , 1 ) ; % number o f j o i n t s57 maxforces=ze ro s ( numsamples , 1 ) ; % maximum bar f o r c e s f o r a l l samples58 maxreact=ze ro s ( numsamples , 1 ) ; % maximum support r e a c t i o n s f o r a l l samples59 f a i l u r e=ze ro s ( numsamples , 1 ) ; % f a i l u r e o f t r u s s6061 f o r i s =1:numsamples6263 % generate random j o i n t s t r ength l i m i t64 var s t r ength = ( j s t r c o v ∗ j strmean ) ∗ randn (1 , 1 ) ;6566 j s t r e n g t h = jstrmean + var s t r ength ;6768 % generate random samples69 v a r j o i n t s = ( jposcov ∗ ext ) ∗ randn ( numjoints , 3 ) ;7071 % perturb j o i n t p o s i t i o n s72 r a n d j o i n t s = j o i n t s + v a r j o i n t s ;7374 % compute f o r c e s in bars and r e a c t i o n s75 [ ba r f o r c e s , r e a c f o r c e s ] = f o r c e a na l y s i s 3 D ( rand jo in t s , connec t i v i ty ,

    r e a c j o i n t s , reacvecs , l o a d j o i n t s , l oadvecs ) ;767778 % determine maximum f o r c e magnitude in bars and supports79 maxforces ( i s ) = max( abs ( b a r f o r c e s ) ) ;80 maxreact ( i s ) = max( abs ( r e a c f o r c e s ) ) ;8182 % determine whether t r u s s f a i l e d83 f a i l u r e ( i s ) = maxforces ( i s ) > j s t r e n g t h | | maxreact ( i s ) > j s t r e n g t h ; %We

    can ignore the magnitude o f the r e a c t i o n f o r c e s because the t r u s s j u s tr e s t s on the p l a t e s − i t does not magnet i ca l l y attach to the p l a t e

    84 end85 %maxforces ( maxforces >10) = [ ] ;8687 f i g u r e (2 ) ;88 subplot ( 1 , 2 , 1 ) ;89 h i s t ( maxforces , 3 0 ) ;90 t i t l e ( ' Histogram of maximum bar f o r c e s ' ) ;91 x l a b e l ( ' Magnitude o f bar f o r c e s ' ) ;92 y l a b e l ( ' Frequency ' ) ;9394 subplot ( 1 , 2 , 2 ) ;95 h i s t ( maxreact , 3 0 ) ;96 t i t l e ( ' Histogram of maximum support r e a c t i o n s ' ) ;

    ASEN 2001 Section 014 9 of 37 Fall 2017

  • 97 x l a b e l ( ' Magnitude o f r e a c t i o n f o r c e s ' ) ;98 y l a b e l ( ' Frequency ' ) ;99

    100101 f i g u r e (3 ) ;102 h i s t ( maxforces , 3 0 ) ;103 t i t l e ( ' Histogram of maximum bar f o r c e s ' ) ;104 x l a b e l ( ' Magnitude o f bar f o r c e s ' ) ;105 y l a b e l ( ' Frequency ' ) ;106 f p r i n t f ( ' \ nFa i lu re p r o b a b i l i t y : %e \n\n ' , sum( f a i l u r e ) /numsamples ) ;107108109 %% Safety Factor Calculator110111 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%112 %This s c r i p t s imply handles the f a c t o r o f s a f e t y c a l c u l a t i o n f o r the t r u s s113 %des ign lab f o r ASEN 2001 .114 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%115116117 %Created by Jarrod Puseman118 %20 Oct 2017119 %ASEN 2001 Lab 2120 %Dr . Jackson /Dr . Neogi121 %Last Revised : 20 Oct 2017122123124 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%125 %D e f i n i t i o n o f Constants126 mu=4.8; %Average j o i n t s t r ength [N]127 sigma =.4; %Standard dev i a t i on o f j o i n t s t r ength [N]128 P=.01; %Des i red f a i l u r e p r o b a b i l i t y129130 %Backwards c a l c u l a t e the maximum a l l owab l e f o r c e131 F des ign=i c d f ( ' normal ' ,P,mu, sigma ) ;132133 %Calcu la te how many standard d e v i a t i o n s t h i s i s134 n=(mu−F des ign ) / sigma ;135136 %Use the number o f d e v i a t i o n s from the mean to c a l c u l a t e the s a f t e y f a c t o r137 k=mu/(mu−n∗ sigma ) ;138 %k = mu/ F des ign ; %Yie ld s the same answer139 end140141 %% ReadInput Function142 func t i on [ j o i n t s , connec t i v i ty , r e a c j o i n t s , reacvecs , newLoadjoints , newLoadvec

    ]= readinput3D ( i n p u t f i l e )143 % func t i on [ j o i n t s , connec t i v i ty , r e a c j o i n t s , reacvecs , l o a d j o i n t s , l oadvecs ]=

    readinput3D ( i n p u t f i l e )144 %145 % read input f i l e146 %147 % input : i n p u t f i l e − name o f input f i l e148 %149 % output : j o i n t s − coo rd ina t e s o f j o i n t s

    ASEN 2001 Section 014 10 of 37 Fall 2017

  • 150 % c o n n e c t i v i t y − c o n n e c t i v i t y151 % r e a c j o i n t s − j o i n t id where r e a c t i o n ac t s on152 % reacvec s − uni t vec to r a s s o c i a t e d with r e a c t i o n f o r c e153 % l o a d j o i n t s − j o i n t id where e x t e r n a l load ac t s on154 % loadvecs − load vec to r155 %156 % Author : Kurt Maute , Sept 21 2011157 % Modif ied by Jake S i e g e l and Jarrod Puseman Oct 2 2017158159 % open i n p u t f i l e160 f i d=fopen ( i n p u t f i l e ) ;161162 i f f i d 0173174 % check i f comment175 i f strcmp ( l i n e (1 ) , '# ' )176 % read next l i n e and cont inue177 l i n e=f g e t l ( f i d ) ;178 cont inue ;179 end180181 switch inpb lk182183 case 1 % read number o f j o i n t s , bars , r e a c t i on s , and loads184185 dims=s s c a n f ( l i n e , '%d%d%d%d%d ' ) ;186187 numjoints = dims (1 ) ;188 numbars = dims (2 ) ;189 numreact = dims (3 ) ;190 numloads = dims (4 ) ;191192 % check f o r c o r r e c t number o f r e a c t i o n f o r c e s193 i f numreact ˜=6; e r r o r ( ' i n c o r r e c t number o f r e a c t i o n f o r c e s ' ) ; end194195 % i n i t i a l i z e a r rays196 j o i n t s = ze ro s ( numjoints , 3 ) ;197 c o n n e c t i v i t y = ze ro s ( numbars , 2 ) ;198 r e a c j o i n t s = ze ro s ( numreact , 1 ) ;199 r eacvec s = ze ro s ( numreact , 3 ) ;200 l o a d j o i n t s = ze ro s ( numloads , 1 ) ;201 loadvecs = ze ro s ( numloads , 3 ) ;202203 % check whether system s a t i s f i e s s t a t i c determinancy cond i t i on204 i f 3∗ numjoints − 6 ˜= numbars

    ASEN 2001 Section 014 11 of 37 Fall 2017

  • 205 % e r r o r ( ' Truss i s not s t a t i c a l l y determinate ' ) ;206 end207208 % expect next input block to be j o i n t coo rd ina t e s209 inpblk = 2 ;210211 case 2 % read coo rd ina t e s o f j o i n t s212213 % increment j o i n t id214 counter = counter + 1 ;215216 % read j o i n t id and coo rd ina t e s ;217 tmp=s s c a n f ( l i n e , '%d%e%e%e ' ) ;218219 % e x t r a c t and check j o i n t id220 j o i n t i d=tmp(1) ;221 i f j o i n t i d >numjoints | | j o i n t i d numbars | | baridnumjoints | | min (tmp ( 2 : 3 ) )

  • 257 i f counter==numbars258 inpblk = 4 ;259 counter = 0 ;260 end261262 case 4 % read r e a t i o n f o r c e in fo rmat ion263264 % increment r e a c t i o n id265 counter = counter + 1 ;266267 % read j o i n t id and uni t vec to r o f r e a c t i o n f o r c e ;268 tmp=s s c a n f ( l i n e , '%d%e%e%e ' ) ;269270 % e x t r a c t and check j o i n t id271 j o i n t i d=tmp(1) ;272 i f j o i n t i d >numjoints | | j o i n t i d numjoints | | j o i n t i d

  • 310311 % expect no a d d i t i o n a l input block312 i f counter==numloads313 inpblk = 99 ;314 counter = 0 ;315 end316317 otherw i se318 f p r i n t f ( ' Warning : unknown input : %s \n ' , l i n e ) ;319 end320321 % read next l i n e322 l i n e=f g e t l ( f i d ) ;323 end324325326 %Now we account f o r the weight o f the bars and b a l l s at the j o i n t s327 b a l l =.0819; %[N]328 magnet =.0164199; %[N] weight o f magnet329 newLoadjoints =(1: numjoints ) ' ;330 newLoadvec=ze ro s ( numjoints , 3 ) ;331 newLoadvec ( : , 3 )=−b a l l ;%Weight o f the b a l l s [N] − a l l in −z d i r e c t i o n332 newLoadvec ( l o a d j o i n t s , : )=newLoadvec ( l o a d j o i n t s , : )+loadvecs ; %Sum our weights

    and prev ious e x t e r n a l l oads333 rho =.00831;%N/ in o f bar334 %Add weight o f bars to the s imu la t i on as we l l as weight o f the s t e e l b a l l s335 f o r i =1:numbars336 weight=rho∗norm( j o i n t s ( c o n n e c t i v i t y ( i , 1 ) , : )− j o i n t s ( c o n n e c t i v i t y ( i , 2 ) , : ) ) ;

    %This assumes337 newLoadvec ( [ c o n n e c t i v i t y ( i , 1 ) c o n n e c t i v i t y ( i , 2 ) ] , 3 ) = newLoadvec ( [

    c o n n e c t i v i t y ( i , 1 ) c o n n e c t i v i t y ( i , 2 ) ] , 3 )−weight/2−magnet ;338 end339 % c l o s e input f i l e340 f c l o s e ( f i d ) ;341342 end343344345 %% Force Analysis346 func t i on [ ba r f o r c e s , r e a c f o r c e s ]= f o r c e a n a l y s i s 3 D ( j o i n t s , connec t i v i ty ,

    r e a c j o i n t s , reacvecs , l o a d j o i n t s , l oadvecs )347 % func t i on [ ba r f o r c e s , r e a c f o r c e s ]= f o r c e a n a l y s i s 3 D ( j o i n t s , connec t i v i ty ,

    r e a c j o i n t s , reacvecs , l o a d j o i n t s , l oadvecs )348 %349 % compute f o r c e s in bars and r e a c t i o n f o r c e s350 %351 % input : j o i n t s − coo rd ina t e s o f j o i n t s352 % c o n n e c t i v i t y − c o n n e c t i v i t y353 % r e a c j o i n t s − j o i n t id where r e a c t i o n ac t s on354 % reacvec s − uni t vec to r a s s o c i a t e d with r e a c t i o n f o r c e355 % l o a d j o i n t s − j o i n t id where e x t e r n a l load ac t s on356 % loadvecs − load vec to r357 %358 % output : b a r f o r c e s − f o r c e magnitude in bars359 % r e a c f o r c e s − r e a c t i o n f o r c e s

    ASEN 2001 Section 014 14 of 37 Fall 2017

  • 360 %361 % Author : Kurt Maute , Sept 21 2011362 % Modif ied by Lab 23A Oct . 2363364 % e x t r a c t number o f j o i n t s , bars , r e a c t i on s , and loads365 numjoints = s i z e ( j o i n t s , 1 ) ;366 numbars = s i z e ( connec t i v i ty , 1 ) ;367 numreact = s i z e ( r e a c j o i n t s , 1 ) ;368 numloads = s i z e ( l o a d j o i n t s , 1 ) ;369370 % number o f equat ions371 numeqns = 3 ∗ numjoints ;372373 % a l l o c a t e ar rays f o r l i n e a r system374 Amat = ze ro s ( numeqns ) ;375 bvec = ze ro s ( numeqns , 1 ) ;376377 % bu i ld Amat − loop over a l l j o i n t s378379 f o r i =1: numjoints380381 % equat ion id numbers382 idx = 3∗ i −2;383 idy = 3∗ i −1;384 idz = 3∗ i ;385386387 % get a l l bars connected to j o i n t388 [ ibar , i j t ]= f i n d ( c o n n e c t i v i t y==i ) ;389390 % loop over a l l bars connected to j o i n t391 f o r ib =1: l ength ( iba r )392393 % get bar id394 bar id=iba r ( ib ) ;395396 % get coo rd ina t e s f o r j o i n t s ” i ” and ” j ” and ”k” o f bar ” bar id ”397 j o i n t i = j o i n t s ( i , : ) ;398 i f i j t ( ib ) == 1399 j i d = c o n n e c t i v i t y ( barid , 2 ) ;400 e l s e401 j i d = c o n n e c t i v i t y ( barid , 1 ) ;402 end403 j o i n t j = j o i n t s ( j i d , : ) ;404405 % compute un i t vec to r po in t ing away from j o i n t i406 v e c i j = j o i n t j − j o i n t i ;407 uvec = v e c i j /norm( v e c i j ) ;408409 % add uni t vec to r in to Amat410 Amat ( [ idx idy idz ] , bar id )=uvec ;411 end412 end413414 % bu i ld c o n t r i b u t i o n o f support r e a c t i o n s

    ASEN 2001 Section 014 15 of 37 Fall 2017

  • 415 f o r i =1:numreact416417 % get j o i n t id at which r e a c t i o n f o r c e ac t s418 j i d=r e a c j o i n t s ( i ) ;419420 % equat ion id numbers421 idx = 3∗ j i d −2;422 idy = 3∗ j i d −1;423 idz = 3∗ j i d ;424425 % add uni t vec to r in to Amat426 Amat ( [ idx idy idz ] , numbars+i )=reacvec s ( i , : ) ;427 end428429 % bu i ld load vec to r430 f o r i =1:numloads431432 % get j o i n t id at which e x t e r n a l f o r c e ac t s433 j i d=l o a d j o i n t s ( i ) ;434435 % equat ion id numbers436 idx = 3∗ j i d −2;437 idy = 3∗ j i d −1;438 idz = 3∗ j i d ;439440 % add uni t vec to r in to bvec ( s i gn change )441 bvec ( [ idx idy idz ] )=−l oadvec s ( i , : ) ;442 end443444 % check f o r i n v e r t a b i l i t y o f Amat445 i f rank (Amat) ˜= numeqns446 e r r o r ( 'Amat i s rank d e f f i c i e n t : %d < %d\n ' , rank (Amat) , numeqns ) ;447 end448449 % s o l v e system450 xvec=Amat\bvec ;451452 % e x t r a c t f o r c e s in bars and r e a c t i o n f o r c e s453 b a r f o r c e s=xvec ( 1 : numbars ) ;454 r e a c f o r c e s=xvec ( numbars+1:end ) ;455456 end457 %% Write Output Function458 func t i on writeoutput3D ( o u t p u t f i l e , i n p u t f i l e , ba r f o r c e s , r e a c f o r c e s , j o i n t s ,

    connec t i v i ty , r e a c j o i n t s , reacvecs , l o a d j o i n t s , l oadvec s )459 % wri teoutput ( o u t p u t f i l e , i n p u t f i l e , ba r f o r c e s , r e a c f o r c e s , j o i n t s , connec t i v i ty ,

    r e a c j o i n t s , reacvecs , l o a d j o i n t s , l oadvecs ) ;460 %461 % output a n a l y s i s r e s u l t s462 %463 % input : o u t p u t f i l e − name o f output f i l e464 % i n p u t f i l e − name o f input f i l e465 % b a r f o r c e s − f o r c e magnitude in bars466 % r e a c f o r c e s − r e a c t i o n f o r c e s467 % j o i n t s − coo rd ina t e s o f j o i n t s

    ASEN 2001 Section 014 16 of 37 Fall 2017

  • 468 % c o n n e c t i v i t y − c o n n e c t i v i t y469 % r e a c j o i n t s − j o i n t id where r e a c t i o n ac t s on470 % reacvec s − uni t vec to r a s s o c i a t e d with r e a c t i o n f o r c e471 % l o a d j o i n t s − j o i n t id where e x t e r n a l load ac t s on472 % loadvecs − load vec to r473 %474 %475 % Author : Kurt Maute , Sept 21 2011476 % Modif ied : Jarrod Puseman and Jake S e i g e l Lab 23A Oct 2 2017477478 % open output f i l e479 f i d=fopen ( o u t p u t f i l e , 'w ' ) ;480481 % wr i t e header482 f p r i n t f ( f i d , '3−D Truss a n a l y s i s \n ' ) ;483 f p r i n t f ( f i d , '−−−−−−−−−−−−−−−−−−\n\n ' ) ;484 f p r i n t f ( f i d , ' Date : %s \n\n ' , d a t e s t r (now) ) ;485486 % wr i t e name o f input f i l e487 f p r i n t f ( f i d , ' Input f i l e : %s \n\n ' , i n p u t f i l e ) ;488489 % wr i t e coo rd ina t e s o f j o i n t s490 f p r i n t f ( f i d , ' Jo in t s : Joint−id x−coord inate y−coord inate z−coord inate \

    n ' ) ;491 f o r i =1: s i z e ( j o i n t s , 1 )492 f p r i n t f ( f i d , '%17d %12.2 f %12.2 f %12.2 f \n ' , i , j o i n t s ( i , 1 ) , j o i n t s ( i , 2 ) , j o i n t s

    ( i , 3 ) ) ;493 end494 f p r i n t f ( f i d , ' \n\n ' ) ;495496 %Write the l eng th s o f the bars497 f p r i n t f ( f i d , ' Length o f the Bars : Bar−id Length\n ' ) ;498 f o r i =1: s i z e ( connec t i v i ty , 1 )499 f p r i n t f ( f i d , '%27d %12.2 f \n ' , i , norm( j o i n t s ( c o n n e c t i v i t y ( i , 1 ) , : )− j o i n t s (

    c o n n e c t i v i t y ( i , 2 ) , : ) ) ) ;500 end501 f p r i n t f ( f i d , ' \n\n ' ) ;502503 % wr i t e e x t e r n a l l oads504 f p r i n t f ( f i d , ' External l oads : Joint−id Force−x Force−y Force−z\n ' ) ;505 f o r i =1: s i z e ( l o a d j o i n t s , 1 )506 f p r i n t f ( f i d , '%17d %12.2 f %12.2 f %12.2 f \n ' , l o a d j o i n t s ( i ) , l oadvec s ( i , 1 ) ,

    l oadvec s ( i , 2 ) , l oadvecs ( i , 3 ) ) ;507 end508 f p r i n t f ( f i d , ' \n ' ) ;509510 % wr i t e c o n n e c t i v i t y and f o r c e s511 f p r i n t f ( f i d , ' Bars : Bar−id Joint−i Jo int−j Force (T,C)

    \n ' ) ;512 f o r i =1: s i z e ( connec t i v i ty , 1 )513 i f b a r f o r c e s ( i ) >0; tc= 'T ' ; e l s e tc= 'C ' ; end514 f p r i n t f ( f i d , '%17d %7d %12d %12.3 f (%s ) \n ' , ...515 i , c o n n e c t i v i t y ( i , 1 ) , c o n n e c t i v i t y ( i , 2 ) , abs ( b a r f o r c e s ( i ) ) , t c ) ;516 end517 f p r i n t f ( f i d , ' \n ' ) ;

    ASEN 2001 Section 014 17 of 37 Fall 2017

  • 518519 % wr i t e c o n n e c t i v i t y and f o r c e s520 f p r i n t f ( f i d , ' React ions : Joint−id Uvec−x Uvec−y Uvec−z

    Force\n ' ) ;521 f o r i =1: s i z e ( r e a c j o i n t s , 1 )522 f p r i n t f ( f i d , '%17d %12.2 f %12.2 f %12.2 f %12.3 f \n ' , r e a c j o i n t s ( i ) , r eacvec s ( i

    , 1 ) , r eacvec s ( i , 2 ) , r ea cvec s ( i , 3 ) , r e a c f o r c e s ( i ) ) ;523 end524525 % c l o s e output f i l e526 f c l o s e ( f i d ) ;527528 end529530 %% PlotTruss 3D531 func t i on p lot t russ3D ( xyz , topo , e f o r c e , loadvec , fbc , r e a c f o r c e s , reacvecs , rads ,

    p l t f l a g s )532 %func t i on p l o t t r u s s ( xyz , topo , e f o r c e , fbc , rads , p l t f l a g s )533 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−534 %535 % p lo t 3−t rus s , bars co l o r ed acco r ing to f o r c e536 % supported nodes are p l o t t ed in red537 % non−supported nodes are p l o t t ed in black538 %539 % Input : xyz − x , y , and z coo rd ina t e s o f nodes540 % ( number o f nodes x 3 )541 %542 % Node 1 − [ x1 y1 z1 ;543 % Node 2 − x2 y2 z2 ;544 % . . . . . .545 % Node n − xn yn zn ] ;546 %547 % topo − topo logy o f t r u s s548 % ( number o f bars x 2 )549 %550 % Member 1 − [ NodeA NodeB ;551 % Member 2 − NodeD NodeC ;552 % . . . . . .553 % Member m − NodeX NodeK ] ;554 %555 % e f o r c e − i n t e r n a l bar f o r c e s556 % ( number o f bars x 1 )557 %558 % Member 1 − [ I n t e rna lForce1 ;559 % Member 2 − In t e rna lForce2 ;560 % . . . . . .561 % Member m − InternalForceM ] ;562 %563 % loadvec − load at each j o i n t564 %565 % fbc − id numbers o f nodes which are supported566 % ( number o f supported nodes x 1 )567 %568 % rads − p lo t rad iu s o f bars and j o i n t s569 % 1 x 1 : automatic r a t i o (Recommend : 0 . 0 1 )

    ASEN 2001 Section 014 18 of 37 Fall 2017

  • 570 % 3 x 1 : [ bar , node , suported node ]571 %572 % p l t f l a g s − f l a g s f o r p r i n t i n g annotat ion573 % (3 x 1)574 % 1 . component : 0/1 − p lo t node id numbers575 % 2 . component : 0/1 − p lo t bar id numbers576 % 3 . component : 0/1 − p lo t f o r c e value577 % 4 . component : 0/1 − 2D(0) or 3D(1) view578 %579 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−580 % Kurt Maute f o r ASEN 2001 Oct . 2006581 % Revised Oct . 2007 by Sungeun Jeon582 % Revised Sep . 2010 by Kurt Maute583 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−584585 f i g u r e (1 ) ;586 c l f ;587588 % check input589590 i f narg in

  • 625 nb=topo ( i , 2 ) ;626 [ xc , yc , zc ]= p lo tbar ( xyz ( na , : ) , xyz (nb , : ) , radb ) ;627 cc=e f o r c e ( i ) ∗ ones ( s i z e ( xc ) ) ;628 s u r f ( xc , yc , zc , cc , ' EdgeColor ' , ' none ' ) ;629 i f p l t f l a g s (2 ) > 0630 text ( ( xyz ( na , 1 )+xyz (nb , 1 ) ) /2+1.8∗ radb , ( xyz ( na , 2 )+xyz (nb , 2 ) ) /2+1.8∗ radb

    , ( xyz ( na , 3 )+xyz (nb , 3 ) ) /2+1.8∗ radb , num2str ( i ) ) ;631 end632 i f p l t f l a g s (3 ) > 0633 text ( ( xyz ( na , 1 )+xyz (nb , 1 ) ) /2+1.8∗ radb , ( xyz ( na , 2 )+xyz (nb , 2 ) ) /2+1.8∗ radb

    , ( xyz ( na , 3 )+xyz (nb , 3 ) ) /2+1.8∗ radb , s p r i n t f ( ' %.2 f ' , e f o r c e ( i ) ) ) ;634 end635 hold on ;636 end637638 % p lo t node id numbers639640 i f p l t f l a g s (1 ) > 0641 f o r i =1:numnode642 text ( xyz ( i , 1 ) +1.8∗ radj , xyz ( i , 2 ) +1.5∗ radj , xyz ( i , 3 ) +1.3∗ radj , num2str

    ( i ) ) ;643 end644 end645646 co l o rba r ;647 c a x i s ( [ minfrc maxfrc ] )648649 % p lo t b a l l j o i n t s650651 f o r i =1:numnode652 [ sx , sy , sz ]= plotnode ( xyz ( i , : ) , r ad j ) ;653 s u r f ( sx , sy , sz , ' EdgeColor ' , ' none ' , ' FaceColor ' , ' black ' ) ;654 hold on ;655 end656657 % p lo t supported nodes658659 f o r i =1: l ength ( fbc )660 na=fbc ( i ) ;661 [ sx , sy , sz ]= plotnode ( xyz ( na , : ) , radk ) ;662 s u r f ( sx , sy , sz , ' EdgeColor ' , ' none ' , ' FaceColor ' , ' red ' ) ;663 hold on ;664 end665666 %Plot the f o r c e s ac t ing at each j o i n t667 qu iver3 ( xyz ( : , 1 ) , xyz ( : , 2 ) , xyz ( : , 3 ) , loadvec ( : , 1 ) , loadvec ( : , 2 ) , loadvec ( : , 3 ) , 'm ' ,

    ' f i l l e d ' ) ;668 qu iver3 ( xyz ( fbc , 1 ) , xyz ( fbc , 2 ) , xyz ( fbc , 3 ) , r eacvec s ( : , 1 ) .∗ r e a c f o r c e s , r eacvec s

    ( : , 2 ) .∗ r e a c f o r c e s , r eacvec s ( : , 3 ) .∗ r e a c f o r c e s , ' r ' ) ;669 % p lo t parameters670671 a x i s ( ' equal ' ) ;672 t i t l e ( 'Member f o r c e s ' ) ;673674 l i g h t a n g l e (−45 ,30)

    ASEN 2001 Section 014 20 of 37 Fall 2017

  • 675 s e t ( gcf , ' Renderer ' , ' openGl ' )676 s e t ( f i n d o b j ( gca , ' type ' , ' s u r f a c e ' ) , ...677 ' FaceLight ing ' , ' phong ' , ...678 ' AmbientStrength ' , . 3 , ' Di f fu s eS t r eng th ' , . 8 , ...679 ' Specu larStrength ' , . 9 , ' SpecularExponent ' , 25 , ...680 ' BackFaceLighting ' , ' u n l i t ' )681682 i f p l t f l a g s (4 )683 % use d e f a u l t684 e l s e685 % s e t view point to 0 ,0 ,1686 view ( [ 0 0 1 ] ) ;687 end688689 return690 end691692 func t i on [ sx , sy , sz ]= plotnode ( xyz , rads )693 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−694 % re tu rn s sphere o f rad iu s rads at p o s i t i o n xyz (3 x1 )695 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−696 % Kurt Maute f o r ASEN 2001 Oct . 2006697 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−698 [ sx , sy , sz ]= sphere (30) ;699 n l=length ( sx ) ;700 omat=ones ( s i z e ( sx ) ) ;701 sx=rads ∗ sx+xyz (1 ) ∗omat ;702 sy=rads ∗ sy+xyz (2 ) ∗omat ;703 sz=rads ∗ sz+xyz (3 ) ∗omat ;704705 return706 end707708 func t i on [ xc , yc , zc ]= p lo tbar ( xa , xb , rads )709 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−710 % re tu rn s c y l i n d e r o f rad iu s rads711 % endpoints de f ined by xa (3 x1 ) and xb (3 x1 )712 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−713 % Kurt Maute f o r ASEN 2001 Oct . 2006714 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−715716 xba=xb−xa ;717 l en=norm( xba ) ;718719 % c r e a t e ba s i c c y l i n d e r720721 [ xc , yc , zc ]= c y l i n d e r ( [ rads rads ] , 2 0 ) ;722723 % s t r e t c h c y l i n d e r724725 cmat=[ l en ∗zc ' xc ' yc ' ] ;726727 % c r e a t e t rans fo rmat ion matrix728729 ev1=1/ l en ∗xba ' ;

    ASEN 2001 Section 014 21 of 37 Fall 2017

  • 730 eva=[ev1 (2 ) ; −ev1 (1 ) ; 0 ] ;731732 i f (norm( eva ) == 0)733 eva=[ev1 (3 ) ; 0 ; −ev1 (1 ) ] ;734 i f (norm( eva ) == 0)735 eva =[0; ev1 (3 ) ; −ev1 (2 ) ] ;736 end737 end738739 eva=1/norm( eva ) ∗eva ;740 ev2=c r o s s ( ev1 , eva ) ;741 ev3=c r o s s ( ev1 , ev2 ) ;742743 T=[ev1 ev2 ev3 ] ;744745 % r o t a t e c y l i n d e r746747 cpmat ( : , [ 1 3 5 ] ) =(T∗cmat ( : , [ 1 3 5 ] ) ' ) ' ;748 cpmat ( : , [ 2 4 6 ] ) =(T∗cmat ( : , [ 2 4 6 ] ) ' ) ' ;749750 n l=length ( xc ) ;751 omat=ones ( nl , 1 ) ;752753 xc ( 1 , : )=cpmat ( : , 1 )+xa (1) ∗omat ;754 xc ( 2 , : )=cpmat ( : , 2 )+xa (1) ∗omat ;755 yc ( 1 , : )=cpmat ( : , 3 )+xa (2) ∗omat ;756 yc ( 2 , : )=cpmat ( : , 4 )+xa (2) ∗omat ;757 zc ( 1 , : )=cpmat ( : , 5 )+xa (3 ) ∗omat ;758 zc ( 2 , : )=cpmat ( : , 6 )+xa (3 ) ∗omat ;759760 return761 end

    ASEN 2001 Section 014 22 of 37 Fall 2017

  • Alec Bosshart and Caleb Sytner developed the following code:

    1 func t i on truss3dmcs ( i n p u t f i l e , o u t p u t f i l e )2 %3 % S t o c h a s t i c a n a l y s i s o f 2−D s t a t i c a l l y determinate t r u s s by4 % Monte Carlo Simulat ion . Only p o s i t i o n s and s t r ength o f j o i n t s5 % tr ea t ed as random v a r i a b l e s6 %7 % Assumption : v a r i a t i o n o f j o i n t s t r ength and p o s i t i o n s de s c r ibed8 % via Gaussian d i s t r i b u t i o n s9 %

    10 % j o i n t s t r ength : mean = 1511 % c o e f f i c i e n t o f vara t i on = 0 .112 % j o i n t p o s i t i o n :13 % c o e f f i c i e n t o f vara t i on = 0.0114 % ( de f ined wrt to maximum dimension o f t r u s s )15 %16 % number o f samples i s s e t to 1e417 %18 % Input : i n p u t f i l e − name o f input f i l e19 %20 % Author : Kurt Maute f o r ASEN 2001 , Oct 13 201221 % Modif ied by Caleb Sytner and Alec Bosshart2223 %F i r s t perform a normal t r u s s a n a l y s i s24 t rus s3d ( i n p u t f i l e , o u t p u t f i l e )252627 % parameters28 jstrmean = 4 . 8 ; % mean o f j o i n t s t r ength29 j s t r c o v = 0 . 0 9 ; % c o e f f i c i e n t o f v a r i a t i o n o f j o i n t s t r ength30 jposcov = 0 . 0 1 ; % c o e f f i c i e n t o f v a r i a t i o n o f j o i n t p o s i t i o n31 numsamples = 1e5 ; % number o f samples3233 % read input f i l e34 [ j o i n t s , connec t i v i ty , r e a c j o i n t s , reacvecs , l o a d j o i n t s , l oadvecs ]= readinput3D (

    i n p u t f i l e ) ;3536 % determine extens i on o f t r u s s37 ext x=max( j o i n t s ( : , 1 ) )−min ( j o i n t s ( : , 1 ) ) ; % extens i on in x−d i r e c t i o n38 ext y=max( j o i n t s ( : , 2 ) )−min ( j o i n t s ( : , 2 ) ) ; % extens i on in the y−d i r e c t i o n39 e x t z=max( j o i n t s ( : , 3 ) )−min ( j o i n t s ( : , 3 ) ) ; % extens i on in z d i r e c t i o n40 ext =max ( [ ext x , ext y , e x t z ] ) ;4142 % loop o v e r a l l samples43 numjoints=s i z e ( j o i n t s , 1 ) ; % number o f j o i n t s44 maxforces=ze ro s ( numsamples , 1 ) ; % maximum bar f o r c e s f o r a l l samples45 maxreact=ze ro s ( numsamples , 1 ) ; % maximum support r e a c t i o n s f o r a l l samples46 f a i l u r e=ze ro s ( numsamples , 1 ) ; % f a i l u r e o f t r u s s4748 f o r i s =1:numsamples4950 % generate random j o i n t s t r ength l i m i t51 var s t r ength = ( j s t r c o v ∗ j strmean ) ∗ randn (1 , 1 ) ;5253 j s t r e n g t h = jstrmean + var s t r ength ;

    ASEN 2001 Section 014 23 of 37 Fall 2017

  • 5455 % generate random samples56 v a r j o i n t s = ( jposcov ∗ ext ) ∗ randn ( numjoints , 3 ) ;5758 % perturb j o i n t p o s i t i o n s59 r a n d j o i n t s = j o i n t s + v a r j o i n t s ;6061 % compute f o r c e s in bars and r e a c t i o n s62 [ ba r f o r c e s , r e a c f o r c e s , ˜ ] = f o r c e a n a l y s i s 3 D ( rand jo in t s , connec t i v i ty ,

    r e a c j o i n t s , reacvecs , l o a d j o i n t s , l oadvecs ) ;6364 % determine maximum f o r c e magnitude in bars and supports65 maxforces ( i s ) = max( abs ( b a r f o r c e s ) ) ;66 maxreact ( i s ) = max( abs ( r e a c f o r c e s ) ) ;6768 % determine whether t r u s s f a i l e d69 f a i l u r e ( i s ) = maxforces ( i s ) > j s t r e n g t h | | maxreact ( i s ) > j s t r e n g t h ;70 end7172 f i g u r e (1 ) ;73 subplot ( 1 , 2 , 1 ) ;74 h i s t ( maxforces , 3 0 ) ;75 t i t l e ( ' Histogram of maximum bar f o r c e s ' ) ;76 x l a b e l ( ' Magnitude o f bar f o r c e s ' ) ;77 y l a b e l ( ' Frequency ' ) ;7879 subplot ( 1 , 2 , 2 ) ;80 h i s t ( maxreact , 3 0 ) ;81 t i t l e ( ' Histogram of maximum support r e a c t i o n s ' ) ;82 x l a b e l ( ' Magnitude o f r e a c t i o n f o r c e s ' ) ;83 y l a b e l ( ' Frequency ' ) ;8485 f p r i n t f ( ' \ nFa i lu re p r o b a b i l i t y : %e \n\n ' , sum( f a i l u r e ) /numsamples ) ;86 %% Factor of Safety87 %Caleb Sytner and Alec Bosshart8889 Pdsr = . 0 1 ;9091 Fdsr = i c d f ( ' normal ' , Pdsr , 4 . 8 , 0 . 4 ) ;9293 n = (4.8−Fdsr ) / 0 . 4 ;9495 k = 4.8/(4 .8 −0 .4∗n) ;9697 end9899

    100101 %% Truss Analysis102 func t i on t rus s3d ( i n p u t f i l e , o u t p u t f i l e )103 % func t i on t rus s2d ( i n p u t f i l e , o u t p u t f i l e )104 %105 % Analys i s o f 2−D s t a t i c a l l y determinate t r u s s106 %107 % Input : i n p u t f i l e − name o f input f i l e

    ASEN 2001 Section 014 24 of 37 Fall 2017

  • 108 % o u t p u t f i l e − name o f output f i l e109 %110 % Author : Kurt Maute f o r ASEN 2001 , Sept 21 2011111 % Modif ied by Caleb Sytner and Alec Bosshart112113 % read input f i l e114 [ j o i n t s , connec t i v i ty , r e a c j o i n t s , reacvecs , l o a d j o i n t s , l oadvecs ]= readinput3D (

    i n p u t f i l e ) ;115116 % compute f o r c e s in bars and r e a c t i o n s117 [ ba r f o r c e s , r e a c f o r c e s , loadJointVec ]= f o r c e an a l y s i s 3 D ( j o i n t s , connec t i v i ty ,

    r e a c j o i n t s , reacvecs , l o a d j o i n t s , l oadvecs ) ;118119 % wr i t e o u t p u t f i l e120 writeoutput3D ( loadJointVec , o u t p u t f i l e , i n p u t f i l e , ba r f o r c e s , r e a c f o r c e s , j o i n t s ,

    connec t i v i ty , r e a c j o i n t s , reacvecs , l o a d j o i n t s , l oadvec s ) ;121122 % p lo t t r u s s ( used in Lab 2)123 jo int s3D=ze ro s ( s i z e ( j o i n t s , 1 ) , 3 ) ;124 jo int s3D ( : , 1 : 3 )=j o i n t s ;125 p l o t t r u s s ( jo ints3D , connec t i v i ty , ba r f o r c e s , r e a c j o i n t s , 3 ∗ [ 0 . 0 2 5 , 0 . 0 4 , 0 . 0 5 ] , [ 1 1

    0 0 ] )126 end127128129130131132 %% Read Input Function133 func t i on [ j o i n t s , connec t i v i ty , r e a c j o i n t s , reacvecs , l o a d j o i n t s , l oadvec s ]=

    readinput3D ( i n p u t f i l e )134 % func t i on [ j o i n t s , connec t i v i ty , r e a c j o i n t s , reacvecs , l o a d j o i n t s , l oadvecs ]=

    readinput ( i n p u t f i l e )135 %136 % read input f i l e137 %138 % input : i n p u t f i l e − name o f input f i l e139 %140 % output : j o i n t s − coo rd ina t e s o f j o i n t s141 % c o n n e c t i v i t y − c o n n e c t i v i t y142 % r e a c j o i n t s − j o i n t id where r e a c t i o n ac t s on143 % reacvec s − uni t vec to r a s s o c i a t e d with r e a c t i o n f o r c e144 % l o a d j o i n t s − j o i n t id where e x t e r n a l load ac t s on145 % loadvecs − load vec to r146 %147 % Author : Kurt Maute , Sept 21 2011148 % Modif ied by Caleb Sytner and Alec Bosshart149150 % open i n p u t f i l e151 f i d=fopen ( i n p u t f i l e ) ;152153 i f f i d

  • 157 inpblk =1;158159 % read f i r s t l i n e160 l i n e=f g e t l ( f i d ) ;161162 % read input f i l e163 whi l e l i n e > 0164165 % check i f comment166 i f strcmp ( l i n e (1 ) , '# ' )167 % read next l i n e and cont inue168 l i n e=f g e t l ( f i d ) ;169 cont inue ;170 end171172 switch inpb lk173174 case 1 % read number o f j o i n t s , bars , r e a c t i on s , and loads175176 dims=s s c a n f ( l i n e , '%d%d%d%d%d ' ) ;177178 numjoints = dims (1 ) ;179 numbars = dims (2 ) ;180 numreact = dims (3 ) ;181 numloads = dims (4 ) ;182183 % check f o r c o r r e c t number o f r e a c t i o n f o r c e s184 i f numreact ˜=6; e r r o r ( ' i n c o r r e c t number o f r e a c t i o n f o r c e s ' ) ; end185186 % i n i t i a l i z e a r rays187 j o i n t s = ze ro s ( numjoints , 3 ) ;188 c o n n e c t i v i t y = ze ro s ( numbars , 2 ) ;189 r e a c j o i n t s = ze ro s ( numreact , 1 ) ;190 r eacvec s = ze ro s ( numreact , 3 ) ;191 l o a d j o i n t s = ze ro s ( numloads , 1 ) ;192 loadvecs = ze ro s ( numloads , 3 ) ;193194 % check whether system s a t i s f i e s s t a t i c determiancy cond i t i on195 i f 3∗ numjoints − 6 ˜= numbars196 e r r o r ( ' t r u s s i s not s t a t i c a l l y determinate ' ) ;197 end198199 % expect next input block to be j o i n t coo rd ina t e s200 inpblk = 2 ;201202 case 2 % read coo rd ina t e s o f j o i n t s203204 % increment j o i n t id205 counter = counter + 1 ;206207 % read j o i n t id and coo rd ina t e s ;208 tmp=s s c a n f ( l i n e , '%d%e%e%e ' ) ;209210 % e x t r a c t and check j o i n t id211 j o i n t i d=tmp(1) ;

    ASEN 2001 Section 014 26 of 37 Fall 2017

  • 212 i f j o i n t i d >numjoints | | j o i n t i d numbars | | baridnumjoints | | min (tmp ( 2 : 3 ) )numjoints | | j o i n t i d

  • 264 e r r o r ( ' j o i n t id number need to be sma l l e r than number o fj o i n t s and l a r g e r than 0 ' ) ;

    265 end266267 % e x t r a c t u n t i t vec to r and check l ength268 uvec=tmp ( 2 : 4 ) ;269 uvec=uvec/norm( uvec ) ;270271 % s t o r e j o i n t id and uni t vec to r272 r e a c j o i n t s ( counter ) = j o i n t i d ;273 r eacvec s ( counter , : ) = uvec ;274275 % expect next input block to be e x t e r n a l l oads276 i f counter==numreact277 inpblk = 5 ;278 counter = 0 ;279 end280281 case 5 % read e x t e r n a l load in fo rmat ion282283 % increment r e a c t i o n id284 counter = counter + 1 ;285286 % read j o i n t id and uni t vec to r o f r e a c t i o n f o r c e ;287 tmp=s s c a n f ( l i n e , '%d%e%e%e ' ) ;288289 % e x t r a c t and check j o i n t id290 j o i n t i d=tmp(1) ;291 i f j o i n t i d >numjoints | | j o i n t i d

  • 317 f c l o s e ( f i d ) ;318319 end320321322323 %% Force Analysis324 func t i on [ ba r f o r c e s , r e a c f o r c e s , loadJointVec ]= fo r c e a n a l y s i s 3 D ( j o i n t s ,

    connec t i v i ty , r e a c j o i n t s , reacvecs , l o a d j o i n t s , l oadvec s )325 % func t i on [ ba r f o r c e s , r e a c f o r c e s ]= f o r c e a n a l y s i s ( j o i n t s , connec t i v i ty , r e a c j o i n t s

    , reacvecs , l o a d j o i n t s , l oadvec s )326 %327 % compute f o r c e s in bars and r e a c t i o n f o r c e s328 %329 % input : j o i n t s − coo rd ina t e s o f j o i n t s330 % c o n n e c t i v i t y − c o n n e c t i v i t y331 % r e a c j o i n t s − j o i n t id where r e a c t i o n ac t s on332 % reacvec s − uni t vec to r a s s o c i a t e d with r e a c t i o n f o r c e333 % l o a d j o i n t s − j o i n t id where e x t e r n a l load ac t s on334 % loadvecs − load vec to r335 %336 % output : b a r f o r c e s − f o r c e magnitude in bars337 % r e a c f o r c e s − r e a c t i o n f o r c e s338 %339 % Author : Kurt Maute , Sept 21 2011340 % Modif ied by Caleb Sytner and Alec Bosshart341342 % e x t r a c t number o f j o i n t s , bars , r e a c t i on s , and loads343 numjoints = s i z e ( j o i n t s , 1 ) ;344 numbars = s i z e ( connec t i v i ty , 1 ) ;345 numreact = s i z e ( r e a c j o i n t s , 1 ) ;346 numloads = s i z e ( l o a d j o i n t s , 1 ) ;347348 % number o f equat ions349 numeqns = 3 ∗ numjoints ;350351 % a l l o c a t e ar rays f o r l i n e a r system352 Amat = ze ro s ( numeqns ) ;353 bvec = ze ro s ( numeqns , 1 ) ;354355 % bu i ld Amat − loop over a l l j o i n t s356 f o r i =1: numjoints357358 % equat ion id numbers359 idx = 3∗ i −2;360 idy = 3∗ i −1;361 idz = 3∗ i ;362363 % get a l l bars connected to j o i n t364 [ ibar , i j t ]= f i n d ( c o n n e c t i v i t y==i ) ;365366 % loop over a l l bars connected to j o i n t367 f o r ib =1: l ength ( iba r )368369 % get bar id

    ASEN 2001 Section 014 29 of 37 Fall 2017

  • 370 bar id=iba r ( ib ) ;371372 % get coo rd ina t e s f o r j o i n t s ” i ” and ” j ” o f bar ” bar id ”373 j o i n t i = j o i n t s ( i , : ) ;374 i f i j t ( ib ) == 1375 j i d = c o n n e c t i v i t y ( barid , 2 ) ;376 e l s e377 j i d = c o n n e c t i v i t y ( barid , 1 ) ;378 end379 j o i n t j = j o i n t s ( j i d , : ) ;380381 % compute un i t vec to r po in t ing away from j o i n t i382 v e c i j = j o i n t j − j o i n t i ;383 uvec = v e c i j /norm( v e c i j ) ;384385 % add uni t vec to r in to Amat386 Amat ( [ idx idy idz ] , bar id )=uvec ;387 end388 end389390 % bu i ld c o n t r i b u t i o n o f support r e a c t i o n s391 f o r i =1:numreact392393 % get j o i n t id at which r e a c t i o n f o r c e ac t s394 j i d=r e a c j o i n t s ( i ) ;395396 % equat ion id numbers397 idx = 3∗ j i d −2;398 idy = 3∗ j i d −1;399 idz = 3∗ j i d ;400401 % add uni t vec to r in to Amat402 Amat ( [ idx idy idz ] , numbars+i )=reacvec s ( i , : ) ;403 end404405 %%%%%Factor in c o n t r i b u t i o n o f bar weight%%%%%406 %Find the l ength o f each bar407 BarLength = ze ro s ( numbars , 2 ) ;408409 f o r i =1:numbars410 j1 = c o n n e c t i v i t y ( i , 1 ) ;411 j2 = c o n n e c t i v i t y ( i , 2 ) ;412413 vec1 = j o i n t s ( j1 , : ) ;414 vec2 = j o i n t s ( j2 , : ) ;415416 d i s t ance = norm( vec2−vec1 ) ;417 BarLength ( i , 1 ) = i ;418 BarLength ( i , 2 ) = d i s t anc e ;419 end420 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%421 BarWeight = BarLength . ∗ 0 . 0 0 8 3 1 ; %Mult ip ly bar l ength by dens i ty in N/ in422423424 loadJointVec = [ l o a d j o i n t s l oadvec s ] ;

    ASEN 2001 Section 014 30 of 37 Fall 2017

  • 425426 f o r i = 1 : numbars427 j o i n t 1 = c o n n e c t i v i t y ( i , 1 ) ;428 j o i n t 2 = c o n n e c t i v i t y ( i , 2 ) ;429 addWeight = −BarWeight ( i , 2 ) /2 ;430 temp = f i n d ( loadJointVec ( : , 1 )==j o i n t 1 ) ;431 i f isempty ( temp ) == 1432 loadJointVec = [ loadJointVec ; j o i n t 1 0 0 addWeight ] ;433 e l s e434 loadJointVec ( temp , 4 ) = loadJointVec ( temp , 4 )+addWeight ;435 end436437 temp = f i n d ( loadJointVec ( : , 1 )==j o i n t 2 ) ;438 i f isempty ( temp ) == 1439 loadJointVec = [ loadJointVec ; j o i n t 2 0 0 addWeight ] ;440 e l s e441 loadJointVec ( temp , 4 ) = loadJointVec ( temp , 4 )+addWeight ;442 end443 end444 loadJointVec ( : , 4 ) = loadJointVec ( : , 4 ) −0.0819; %adds the weight o f the b a l l445446447 %Calc luate number o f magnets at each j o i n t , and add to loadVec448449 f o r i =1: numjoints450 numMagnets = 0 ;451 f o r k=1:numbars452 i f c o n n e c t i v i t y (k , 1 ) == i | | c o n n e c t i v i t y (k , 2 ) == i453 numMagnets = numMagnets + 1 ;454 end455 end456 loadJointVec ( i , 4 ) = loadJointVec ( i , 4 ) − (numMagnets ∗ . 001675∗9 .8 ) ;457 end458459 % bu i ld load vec to r460 f o r i =1: numjoints461462 % get j o i n t id at which e x t e r n a l f o r c e ac t s463 j i d=loadJointVec ( i , 1 ) ;464465 % equat ion id numbers466 idx = 3∗ j i d −2;467 idy = 3∗ j i d −1;468 idz = 3∗ j i d ;469470 % add uni t vec to r in to bvec ( s i gn change )471 bvec ( [ idx idy idz ] )=−loadJointVec ( i , 2 : 4 ) ;472 end473474 % check f o r i n v e r t a b i l i t y o f Amat475 i f rank (Amat) ˜= numeqns476 e r r o r ( 'Amat i s rank d e f f i c i e n t : %d < %d\n ' , rank (Amat) , numeqns ) ;477 end478479 % s o l v e system

    ASEN 2001 Section 014 31 of 37 Fall 2017

  • 480 xvec=Amat\bvec ;481482 % e x t r a c t f o r c e s in bars and r e a c t i o n f o r c e s483 b a r f o r c e s=xvec ( 1 : numbars ) ;484 r e a c f o r c e s=xvec ( numbars+1:end ) ;485486 end487488489490491 %% Write Output Function492 func t i on writeoutput3D ( loadJointVec , o u t p u t f i l e , i n p u t f i l e , ba r f o r c e s , r e a c f o r c e s ,

    j o i n t s , connec t i v i ty , r e a c j o i n t s , reacvecs , l o a d j o i n t s , l oadvec s )493 % wri teoutput ( o u t p u t f i l e , i n p u t f i l e , ba r f o r c e s , r e a c f o r c e s , j o i n t s , connec t i v i ty ,

    r e a c j o i n t s , reacvecs , l o a d j o i n t s , l oadvecs ) ;494 %495 % output a n a l y s i s r e s u l t s496 %497 % input : o u t p u t f i l e − name o f output f i l e498 % i n p u t f i l e − name o f input f i l e499 % b a r f o r c e s − f o r c e magnitude in bars500 % r e a c f o r c e s − r e a c t i o n f o r c e s501 % j o i n t s − coo rd ina t e s o f j o i n t s502 % c o n n e c t i v i t y − c o n n e c t i v i t y503 % r e a c j o i n t s − j o i n t id where r e a c t i o n ac t s on504 % reacvec s − uni t vec to r a s s o c i a t e d with r e a c t i o n f o r c e505 % l o a d j o i n t s − j o i n t id where e x t e r n a l load ac t s on506 % loadvecs − load vec to r507 %508 %509 % Author : Kurt Maute , Sept 21 2011510 % Modif ied by Caleb Sytner and Alec Bosshart511512 % open output f i l e513 f i d=fopen ( o u t p u t f i l e , 'w ' ) ;514515 % wr i t e header516 f p r i n t f ( f i d , '3−D Truss a n a l y s i s \n ' ) ;517 f p r i n t f ( f i d , '−−−−−−−−−−−−−−−−−−\n\n ' ) ;518 f p r i n t f ( f i d , ' Date : %s \n\n ' , d a t e s t r (now) ) ;519520 % wr i t e name o f input f i l e521 f p r i n t f ( f i d , ' Input f i l e : %s \n\n ' , i n p u t f i l e ) ;522523 % wr i t e coo rd ina t e s o f j o i n t s524 f p r i n t f ( f i d , ' Jo in t s : Joint−id x−coord inate y−coord inate z−coord inate \

    n ' ) ;525 f o r i =1: s i z e ( j o i n t s , 1 )526 f p r i n t f ( f i d , '%17d %12.2 f %12.2 f %12.2 f \n ' , i , j o i n t s ( i , 1 ) , j o i n t s ( i , 2 ) , j o i n t s

    ( i , 3 ) ) ;527 end528 f p r i n t f ( f i d , ' \n\n ' ) ;529530 % wr i t e e x t e r n a l l oads

    ASEN 2001 Section 014 32 of 37 Fall 2017

  • 531 f p r i n t f ( f i d , ' External l oads : Joint−id Force−x Force−y Force−z\n ' ) ;532 f o r i =1: s i z e ( l o a d j o i n t s , 1 )533 f p r i n t f ( f i d , '%17d %12.2 f %12.2 f %12.2 f \n ' , l o a d j o i n t s ( i ) , l oadvec s ( i , 1 ) ,

    l oadvec s ( i , 2 ) , l oadvecs ( i , 3 ) ) ;534 end535 f p r i n t f ( f i d , ' \n ' ) ;536537 % wr i t e c o n n e c t i v i t y and f o r c e s538 f p r i n t f ( f i d , ' Bars : Bar−id Joint−i Jo int−j Force (T,C)

    \n ' ) ;539 f o r i =1: s i z e ( connec t i v i ty , 1 )540 i f b a r f o r c e s ( i ) >0; tc= 'T ' ; e l s e tc= 'C ' ; end541 f p r i n t f ( f i d , '%17d %7d %12d %12.3 f (%s ) \n ' , ...542 i , c o n n e c t i v i t y ( i , 1 ) , c o n n e c t i v i t y ( i , 2 ) , abs ( b a r f o r c e s ( i ) ) , t c ) ;543 end544 f p r i n t f ( f i d , ' \n ' ) ;545546 % wr i t e c o n n e c t i v i t y and f o r c e s547 f p r i n t f ( f i d , ' React ions : Joint−id Uvec−x Uvec−y Uvec−z

    Force\n ' ) ;548 f o r i =1: s i z e ( r e a c j o i n t s , 1 )549 f p r i n t f ( f i d , '%17d %12.2 f %12.2 f %12.2 f %12.3 f \n ' , r e a c j o i n t s ( i ) , r eacvec s ( i

    , 1 ) , r eacvec s ( i , 2 ) , r ea cvec s ( i , 3 ) , r e a c f o r c e s ( i ) ) ;550 end551552 % c l o s e output f i l e553 f c l o s e ( f i d ) ;554555 end556557558 %% Plot Truss559 func t i on p l o t t r u s s ( xyz , topo , e f o r c e , fbc , rads , p l t f l a g s )560 %func t i on p l o t t r u s s ( xyz , topo , e f o r c e , fbc , rads , p l t f l a g s )561 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−562 %563 % p lo t 3−t rus s , bars co l o r ed acco r ing to f o r c e564 % supported nodes are p l o t t ed in red565 % non−supported nodes are p l o t t ed in black566 %567 % Input : xyz − x , y , and z coo rd ina t e s o f nodes568 % ( number o f nodes x 3 )569 %570 % Node 1 − [ x1 y1 z1 ;571 % Node 2 − x2 y2 z2 ;572 % . . . . . .573 % Node n − xn yn zn ] ;574 %575 % topo − topo logy o f t r u s s576 % ( number o f bars x 2 )577 %578 % Member 1 − [ NodeA NodeB ;579 % Member 2 − NodeD NodeC ;580 % . . . . . .581 % Member m − NodeX NodeK ] ;

    ASEN 2001 Section 014 33 of 37 Fall 2017

  • 582 %583 % e f o r c e − i n t e r n a l bar f o r c e s584 % ( number o f bars x 1 )585 %586 % Member 1 − [ I n t e rna lForce1 ;587 % Member 2 − In t e rna lForce2 ;588 % . . . . . .589 % Member m − InternalForceM ] ;590 %591 % fbc − id numbers o f nodes which are supported592 % ( number o f supported nodes x 1 )593 %594 % rads − p lo t rad iu s o f bars and j o i n t s595 % 1 x 1 : automatic r a t i o (Recommend : 0 . 0 1 )596 % 3 x 1 : [ bar , node , suported node ]597 %598 % p l t f l a g s − f l a g s f o r p r i n t i n g annotat ion599 % (3 x 1)600 % 1 . component : 0/1 − p lo t node id numbers601 % 2 . component : 0/1 − p lo t bar id numbers602 % 3 . component : 0/1 − p lo t f o r c e value603 % 4 . component : 0/1 − 2D(0) or 3D(1) view604 %605 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−606 % Kurt Maute f o r ASEN 2001 Oct . 2006607 % Revised Oct . 2007 by Sungeun Jeon608 % Revised Sep . 2010 by Kurt Maute609 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−610611 f i g u r e (1 ) ;612 c l f ;613614 % check input615616 i f narg in < 6 ; e r r o r ( ' r ou t ine r e q u i r e s 6 input parameters ' ) ; end617618 % e x t r a c t619620 [ numnode , dim]= s i z e ( xyz ) ;621 numelem = s i z e ( topo , 1 ) ;622623 i f dim ˜= 3624 d i s p l a y ( ' Error in p l o t t r u s s : 3 coo rd ina t e s are needed f o r array xyz ' ) ;625 re turn ;626 end627628 % e x t r a c t min and max f o r c e va lue s629630 minfrc=f l o o r ( min ( e f o r c e ) ) ;631 maxfrc=c e i l (max( e f o r c e ) ) ;632633 % d e f i n e rad iu s o f bars634635 i f l ength ( rads ) == 1636 radb = rads (1 ) ;

    ASEN 2001 Section 014 34 of 37 Fall 2017

  • 637 rad j = 1.75∗ radb ;638 radk = 1.5∗ rad j ;639 e l s e640 radb = rads (1 ) ;641 rad j = rads (2 ) ;642 radk = rads (3 ) ;643 end644645 % p lo t bars646647 f i g u r e (1 )648649 f o r i =1:numelem650 na=topo ( i , 1 ) ;651 nb=topo ( i , 2 ) ;652 [ xc , yc , zc ]= p lo tbar ( xyz ( na , : ) , xyz (nb , : ) , radb ) ;653 cc=e f o r c e ( i ) ∗ ones ( s i z e ( xc ) ) ;654 s u r f ( xc , yc , zc , cc , ' EdgeColor ' , ' none ' ) ;655 i f p l t f l a g s (2 ) > 0656 text ( ( xyz ( na , 1 )+xyz (nb , 1 ) ) /2+1.8∗ radb , ( xyz ( na , 2 )+xyz (nb , 2 ) ) /2+1.8∗ radb

    , ( xyz ( na , 3 )+xyz (nb , 3 ) ) /2+1.8∗ radb , num2str ( i ) ) ;657 end658 i f p l t f l a g s (3 ) > 0659 text ( ( xyz ( na , 1 )+xyz (nb , 1 ) ) /2+1.8∗ radb , ( xyz ( na , 2 )+xyz (nb , 2 ) ) /2+1.8∗ radb

    , ( xyz ( na , 3 )+xyz (nb , 3 ) ) /2+1.8∗ radb , s p r i n t f ( ' %.2 f ' , e f o r c e ( i ) ) ) ;660 end661 hold on ;662 end663664 % p lo t node id numbers665666 i f p l t f l a g s (1 ) > 0667 f o r i =1:numnode668 text ( xyz ( i , 1 ) +1.8∗ radj , xyz ( i , 2 ) +1.5∗ radj , xyz ( i , 3 ) +1.3∗ radj , num2str

    ( i ) ) ;669 end670 end671672 co l o rba r ;673 c a x i s ( [ minfrc maxfrc ] )674675 % p lo t b a l l j o i n t s676677 f o r i =1:numnode678 [ sx , sy , sz ]= plotnode ( xyz ( i , : ) , r ad j ) ;679 s u r f ( sx , sy , sz , ' EdgeColor ' , ' none ' , ' FaceColor ' , ' black ' ) ;680 hold on ;681 end682683 % p lo t supported nodes684685 f o r i =1: l ength ( fbc )686 na=fbc ( i ) ;687 [ sx , sy , sz ]= plotnode ( xyz ( na , : ) , radk ) ;688 s u r f ( sx , sy , sz , ' EdgeColor ' , ' none ' , ' FaceColor ' , ' red ' ) ;

    ASEN 2001 Section 014 35 of 37 Fall 2017

  • 689 hold on ;690 end691692 % p lo t parameters693694 a x i s ( ' equal ' ) ;695 t i t l e ( 'Member f o r c e s ' ) ;696697 l i g h t a n g l e (−45 ,30)698 s e t ( gcf , ' Renderer ' , ' openGl ' )699 s e t ( f i n d o b j ( gca , ' type ' , ' s u r f a c e ' ) , ...700 ' FaceLight ing ' , ' phong ' , ...701 ' AmbientStrength ' , . 3 , ' Di f fu s eS t r eng th ' , . 8 , ...702 ' Specu larStrength ' , . 9 , ' SpecularExponent ' , 25 , ...703 ' BackFaceLighting ' , ' u n l i t ' )704705 i f p l t f l a g s (4 )706 % use d e f a u l t707 e l s e708 % s e t view point to 0 ,0 ,1709 view ( [ 0 0 1 ] ) ;710 end711712 return713 end714715 func t i on [ sx , sy , sz ]= plotnode ( xyz , rads )716 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−717 % re tu rn s sphere o f rad iu s rads at p o s i t i o n xyz (3 x1 )718 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−719 % Kurt Maute f o r ASEN 2001 Oct . 2006720 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−721 [ sx , sy , sz ]= sphere (30) ;722 n l=length ( sx ) ;723 omat=ones ( s i z e ( sx ) ) ;724 sx=rads ∗ sx+xyz (1 ) ∗omat ;725 sy=rads ∗ sy+xyz (2 ) ∗omat ;726 sz=rads ∗ sz+xyz (3 ) ∗omat ;727728 return729 end730731 func t i on [ xc , yc , zc ]= p lo tbar ( xa , xb , rads )732 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−733 % re tu rn s c y l i n d e r o f rad iu s rads734 % endpoints de f ined by xa (3 x1 ) and xb (3 x1 )735 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−736 % Kurt Maute f o r ASEN 2001 Oct . 2006737 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−738739 xba=xb−xa ;740 l en=norm( xba ) ;741742 % c r e a t e ba s i c c y l i n d e r743

    ASEN 2001 Section 014 36 of 37 Fall 2017

  • 744 [ xc , yc , zc ]= c y l i n d e r ( [ rads rads ] , 2 0 ) ;745746 % s t r e t c h c y l i n d e r747748 cmat=[ l en ∗zc ' xc ' yc ' ] ;749750 % c r e a t e t rans fo rmat ion matrix751752 ev1=1/ l en ∗xba ' ;753 eva=[ev1 (2 ) ; −ev1 (1 ) ; 0 ] ;754755 i f (norm( eva ) == 0)756 eva=[ev1 (3 ) ; 0 ; −ev1 (1 ) ] ;757 i f (norm( eva ) == 0)758 eva =[0; ev1 (3 ) ; −ev1 (2 ) ] ;759 end760 end761762 eva=1/norm( eva ) ∗eva ;763 ev2=c r o s s ( ev1 , eva ) ;764 ev3=c r o s s ( ev1 , ev2 ) ;765766 T=[ev1 ev2 ev3 ] ;767768 % r o t a t e c y l i n d e r769770 cpmat ( : , [ 1 3 5 ] ) =(T∗cmat ( : , [ 1 3 5 ] ) ' ) ' ;771 cpmat ( : , [ 2 4 6 ] ) =(T∗cmat ( : , [ 2 4 6 ] ) ' ) ' ;772773 n l=length ( xc ) ;774 omat=ones ( nl , 1 ) ;775776 xc ( 1 , : )=cpmat ( : , 1 )+xa (1) ∗omat ;777 xc ( 2 , : )=cpmat ( : , 2 )+xa (1) ∗omat ;778 yc ( 1 , : )=cpmat ( : , 3 )+xa (2) ∗omat ;779 yc ( 2 , : )=cpmat ( : , 4 )+xa (2) ∗omat ;780 zc ( 1 , : )=cpmat ( : , 5 )+xa (3 ) ∗omat ;781 zc ( 2 , : )=cpmat ( : , 6 )+xa (3 ) ∗omat ;782783 return784 end

    ASEN 2001 Section 014 37 of 37 Fall 2017