Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defun Point(x y z)
- (list x y z)
- )
- (defun Line (from to)
- (entmakex
- (list
- (cons 0 "line")
- (cons 10 from)
- (cons 11 to)
- )
- )
- )
- (defun Polygon (points)
- (apply 'command
- (append
- '(".3dpoly")
- points
- '("")
- )
- )
- (princ)
- )
- (defun Arc (center radius sAng eAng)
- (entmakex
- (list (cons 0 "ARC")
- (cons 10 center)
- (cons 40 radius)
- (cons 50 sAng)
- (cons 51 eAng)
- )
- )
- )
- (defun SegmentCirecleRadius (segmentRadius segmentHeight / circleRadius)
- (setq circleRadius (/ (+ (* segmentHeight segmentHeight) (* segmentRadius segmentRadius)) (* segmentHeight 2)))
- )
- (defun SmallSegmentRadius (segmentRadius segmentHeight factor / result hSqr rSqr fSqr)
- (setq hSqr (* segmentHeight segmentHeight))
- (setq rSqr (* segmentRadius segmentRadius))
- (setq fSqr (* factor factor))
- (setq result
- (sqrt
- (+
- (- (* hSqr factor) (* hSqr fSqr))
- (* rSqr factor)
- )
- )
- )
- )
- (defun Segment (segmentHeight segmentRadius basePoint points vertexCount / smSgmBase2 smSgmBase3 circleRadius smCircleRadius2 smCircleRadius3 idx bases)
- (setq circleRadius (SegmentCirecleRadius segmentRadius segmentHeight))
- (setq smCircleRadius2 (SmallSegmentRadius segmentRadius segmentHeight 0.5))
- (setq smCircleRadius3 (SmallSegmentRadius segmentRadius segmentHeight 0.33))
- (setq smCircleRadius4 (SmallSegmentRadius segmentRadius segmentHeight 0.25))
- (setq smCircleRadius5 (SmallSegmentRadius segmentRadius segmentHeight 0.10))
- (setq smSgmBase2 (VertexCircle basePoint smCircleRadius2 vertexCount (/ segmentHeight 2)))
- (setq smSgmBase3 (VertexCircle basePoint smCircleRadius3 vertexCount (- segmentHeight (/ segmentHeight 3))))
- (setq smSgmBase4 (VertexCircle basePoint smCircleRadius3 vertexCount (- segmentHeight (/ segmentHeight 4))))
- (setq smSgmBase5 (VertexCircle basePoint smCircleRadius3 vertexCount (- segmentHeight (/ segmentHeight 10))))
- (setq basePoint (list (car basePoint) (cadr basePoint) (+ (caddr basePoint) segmentHeight)))
- (Polygon points)
- ;(Polygon smSgmBase2)
- ;(Polygon smSgmBase4)
- (ConnectPolygons points smSgmBase2)
- (ConnectPolygons smSgmBase2 smSgmBase3)
- (ConnectPolygons smSgmBase3 smSgmBase4)
- (ConnectPolygons smSgmBase4 smSgmBase5)
- ;(Cone smSgmBase5 basePoint)
- )
- (defun ConnectPolygons(firstPolygon secondPolygon)
- (mapcar '(lambda (from to)
- (Line from to)
- )
- firstPolygon
- secondPolygon
- )
- )
- (defun Cone(polygon point)
- (mapcar '(lambda (polygonPoint)
- (Line polygonPoint point)
- )
- polygon
- )
- )
- (defun Cylinder(firstCylinderBase secondCylinderBase)
- (Polygon firstCylinderBase)
- (Polygon secondCylinderBase)
- (ConnectPolygons firstCylinderBase secondCylinderBase)
- )
- (defun VertexCircle(basePoint radius vertexCount zValue / polygon baseAngle currentPoint idx)
- (setq baseAngle (/ (* 2 pi) vertexCount))
- (setq idx 1)
- (setq currentPoint (polar basePoint 0 radius))
- (setq currentPoint (Point (car currentPoint) (cadr currentPoint) (+ zValue (caddr currentPoint))))
- (setq polygon (list currentPoint))
- (repeat vertexCount
- (setq currentPoint (polar basePoint (* baseAngle idx) radius))
- (setq currentPoint (Point (car currentPoint) (cadr currentPoint) (+ zValue (caddr currentPoint))))
- (setq polygon (append polygon (list currentPoint)))
- (setq idx (+ idx 1))
- )
- (setq polygon polygon)
- )
- (defun c:draw(/ basePoint
- cylinderHeight
- coneHeight
- cylinderRadius
- coneRadius
- vertexCount
- firstCylinderBase
- secondCylinderBase
- coneBase
- conePoint
- segmentHeight
- segmentRadius)
- ; Input
- (setq vertexCount 50) ; Vertex count constant // OK
- ; Base point input // need initget below
- (setq basePoint (getpoint "Input base point for figure: "))
- ; Cylinder params input // need initget below
- (setq cylinderHeight (getdist "Input cylinder height value: "))
- (setq cylinderRadius (getdist "Input cylinder radius value: "))
- ; Cone params input // need initget below
- (setq coneHeight (getdist "Input cone height value: "))
- (setq coneRadius (getdist "Input cone radius value: "))
- ; Sphere params input // need initget below
- (setq segmentHeight (getdist "Input sphere height value: "))
- (setq segmentRadius (getdist "Input sphere radius value: "))
- ; Input end
- ; Drawing
- (setq firstCylinderBase (VertexCircle basePoint cylinderRadius vertexCount 0))
- (setq secondCylinderBase (VertexCircle basePoint cylinderRadius vertexCount cylinderHeight))
- (Cylinder firstCylinderBase secondCylinderBase)
- (setq coneBase (VertexCircle basePoint coneRadius vertexCount cylinderHeight))
- (setq conePoint (Point (car basePoint) (cadr basePoint) (+ (caddr basePoint) cylinderHeight coneHeight)))
- (Polygon coneBase)
- (Cone coneBase conePoint)
- ; Segment
- (setq segmentBase (VertexCircle basePoint segmentRadius vertexCount 0))
- (Segment segmentHeight segmentRadius basePoint segmentBase vertexCount)
- ; Segment
- ; Connect
- (ConnectPolygons secondCylinderBase coneBase)
- (ConnectPolygons firstCylinderBase segmentBase)
- ; Connect end
- ; Drawing end
- (princ)
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement