Mathematical Functions in AutoCAD
Mathematical Functions in AutoCAD
mathematicaltoolthat'srightinsidethesoftware.
AutoCADisverygooddraftingsoftwareformakingarcsandlines,butsometimesthissimpleviewofthingsis
notsufficienttorepresenttypicalengineeringgraphics.Forexample:ifwehaveacablesupportedbytwotowers,
weneedtodefinecatenarycurvetorepresentthecable,yetAutoCADdoesn'thavea"catenary"command.Also,
ifyouneedtoanalyzeabeamdeflectionthereisn'taneasywaytodoit.
TherealCADtoolpoweristhepossibilityofusingCADwithageometriccalculator,notonlyformeasuringareas
anddistances,buttographcomplexfunctions.ThisarticlebringsyouasmallAutoLISProutinetodemonstrate
howtographmathematicalfunctionsandparametricequations.
IfyouknowAutoLISP,skipthenexttwoparagraphs.Ifyoudon'tknowAutoLISP,you'llneedtounderstandhow
towritemathematicalexpressionsinAutoLISP.
Firstrule:AllAutoLISPexpressionsarewrittenbetweenparentheses.
Secondrule:allmathematicalexpressionsarewritteninprefixnotation.
Thirdrule:mathematicoperationsbetweenrealnumbersproducerealnumbers,betweenintegersproduce
integersandbetweenintegers,andrealproducereal.
Examples:
1+3is(+13)inAutoLISP
1+2/4is(+1(/24))inAutoLISP
(+13)=4
(+1.03)=4.0
(/53)=1
(/5.03)=1.66667
Tounderstandindepth,seeyourAutoLISPmanual.
EVALUATINGFUNCTIONSINTHEXYPLANE
Typically,AutoCADusersworkintheXYplane,XvaluesincreasinglefttorightandYvaluesincreasingbottom
totop.Inthegraphfx.lspfile,theGraphFxAutoLISPfunctionevaluatesamathematicalexpressionintheform
Y=F(X)andreturnsasortinglistwiththeevaluatedpoints.
TheAutoLISPfunctionhasfourarguments:themathematicalfunctionY=F(X)inAutoLISPterms,thefirstX
value,thelastXvalueandtheincreasingvaluetoX.
TheAutoLISPfunctionPrintpntlstgraphsa3DPOLYLINEusingalistwithsortedpoints.
Forexampletogeneratealistwithevaluatedpointsusingthetrigonometricfunctionsin(x)between0and10
increasingxin0.1,youneedtowritethefollowingexpressionintheAutoCADcommandline:
(graphFx'(sinx)0100.1)
Toprintthepoints,write
(Printpntlst(graphFx'(sinx)0100.1))
sin(x)graphic
Also,youcangeneratemorecomplexandpracticalgraphs.Forexample,thefollowingequationdefinesthe
deflectioncurveforaproppedcantileverbeamwithauniformload(q):
toexpressthelastequationinAutoLISPyouneedtowritethefollowingline:
(*(/(*qxx)(*48EI))(+(*3LL)(*5Lx)(*2xx)))
Ifthelength(L)ofthebeamis10mandsimplifyingandscalingtheexpressiononlyfordemonstrationwehave:
(printpntlst(graphFx'(*xx0.0005(+300(*50x)(*2xx)))0100.1))
Deflectioncurveforaproppedcantileverbeam
EVALUATINGPARAMETRICFUNCIONSINTHEXYZSPACE
Ifwehaveagraphdescribedbythreefunctions,oneforXcoordinate,oneforYcoordinate,oneforZcoordinate
andacommonparameterwecanusetheGraphParAutoLISPfunction(graphfx.lsp).
ThisAutoLISPfunctionhassixarguments:threemathematicalfunctionsX=F(q),Y=F(q)andZ=F(q)inAutoLISP
terms,thefirstqparametervalue,thelastqparametervalueandtheincreasingvalueofq.
Forexample,wecandescribesuchparabolicmotionwithparametricequationsintheXYplaneusingatime
parameterqmeasuredintimeunitsfromtheinitialprojectionpoint:
ExpressingthelastequationsinAutoLISPwehave:
(+X0(*Vx0q))
(+Y0(*Vy0q)(*0.5gqq))
0
Ifqstartin0andendin200,X0=0,Y0=0andsimplifyingandscalingtheparametricfunctionwehave:
(printpntlst(graphpar'(*100q)'((*100q)(*qq))'002001))
Parabolicmotion
THECABLEPROBLEM
Oneofthemosttypicalproblemsinengineeringistofixacablebetweentwopoints.Thefunctiontodescribethe
shapeisacatenary.Themathematicalexpressionis:
Wherewistheweightperunitlengthofthecable,tisthetension
developedinthecable,andy0istheminimumheightofthecable.
AutoLISPdon'thavethehyperboliccosine,butthatisnotaproblemsincewecandefineitwiththefollowing
function
(defuncosh(angles/angles)
(/(/(+(expangles)(exp(*angles1)))2))
)
Inthecatenary.lspfilewehavearoutinetoprintacablebetweentwopointsdefinedthepointsinAutoCAD,the
weightperunitlengthofthecableandthetension.Thefilehasthreeadditionalfunctions:hyperboliccosine
(cosh),hyperbolicsine(sinh),andarchyperbolicsine(arcsinh)
BelowwecanseethegraphFxAutoLISPuseinthec:catenaryfunction:
(printpntlst(graphFx'(+(*global_c((cosh(/(xglobal_xv)global_c))1))global_yv)x1x21.0))
Cablebetweentwopoints
CONCLUSION
WiththeGraphFxandGraphParAutoLISProutineswecangraphicmathematicalfunctions,alsowecaninclude
theroutinesinsideothersroutineswithinweliketohaveonlythekernelofaspecificproblem(i.e.Thecable
problem).