View Single Post
  #2  
Old 06-17-2015, 06:05 AM
jkramer's Avatar
jkramer jkramer is offline
Registered User
 
Join Date: Oct 2002
Location: the Netherlands
Posts: 382
Re: Circular slot in Modeling

Hi,

just came across your post, and couldn't resist...
This kind of slots are too common not to have a button for it :-)
Here's my way of doing it. The code could be shorter if I would have nested some formulas, but this makes all the math easier to understand for myself...
If you copy-paste the code below to an empty text file with the extension .lsp, it should work.
By the way, I assumed that you wanted to draw a circular slot on a workplane. For creating one in an Annotation Drawing, a couple of things need to be changed.
Code:
(in-package :JAAPS_TOOLS)
(use-package :OLI)

(sd-defdialog 'circular_slot
  :dialog-title "Circular Slot"
  :toolbox-button t
  :variables
  '(
    (point_1 :value-type :point-2d
	     :Title "Center"
		 :next-variable 'point_2
	)
    (point_2 :value-type :point-2d
	     :title "Pick Point"
		 :next-variable 'width
	)
    (width :value-type :positive-length
	   :title "Width"
	   :next-variable 'angle
	)
	(angle :value-type :number :title "+/- Angle")
	(GO :toggle-type :wide-toggle :title "Create Slot!" :push-action (progn
	(sd-call-cmds(create_circular_slot point_1 point_2 width angle))
	:next-variable 'point_1
	(setf point_1 nil)
	(setf point_2 nil)
	);progn
	)
	);variables
 	:local-functions
  	'(
)

	:ok-action 
	'()
)

(defun create_circular_slot (point_1 point_2 width angle)
			(setf angle (/ (* pi angle) 180))
			(setf point_1_x (gpnt2d_x point_1))
			(setf point_1_y (gpnt2d_y point_1))
			(setf point_2_x (gpnt2d_x point_2))
			(setf point_2_y (gpnt2d_y point_2))
			(setf delta_x (- point_2_x point_1_x))
			(setf delta_y (- point_2_y point_1_y))
			(setf radius (sqrt (+ (expt delta_x 2) (expt delta_y 2))))
			(setf r_max (+ radius (/ width 2)))
			(setf r_min (- radius (/ width 2)))
			(setf abs_angle (asin (/ delta_y radius)))
			(if (< delta_x 0) (setf abs_angle (- pi abs_angle))())
			(setf angle_1 (- abs_angle angle))
			(setf angle_2 (+ abs_angle angle))
			(setf begin_1_x (* r_min (cos angle_1)))
			(setf begin_1_y (* r_min (sin angle_1)))
			(setf center_1_x (* radius (cos angle_1)))
			(setf center_1_y (* radius (sin angle_1)))
			(setf end_1_x (* r_max (cos angle_1)))
			(setf end_1_y (* r_max (sin angle_1)))
			(setf begin_2_x (* r_max (cos angle_2)))
			(setf begin_2_y (* r_max (sin angle_2)))
			(setf center_2_x (* radius (cos angle_2)))
			(setf center_2_y (* radius (sin angle_2)))
			(setf end_2_x (* r_min (cos angle_2)))
			(setf end_2_y (* r_min (sin angle_2)))
			(setf begin_1 (gpnt2d begin_1_x begin_1_y))
			(setf center_1 (gpnt2d center_1_x center_1_y))
			(setf end_1 (gpnt2d end_1_x end_1_y))
			(setf begin_2 (gpnt2d begin_2_x begin_2_y))
			(setf center_2 (gpnt2d center_2_x center_2_y))
			(setf end_2 (gpnt2d end_2_x end_2_y))
			(ARC :CENTER center_1 begin_1 end_1)
			(ARC :CENTER center_2 begin_2 end_2)
			(ARC :CENTER point_1 begin_1 end_2)
			(ARC :CENTER point_1 end_1 begin_2)
);defun
Reply With Quote