Jump to content

Recommended Posts

Posted

Hello everyone. I am trying to write a program to automate the process of drawing stone segment coverings. It is labour intensive and prone to errors when done by hand. Everything is actually just mathematical calculations, so it is just fine for the LISP to draw it.

 

I got to a certain level of code that asks for user input of circle radius, stone thickness, calculates the minimum amount of segment that will fit within our production tolerances and creates each individual segment piece accordingly. I manage to calculate and increase the number of segment pieces to an even number when the simplest connection height for the segment template exceeds 150+50mm that we have. 

My second step, which I am currently stuck on, is to create the bottom of the template. This is a 2mm offset from the inner lines of the segment pieces, I cannot wrap my head around this and locate points with the polar command I used to create the segment pieces.

 

I think it would be better to create another function for the template piece, but I cannot calculate the offset intersection points of the segment poly line using basic trigonometry as I used to calculate individual segment piece points and rotate them according to angle and polar function.

Any help would be greatly appreciated.

 

(please ignore all the alert and princ commands in the code. I am using AutoCAD LT and do not have VLIDE therefore i am using those to find out syntax errors our function errors etc.)

 

(defun c:SRV1
       (/
        msg
        osm
        radius
        steinstärke
        segmentformuserinput
        segmentform
        tscondition
        tsegment
        degreeinhalfarch
        TriangleH
        midpotl
        segmentoffset
        segmentminsmalledge
        small1
        centerpt
        pt1
        pt2
        pt3
        pt4
        pt5
        pt6
        pointincrement
        osm
        segmentform
        turns
        turnsdegree
        i
        apt1
        apt2
        apt3
        segmentformuserinput
        schablone
        fräsehohe
        fleisch
        
        )


(defun *error* ( msg )   
    (setvar "filedia" 1)
    (setvar 'Cmdecho 1)    
           
        (if osm (setvar "osmode" osm));OSnap mode other than nil, change it back to osm
         (and msg (not (wcmatch (strcase msg) "*CANCEL*,*QUIT*,*BREAK*"))
        (princ (strcat "\n" msg))
        )
  (princ)
  (exit)
)

;(initget (+ 1 2 4))
(setq radius (getint "Enter radius"))
;(initget (+ 1 2 4))
(setq steinstärke (getint "Enter Steinstärke"))
  
(setq
osm (getvar 'osmode) ;os mode saved
segmentformuserinput 181
turns 0
turnsdegree nil
i 1
minsegmentcount nil
tsegmentdefault 1
degreeinhalfarch nil
segmentoffset 3
segmentsectionoffset 1
segmentminsmalledge 10
small1 0
pointincrement pi
pt1 nil
pt2 nil
pt3 nil
pt4 nil
pt5 nil
pt6 nil
apt1 nil
apt2 nil
apt3 nil
schablone nil
centerpt (getpoint "Centerpoint for the circle");'(0.0 0.0 0.0);
Segmentwith3offset (+ radius segmentoffset)
segmentwith1offset (+ radius segmentsectionoffset)
fräsehohe 150
fleisch nil
tscondition nil
;fleischcondition nil
x 1
)
;;(alert "1")  
(setvar 'Cmdecho 0 ) 
(setvar 'osmode 0);osmode null
(while (or (<= segmentformuserinput 0) (> segmentformuserinput 180))
  ;;(alert "2") 
   (setq
   segmentformuserinput (getreal "Enter Segment Degree 90 for Quarter 180 for half 360 for Circular etc.")
   segmentform (* (/ segmentformuserinput 180.00) pi)
   )
 )   

(defun tsegmentrechner (ts tscondition / )
;;(alert "3")
;(setq degreeinhalfarch (/ segmentform 2 ts) ) 
    (while (or (<= small1 segmentminsmalledge) (> small1 steinstärke) (= tscondition 1))
      (setq degreeinhalfarch (/ segmentform 2 ts)
            TriangleH (* (cos degreeinhalfarch) radius)
            midpotl (- TriangleH (- (+ radius segmentoffset) steinstärke))
            small (/ midpotl (cos degreeinhalfarch))
            small1 (1+ small)
            turnsdegree (* 2 degreeinhalfarch)
            turns (/ segmentform turnsdegree)
            tscondition nil
      )
      ;;(alert "4") 
        (if  (or (<= small1 segmentminsmalledge) (> small1 steinstärke))
        (setq ts (1+ ts)
        tsegment ts
        )        
        )
      ;;(alert "4.1")
      ;;(alert (strcat "degreeinhalfarch inside tsegmentrechner " (angtos degreeinhalfarch)) )
      ;(terpri)(princ degreeinhalfarch)(terpri);(princ midpotl)(terpri)(princ small)
    )
  )


;(alert "5") 

  (defun segmentdrawer (halfangle / )
  (while (<= i turns)
    ;(alert "6") 
     (setq

    pt1 (polar centerpt pointincrement (/ (- Segmentwith3offset steinstärke) (cos halfangle)))
    pt2 (polar centerpt pointincrement segmentwith1offset)
    pt3sidelenght (- Segmentwith3offset (* segmentwith1offset (cos halfangle)))
    pt3 (polar pt2 (- pointincrement halfangle) pt3sidelenght)
    pt4 (polar pt3 (- pointincrement halfangle (/ pi 2)) (* 2 (- (* (/ Segmentwith3offset (cos halfangle)) (sin halfangle)) (* (/ pt3sidelenght (cos halfangle)) (sin halfangle)))))
    pt5 (polar pt4 (- pointincrement halfangle pi) pt3sidelenght)
    pt6 (polar centerpt (- pointincrement (* 2 halfangle)) (/ (- Segmentwith3offset steinstärke) (cos halfangle)))
    apt1 (polar centerpt pointincrement radius)
    apt2 (polar centerpt (- pointincrement halfangle) radius)
    apt3 (polar centerpt (- pointincrement turnsdegree) radius)       
    )
    ;(alert "7") 
    (command-s "_.pline" pt1 pt2 pt3 pt4 pt5 pt6 pt1 "")
    (command-s "_.arc" apt1 apt2 apt3 "")
    (setq
    pointincrement (- pointincrement turnsdegree)
    i (1+ i)
    )
    ;(alert "8")     
  )
  )
;(alert "9")
(tsegmentrechner 1 nil)
;(alert (angtos degreeinhalfarch))  
;(alert (strcat "tsegment count " (rtos tsegment)))
;(alert "10")
(setq
  fleisch (- Segmentwith3offset (* radius (cos (/ segmentform 2))))
)
;(alert (rtos fleisch))  
;(alert "11")
(if (<= fleisch fräsehohe)
   (progn
    ;(alert "15 segment 1 teilig yeterli") 
    (segmentdrawer degreeinhalfarch)  
   )
)
  
(while (>= fleisch fräsehohe)
  ;(alert "12")
        (if (= (rem tsegment 2) 0) ;if tsegment even or uneven
            (progn ;if rem even
              ;(alert "13.1 schablone muss mehr teilig sein")
              (segmentdrawer degreeinhalfarch)
              ;(alert (rtos fleisch)) 
              (setq 
                x (1+ x)
                fleisch (- Segmentwith3offset (* radius (cos (/ segmentform 2 x))))
              )
              ;(alert "13.2")
              ;(alert (rtos fleisch)) 
            ); if rem uneven
            (progn
              ;(alert (strcat "tsegment before count " (rtos tsegment)))
              ;(alert (angtos degreeinhalfarch)) 
              (setq tsegment (1+ tsegment))
              ;(alert "14 tsegment +1 kondu ve segment mehrteilig olmali")
              (tsegmentrechner tsegment 1)
              ;(alert (strcat "tsegment after count " (rtos tsegment)))
              ;(alert (angtos degreeinhalfarch))
              (segmentdrawer degreeinhalfarch)
              (setq 
                x (1+ x)
                fleisch (- Segmentwith3offset (* radius (cos (/ segmentform 2 x))))
              )
              ;(alert "14.1")
              ;(alert (rtos fleisch))               
            ) 
        );if rem ende
    
  );if else fleisch 150 den kücükse
  
(command "_.point" centerpt)
(princ)
(*error* "Program finished succesfully /n")  
  
)

 

Screenshot 2024-01-19 132356.png

Screenshot 2024-01-18 155633.png

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...