Advertisement
Guest User

Untitled

a guest
Dec 20th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (defun Point(x y z)
  2.     (list x y z)
  3. )
  4.  
  5. (defun Line (from to)
  6.     (entmakex
  7.         (list
  8.             (cons 0 "line")
  9.             (cons 10 from)
  10.             (cons 11 to)
  11.         )
  12.     )  
  13. )
  14.  
  15. (defun Polygon (points)
  16.     (apply 'command
  17.         (append
  18.            '(".3dpoly")
  19.                 points
  20.            '("")
  21.         )
  22.     )  
  23.     (princ)
  24. )
  25.  
  26. (defun Arc (center radius sAng eAng)
  27.     (entmakex
  28.         (list (cons 0 "ARC")
  29.             (cons 10  center)
  30.             (cons 40  radius)
  31.             (cons 50 sAng)
  32.             (cons 51 eAng)
  33.         )
  34.     )
  35. )
  36.  
  37. (defun SegmentCirecleRadius (segmentRadius segmentHeight / circleRadius)
  38.     (setq circleRadius (/ (+ (* segmentHeight segmentHeight) (* segmentRadius segmentRadius)) (* segmentHeight 2)))
  39. )
  40.  
  41.  
  42. (defun SmallSegmentRadius (segmentRadius segmentHeight factor / result hSqr rSqr fSqr)
  43.     (setq hSqr (* segmentHeight segmentHeight))
  44.     (setq rSqr (* segmentRadius segmentRadius))
  45.     (setq fSqr (* factor factor))
  46.  
  47.     (setq result
  48.         (sqrt
  49.             (+
  50.                 (- (/ hSqr factor) (/ hSqr fSqr))
  51.                 (/ rSqr factor)
  52.             )
  53.         )
  54.     )
  55. )
  56.  
  57.  
  58.  
  59. (defun Segment (segmentHeight segmentRadius basePoint points vertexCount / smSgmBaseList smCircleRadius smSgmBase prevBase circleRadius idx radiusParam )
  60.  
  61.     (setq circleRadius (SegmentCirecleRadius segmentRadius segmentHeight))
  62.    
  63.     (setq idx 9)
  64.     (setq smSgmBaseList (list))
  65.  
  66.        
  67.     (repeat 9
  68.    
  69.         (setq radiusParam (/ 10.0 idx))
  70.         (setq smCircleRadius (SmallSegmentRadius segmentRadius segmentHeight radiusParam))
  71.         (setq smSgmBase (VertexCircle basePoint smCircleRadius vertexCount (- segmentHeight (/ segmentHeight radiusParam))))
  72.         (setq smSgmBaseList (append smSgmBaseList (list smSgmBase)))
  73.         (setq idx (- idx 1))
  74.    
  75.     )
  76.    
  77.     (Polygon points)
  78.     (setq prevBase points)
  79.     (foreach sgmBase smSgmBaseList
  80.    
  81.         (progn
  82.             (Polygon sgmBase)
  83.             (ConnectPolygons prevBase sgmBase)
  84.             (setq prevBase sgmBase)
  85.             (princ)
  86.         )
  87.    
  88.     )
  89.    
  90.     (setq basePoint (list (car basePoint) (cadr basePoint) (+ (caddr basePoint) segmentHeight)))
  91.     (ConnectPolygons (car smSgmBaseList) points)
  92.     (Cone (last smSgmBaseList) basePoint)
  93.    
  94. )
  95.  
  96. (defun ConnectPolygons(firstPolygon secondPolygon)
  97.     (mapcar '(lambda (from to)
  98.             (Line from to)
  99.         )
  100.         firstPolygon
  101.         secondPolygon
  102.     )  
  103. )
  104.  
  105. (defun Cone(polygon point)
  106.     (mapcar '(lambda (polygonPoint)
  107.             (Line polygonPoint point)
  108.         )
  109.         polygon
  110.     )  
  111. )
  112.  
  113. (defun Cylinder(firstCylinderBase secondCylinderBase)
  114.     (Polygon firstCylinderBase)
  115.     (Polygon secondCylinderBase)   
  116.     (ConnectPolygons firstCylinderBase secondCylinderBase) 
  117. )
  118.  
  119. (defun VertexCircle(basePoint radius vertexCount zValue / polygon baseAngle currentPoint idx)
  120.     (setq baseAngle (/ (* 2 pi) vertexCount))
  121.    
  122.     (setq idx 1)
  123.     (setq currentPoint (polar basePoint 0 radius))
  124.     (setq currentPoint (Point (car currentPoint) (cadr currentPoint) (+ zValue (caddr currentPoint))))
  125.     (setq polygon (list currentPoint))
  126.    
  127.     (repeat vertexCount
  128.         (setq currentPoint (polar basePoint (* baseAngle idx) radius))
  129.         (setq currentPoint (Point (car currentPoint) (cadr currentPoint) (+ zValue (caddr currentPoint))))
  130.         (setq polygon (append polygon (list currentPoint)))
  131.         (setq idx (+ idx 1))
  132.     )
  133.    
  134.     (setq polygon polygon) 
  135. )
  136.  
  137.  
  138. (defun c:draw(/ basePoint
  139.     cylinderHeight
  140.     coneHeight
  141.     cylinderRadius
  142.     coneRadius
  143.     vertexCount
  144.     firstCylinderBase
  145.     secondCylinderBase
  146.     coneBase
  147.     conePoint
  148.     segmentHeight
  149.     segmentRadius)
  150.  
  151.     ;   Input
  152.    
  153.     (setq vertexCount 20) ; Vertex count constant // OK
  154.    
  155.     ;   Base point input // need initget below
  156.     (setq basePoint (getpoint "Input base point for figure: "))
  157.    
  158.     ;   Cylinder params input // need initget below
  159.     (setq cylinderHeight (getdist "Input cylinder height value: "))
  160.     (setq cylinderRadius (getdist "Input cylinder radius value: "))
  161.    
  162.     ;   Cone params input // need initget below
  163.     (setq coneHeight (getdist "Input cone height value: "))
  164.     (setq coneRadius (getdist "Input cone radius value: "))
  165.    
  166.     ;   Sphere params input // need initget below
  167.     (setq segmentHeight (getdist "Input sphere height value: "))
  168.     (setq segmentRadius (getdist "Input sphere radius value: "))
  169.    
  170.     ;   Input end
  171.    
  172.     ;   Drawing
  173.    
  174.     (setq firstCylinderBase (VertexCircle basePoint cylinderRadius vertexCount 0))
  175.     (setq secondCylinderBase (VertexCircle basePoint cylinderRadius vertexCount cylinderHeight))   
  176.     (Cylinder firstCylinderBase secondCylinderBase)
  177.    
  178.    
  179.     (setq coneBase (VertexCircle basePoint coneRadius vertexCount cylinderHeight))
  180.     (setq conePoint (Point (car basePoint) (cadr basePoint) (+ (caddr basePoint) cylinderHeight coneHeight)))  
  181.     (Polygon coneBase)
  182.     (Cone coneBase conePoint)
  183.  
  184.     ;   Segment
  185.    
  186.     (setq segmentBase (VertexCircle basePoint segmentRadius vertexCount 0))
  187.     (Segment segmentHeight segmentRadius basePoint segmentBase vertexCount)
  188.    
  189.     ;   Segment
  190.    
  191.     ;   Connect
  192.     (ConnectPolygons secondCylinderBase coneBase)  
  193.     (ConnectPolygons firstCylinderBase segmentBase)
  194.     ;   Connect end
  195.    
  196.     ;   Drawing end
  197.  
  198.     (princ)
  199.    
  200. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement