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 / smSgmBaseList smCircleRadius smSgmBase prevBase circleRadius idx radiusParam )
- (setq circleRadius (SegmentCirecleRadius segmentRadius segmentHeight))
- (setq idx 9)
- (setq smSgmBaseList (list))
- (repeat 9
- (setq radiusParam (/ 10.0 idx))
- (setq smCircleRadius (SmallSegmentRadius segmentRadius segmentHeight radiusParam))
- (setq smSgmBase (VertexCircle basePoint smCircleRadius vertexCount (- segmentHeight (/ segmentHeight radiusParam))))
- (setq smSgmBaseList (append smSgmBaseList (list smSgmBase)))
- (setq idx (- idx 1))
- )
- (Polygon points)
- (setq prevBase points)
- (foreach sgmBase smSgmBaseList
- (progn
- (Polygon sgmBase)
- (ConnectPolygons prevBase sgmBase)
- (setq prevBase sgmBase)
- (princ)
- )
- )
- (setq basePoint (list (car basePoint) (cadr basePoint) (+ (caddr basePoint) segmentHeight)))
- (ConnectPolygons (car smSgmBaseList) points)
- (Cone (last smSgmBaseList) 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 20) ; 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