Advertisement
Guest User

Untitled

a guest
Dec 14th, 2017
126
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 / smSgmBase2 smSgmBase3 circleRadius smCircleRadius2 smCircleRadius3 idx bases)
  60.  
  61.     (setq circleRadius (SegmentCirecleRadius segmentRadius segmentHeight))
  62.    
  63.     (setq smCircleRadius2 (SmallSegmentRadius segmentRadius segmentHeight 0.5))
  64.     (setq smCircleRadius3 (SmallSegmentRadius segmentRadius segmentHeight 0.33))
  65.     (setq smCircleRadius4 (SmallSegmentRadius segmentRadius segmentHeight 0.25))
  66.     (setq smCircleRadius5 (SmallSegmentRadius segmentRadius segmentHeight 0.10))
  67.    
  68.     (setq smSgmBase2 (VertexCircle basePoint smCircleRadius2 vertexCount (/ segmentHeight 2)))
  69.     (setq smSgmBase3 (VertexCircle basePoint smCircleRadius3 vertexCount (- segmentHeight (/ segmentHeight 3))))
  70.     (setq smSgmBase4 (VertexCircle basePoint smCircleRadius3 vertexCount (- segmentHeight (/ segmentHeight 4))))
  71.     (setq smSgmBase5 (VertexCircle basePoint smCircleRadius3 vertexCount (- segmentHeight (/ segmentHeight 10))))
  72.    
  73.     (setq basePoint (list (car basePoint) (cadr basePoint) (+ (caddr basePoint) segmentHeight)))
  74.    
  75.     (Polygon points)
  76.     ;(Polygon smSgmBase2)
  77.     ;(Polygon smSgmBase4)
  78.    
  79.     (ConnectPolygons points smSgmBase2)
  80.     (ConnectPolygons smSgmBase2 smSgmBase3)
  81.     (ConnectPolygons smSgmBase3 smSgmBase4)
  82.     (ConnectPolygons smSgmBase4 smSgmBase5)
  83.    
  84.     ;(Cone smSgmBase5 basePoint)
  85.    
  86. )
  87.  
  88. (defun ConnectPolygons(firstPolygon secondPolygon)
  89.     (mapcar '(lambda (from to)
  90.             (Line from to)
  91.         )
  92.         firstPolygon
  93.         secondPolygon
  94.     )  
  95. )
  96.  
  97. (defun Cone(polygon point)
  98.     (mapcar '(lambda (polygonPoint)
  99.             (Line polygonPoint point)
  100.         )
  101.         polygon
  102.     )  
  103. )
  104.  
  105. (defun Cylinder(firstCylinderBase secondCylinderBase)
  106.     (Polygon firstCylinderBase)
  107.     (Polygon secondCylinderBase)   
  108.     (ConnectPolygons firstCylinderBase secondCylinderBase) 
  109. )
  110.  
  111. (defun VertexCircle(basePoint radius vertexCount zValue / polygon baseAngle currentPoint idx)
  112.     (setq baseAngle (/ (* 2 pi) vertexCount))
  113.    
  114.     (setq idx 1)
  115.     (setq currentPoint (polar basePoint 0 radius))
  116.     (setq currentPoint (Point (car currentPoint) (cadr currentPoint) (+ zValue (caddr currentPoint))))
  117.     (setq polygon (list currentPoint))
  118.    
  119.     (repeat vertexCount
  120.         (setq currentPoint (polar basePoint (* baseAngle idx) radius))
  121.         (setq currentPoint (Point (car currentPoint) (cadr currentPoint) (+ zValue (caddr currentPoint))))
  122.         (setq polygon (append polygon (list currentPoint)))
  123.         (setq idx (+ idx 1))
  124.     )
  125.    
  126.     (setq polygon polygon) 
  127. )
  128.  
  129.  
  130. (defun c:draw(/ basePoint
  131.     cylinderHeight
  132.     coneHeight
  133.     cylinderRadius
  134.     coneRadius
  135.     vertexCount
  136.     firstCylinderBase
  137.     secondCylinderBase
  138.     coneBase
  139.     conePoint
  140.     segmentHeight
  141.     segmentRadius)
  142.  
  143.     ;   Input
  144.    
  145.     (setq vertexCount 50) ; Vertex count constant // OK
  146.    
  147.     ;   Base point input // need initget below
  148.     (setq basePoint (getpoint "Input base point for figure: "))
  149.    
  150.     ;   Cylinder params input // need initget below
  151.     (setq cylinderHeight (getdist "Input cylinder height value: "))
  152.     (setq cylinderRadius (getdist "Input cylinder radius value: "))
  153.    
  154.     ;   Cone params input // need initget below
  155.     (setq coneHeight (getdist "Input cone height value: "))
  156.     (setq coneRadius (getdist "Input cone radius value: "))
  157.    
  158.     ;   Sphere params input // need initget below
  159.     (setq segmentHeight (getdist "Input sphere height value: "))
  160.     (setq segmentRadius (getdist "Input sphere radius value: "))
  161.    
  162.     ;   Input end
  163.    
  164.     ;   Drawing
  165.    
  166.     (setq firstCylinderBase (VertexCircle basePoint cylinderRadius vertexCount 0))
  167.     (setq secondCylinderBase (VertexCircle basePoint cylinderRadius vertexCount cylinderHeight))   
  168.     (Cylinder firstCylinderBase secondCylinderBase)
  169.    
  170.    
  171.     (setq coneBase (VertexCircle basePoint coneRadius vertexCount cylinderHeight))
  172.     (setq conePoint (Point (car basePoint) (cadr basePoint) (+ (caddr basePoint) cylinderHeight coneHeight)))  
  173.     (Polygon coneBase)
  174.     (Cone coneBase conePoint)
  175.  
  176.     ;   Segment
  177.    
  178.     (setq segmentBase (VertexCircle basePoint segmentRadius vertexCount 0))
  179.     (Segment segmentHeight segmentRadius basePoint segmentBase vertexCount)
  180.    
  181.     ;   Segment
  182.    
  183.     ;   Connect
  184.     (ConnectPolygons secondCylinderBase coneBase)  
  185.     (ConnectPolygons firstCylinderBase segmentBase)
  186.     ;   Connect end
  187.    
  188.     ;   Drawing end
  189.  
  190.     (princ)
  191.    
  192. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement