# I need help to create a lsp file or application.0* ## Recommended Posts  Designing an algorithm and creating a computer application for determining the centers of gravity for a die and calculating the center of pressure of cold forming equipmen*06

##### Share on other sites  attached Example drawing

##### Share on other sites  I send a private message here are the link with pictures:

##### Share on other sites  Helping you create something - is this somethng you do just now manually and in which case, what is the procedure you use -write down the steps you use and then it becomes a lot easier

##### Share on other sites  Posted (edited)

Basically I need

What is the code for Creating an algorithm and developing a computer application to determine the centers of gravity for a cylindrical or prismatic-shaped bar and calculate the center of pressure for cold forming equipment using AutoCAD LISP. I dont know the code is work and is good

```(defun c:CalculateCenters ()
(setq num-parts (getint "\nEnter the number of parts: "))

(setq parts '())
(repeat num-parts
(setq shape (getstring "\nEnter shape (cylindrical/prismatic) for part " (itoa (+ 1 num-parts)) ": "))
(setq mass (getreal (strcat "\nEnter mass of part " (itoa (+ 1 num-parts)) ": ")))
(setq x (getreal (strcat "\nEnter x-coordinate of part " (itoa (+ 1 num-parts)) ": ")))
(setq y (getreal (strcat "\nEnter y-coordinate of part " (itoa (+ 1 num-parts)) ": ")))
(setq parts (cons (list shape mass x y) parts)))

(setq forces '())
(setq distances '())
(repeat num-parts
(setq force (getreal (strcat "\nEnter force " (itoa (+ 1 num-parts)) " applied: ")))
(setq distance (getreal (strcat "\nEnter distance " (itoa (+ 1 num-parts)) " from reference point: ")))
(setq forces (cons force forces))
(setq distances (cons distance distances)))

;; Call functions to calculate centers of gravity and pressure
(setq center-of-gravity (calculate-center-of-gravity parts))
(setq center-of-pressure (calculate-center-of-pressure forces distances))

(alert (strcat "Center of Gravity:\nX: " (rtos (car center-of-gravity) 2 2) "\nY: " (rtos (cadr center-of-gravity) 2 2)))
(alert (strcat "Center of Pressure: " (rtos center-of-pressure 2 2)))
)

(defun calculate-center-of-gravity (parts)
;; Calculate center of gravity logic
;; Modify this function based on your shape-specific calculations
(setq total-mass (apply '+ (mapcar 'cadr parts)))
(setq weighted-sum-x (apply '+ (mapcar (lambda (part) (* (cadr part) (caddr part))) parts)))
(setq weighted-sum-y (apply '+ (mapcar (lambda (part) (* (cadr part) (cadddr part))) parts)))
(list (/ weighted-sum-x total-mass) (/ weighted-sum-y total-mass))
)

(defun calculate-center-of-pressure (forces distances)
;; Calculate center of pressure logic
;; Modify this function based on your specific calculation requirements
(setq total-force (apply '+ forces))
(setq weighted-sum (apply '+ (mapcar '* forces distances)))
(/ weighted-sum total-force)
)
```

Edited by SLW210
##### Share on other sites  ##### Share on other sites  45 minutes ago, andreiprundeanu said:

Basically I need

What is the code for Creating an algorithm and developing a computer application to determine the centers of gravity for a cylindrical or prismatic-shaped bar and calculate the center of pressure for cold forming equipment using AutoCAD LISP. I dont know the code is work and is good

```(defun c:CalculateCenters ()
(setq num-parts (getint "\nEnter the number of parts: "))

(setq parts '())
(repeat num-parts
(setq shape (getstring "\nEnter shape (cylindrical/prismatic) for part " (itoa (+ 1 num-parts)) ": "))
(setq mass (getreal (strcat "\nEnter mass of part " (itoa (+ 1 num-parts)) ": ")))
(setq x (getreal (strcat "\nEnter x-coordinate of part " (itoa (+ 1 num-parts)) ": ")))
(setq y (getreal (strcat "\nEnter y-coordinate of part " (itoa (+ 1 num-parts)) ": ")))
(setq parts (cons (list shape mass x y) parts)))

(setq forces '())
(setq distances '())
(repeat num-parts
(setq force (getreal (strcat "\nEnter force " (itoa (+ 1 num-parts)) " applied: ")))
(setq distance (getreal (strcat "\nEnter distance " (itoa (+ 1 num-parts)) " from reference point: ")))
(setq forces (cons force forces))
(setq distances (cons distance distances)))

;; Call functions to calculate centers of gravity and pressure
(setq center-of-gravity (calculate-center-of-gravity parts))
(setq center-of-pressure (calculate-center-of-pressure forces distances))

(alert (strcat "Center of Gravity:\nX: " (rtos (car center-of-gravity) 2 2) "\nY: " (rtos (cadr center-of-gravity) 2 2)))
(alert (strcat "Center of Pressure: " (rtos center-of-pressure 2 2)))
)

(defun calculate-center-of-gravity (parts)
;; Calculate center of gravity logic
;; Modify this function based on your shape-specific calculations
(setq total-mass (apply '+ (mapcar 'cadr parts)))
(setq weighted-sum-x (apply '+ (mapcar (lambda (part) (* (cadr part) (caddr part))) parts)))
(setq weighted-sum-y (apply '+ (mapcar (lambda (part) (* (cadr part) (cadddr part))) parts)))
(list (/ weighted-sum-x total-mass) (/ weighted-sum-y total-mass))
)

(defun calculate-center-of-pressure (forces distances)
;; Calculate center of pressure logic
;; Modify this function based on your specific calculation requirements
(setq total-force (apply '+ forces))
(setq weighted-sum (apply '+ (mapcar '* forces distances)))
(/ weighted-sum total-force)
)
```

@andreiprundeanu as far as I know , gravity center can be get direct from acad. .  also the center of pressure please upload a sample.DWG

## 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. Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.