Jump to content

Search the Community

Showing results for tags 'math'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • CADTutor
    • News, Announcements & FAQ
    • Feedback
  • AutoCAD
    • AutoCAD Beginners' Area
    • AutoCAD 2D Drafting, Object Properties & Interface
    • AutoCAD Drawing Management & Output
    • AutoCAD 3D Modelling & Rendering
    • AutoCAD Vertical Products
    • AutoCAD LT
    • CAD Management
    • AutoCAD Bugs, Error Messages & Quirks
    • AutoCAD General
    • AutoCAD Blogs
  • AutoCAD Customization
    • The CUI, Hatches, Linetypes, Scripts & Macros
    • AutoLISP, Visual LISP & DCL
    • .NET, ObjectARX & VBA
    • Application Beta Testing
    • Application Archive
  • Other Autodesk Products
    • Autodesk 3ds Max
    • Autodesk Revit
    • Autodesk Inventor
    • Autodesk Software General
  • Other CAD Products
    • BricsCAD
    • SketchUp
    • Rhino
    • SolidWorks
    • MicroStation
    • Design Software
    • Catch All
  • Resources
    • Tutorials & Tips'n'Tricks
    • AutoCAD Museum
    • Blocks, Images, Models & Materials
    • Useful Links
  • Community
    • Introduce Yourself
    • Showcase
    • Work In Progress
    • Jobs & Training
    • Chat
    • Competitions

Categories

  • Programs and Scripts
  • 2D AutoCAD Blocks
  • 3D AutoCAD Blocks
  • Images
    • Backgrounds

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Found 2 results

  1. I am pretty new to lisp programming and have only been working in it for a few months and I am pretty stuck on how to get this lisp program I've hacked together into what I need. Any help would be greatly appreciated. I would like help optimizing the lisp to be more like autocad's save as an old dxf way of converting an ellipse to a polyline. The current way I am converting an ellipse to poly line is by moving a static degree of distance between each point, the way I cannot figure out and the ideal way for me to do this is by specifying the maximum gap between the true ellipse and the polyline version. I have looked at other lisp programs out there and they are not high resolution enough for what I need, I need the data to be extremely close to the actual ellipse. I would appreciate help in pointing me towards how to do this mathematically, help implement that into a lisp, and any tips on best practice lisp programming that I might be really messing up here. Below is the function I have written to handle this so far, it takes in el which is the vla ellipse object and angleIncrement which is the degree difference between two points of the polyline. In a perfect world the second argument would be changed to be the maximum distance between the true ellipse and the polyline version. This is a function used in another script that then chains the data and does a few other things as well. (defun EllipseToLine (el angleIncrement / majorradius minorradius startangle endangle startpoint endpoint centerpoint tempVar) (vl-load-com) (setvar "cmdecho" 0) (setq majorradius (vla-get-MajorRadius el)) (setq minorradius (vla-get-MinorRadius el)) (setq startangle (* (vla-get-StartAngle el) (/ 180 pi))) (setq endangle (* (vla-get-EndAngle el)(/ 180 pi))) (setq startpoint (vlax-safearray->list (vlax-variant-value (vla-get-startpoint el)))) (setq endpoint (vlax-safearray->list (vlax-variant-value (vla-get-endpoint el)))) (setq centerpoint (vlax-safearray->list (vlax-variant-value (vla-get-center el)))) (setq centerx (nth 0 centerpoint)) (setq centery (nth 1 centerpoint)) (princ "End angle: ")(princ endangle)(princ "\n") (princ "Start angle: ")(princ startangle)(princ "\n") (setq startx (nth 0 startpoint)) (setq starty (nth 1 startpoint)) (setq endx (nth 0 endpoint)) (setq endy (nth 1 endpoint)) ; make sure we convert the ellipse on the correct layer and then later return to the layer we were on (setq ellipseLayer (vla-get-layer el)) (setq currentLayer (getvar "clayer")) (setvar "clayer" ellipseLayer) ; calculate angle between start angle and start point because the start point ; is not at the start angle so we have to adjust so numbers match up (setq angleOffset (- (* (angle centerpoint startpoint) (/ 180 pi)) startangle)) (setq radianOffset (* angleOffset (/ pi 180))) ; a = major radius ; b = minor radius (setq ecc (sqrt (- 1 (/ (expt minorradius 2) (expt majorradius 2))))) (setq angleInverted 0) (setq done 0) (setq i 0) (setq currentAngle startangle) (setq nintyDegrees 90.0) (setq twoHundredSeventyDegrees 270.0) (while (= done 0) (if (< currentAngle 0) (progn (setq currentAngle (+ currentAngle 360)) (setq angleInverted 1) ) ) (if (> currentAngle 360) (progn (setq currentAngle (- currentAngle 360)) (setq angleInverted 1) ) ) (cond ((or (and (> startangle endangle) (= angleInverted 0)) (and (> endangle startangle) (= angleInverted 1))) (if (< currentAngle endangle) (setq currentAngle endangle) ) ) ((or (and (> endangle startangle) (= angleInverted 0)) (and (> startangle endangle) (= angleInverted 1))) (if (> currentAngle endangle) (setq currentAngle endangle) ) ) ) (setq newAngle currentAngle) (if (or (> newAngle 0) (< newAngle 0)) (setq newAngle (* newAngle (/ pi 180))) ) (setq factor -1) (if (or (<= currentAngle nintyDegrees) (>= currentAngle twoHundredSeventyDegrees)) (setq factor 1) ) ; using the origional un rotated angle get the next point on the ellipse (setq x2 (/ (* majorradius minorradius) (* factor (sqrt (+ (expt minorradius 2) (* (expt majorradius 2) (expt (/ (sin newAngle) (cos newAngle)) 2))))))) (setq y2 (* x2 (/ (sin newAngle) (cos newAngle)))) (setq x2 (+ x2 centerx) y2 (+ y2 centery) ) ; rotate point on the ellipse by radian/angle offset so it matches the cad data (setq rotatedx (+ (- (* (cos radianOffset) (- x2 centerx)) (* (sin radianOffset) (- y2 centery))) centerx)) (setq rotatedy (+ (+ (* (sin radianOffset) (- x2 centerx)) (* (cos radianOffset) (- y2 centery))) centery)) (setq x2 rotatedx y2 rotatedy ) (if (= currentAngle endangle) (setq done 1) ) (if (> i 0) (if (= i 1) (command "_.line" (strcat (rtos startx) "," (rtos starty)) (strcat (rtos x2) "," (rtos y2)) "") (if (= done 1) (command "_.line" (strcat (rtos x1) "," (rtos y1)) (strcat (rtos endx) "," (rtos endy)) "") (command "_.line" (strcat (rtos x1) "," (rtos y1)) (strcat (rtos x2) "," (rtos y2)) "") ) ) ) (setq x1 x2 y1 y2 ) (setq currentAngle (+ currentAngle angleIncrement) i (+ 1 i) ) ) ; delete the origional ellipse (vla-delete el) (setvar "clayer" currentLayer) (princ) )
  2. I'm trying to write a routine to draw a style of cover that we use regularly, but I'm having trouble getting past the math functions in lisp. I should clarify that I don't have a clue on .lsp programing; so any help must take that into consideration to save both of us a lot of headaches. Here is what I have so far: (defun c:SBC () (defun dtr (deg) (* deg (/ pi 180)) ) (setvar "cmdecho" 0) ; Data Input (prompt "\nENTER ALL DIMENSIONS IN DECIMALS ") (setq mthk (getreal "\nEnter Material Thickness: ")) (setq ikr (getreal "\nEnter Cover I/S Knuckle Radius: ")) (setq csf (getreal "\nEnter Cover Straight Flange: ")) (setq covrad (getreal "\nEnter Cover I/S Radius: ")) (setq covlng (getreal "\Enter Cover I/S Length: ")) (prompt "\nEnter Lip I/S Dimension: : ")) (if (= lip nil) (setq lip 0.4375)) (prompt "\nEnter Hinge I/S Width: : ")) (if (= hw nil) (setq hw 1.0)) (setq hdp (getreal "\nEnter Hinge I/S Depth: ")) ; Calculations ;Inside Bend Radius (setq isbr (/ mthk 2)) ;Included Bend Angle at Lip (setq iba1 (dtr 90)) ;Centerline Bend Radius (setq cbr1 (= mthk)) ;Centerline Arc Length at Lip (setq cal1 ((* cbr1 2 pi iba1) / 360))) ;Centerline Arc Length/2 at Lip (setq hafcal1 (cal1 / 2)) ;Centerline Bend Radius at Flange (setq cbr2 ((mthk / 2) + ikr) ;Included Bend Angle at Flange (setq iba2 (angle 90)) ;Centerline Arc Length at Flange (setq cal2 (cbr2 * 2 * pi * iba2 / 360)) ;Circle Blank Radius (setq cirbr (covrad - ikr + cal2 + csf)) )
×
×
  • Create New...