Author Topic: Trig wieners ...  (Read 7443 times)

0 Members and 1 Guest are viewing this topic.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Trig wieners ...
« on: July 07, 2007, 04:13:53 PM »
It's been awhile since I had to do any trig and I had to solve this one today.

Can any trig wieners out there see a better way to calculate the cut off elevation in the following?



Code: [Select]
(defun _GetBatteredPileCutOffElev ( p1 p2 radius /  elevations points )

    ;;  ASCII representation is idealized elevation, side ab
    ;;  is the CL of the pile; p1 = point a, p2 = point b.
    ;;
    ;;             elev               
    ;;            ------ + b (p2)
    ;;                  /|\
    ;;                 / | \     
    ;;                /  |  \     result
    ;;               / e +---+ d --------
    ;;              /    |
    ;;      (p1) a +-----+ c
    ;;
    ;;  Angles in representation are not proportionate: Angle
    ;;  a-b-d = 90, whereas angle e-b-d equals angle c-a-b.
    ;;
    ;;  Side bd is the radius of the pile.
    ;;
    ;;  Elevation at point 'e' is the desired result.

    (-

        (apply 'max                                 ;; start elev 
            (setq elevations                               
                (mapcar 'last                               
                    (setq points                           
                        (list p1 p2)                       
                    )                                       
                )                                           
            )                                               
        )                                                   
       
        (*                                          ;; side be       
            radius                                  ;; side bd
            (cos                                    ;; cos angle a
                (atan                               ;; angle a
                    (/                              ;; tan angle a
                        (abs (apply '- elevations)) ;; side bc
                        (apply 'distance            ;; side ac
                            (mapcar                 
                               '(lambda (point)     ;; xy of point
                                    (list
                                        (car point)
                                        (cadr point)
                                    )
                                )
                                points
                            )
                        )
                    )
                )
            )
        )
    )
)

Thanks!
« Last Edit: July 07, 2007, 05:42:17 PM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Trig wieners ...
« Reply #1 on: July 07, 2007, 05:47:46 PM »
Is Z the Elevation , or Y ?

Added:
I see from your code you use Z, but it's not obvious from the Problem.
« Last Edit: July 07, 2007, 05:53:15 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Trig wieners ...
« Reply #2 on: July 07, 2007, 05:58:27 PM »
I see from your code you use Z, but it's not obvious from the Problem.

Really? I wrote 'Elevation' on both the pic and in the code header. How could I better indicate as such (genuine inquiry)?

Thanks KB.

Michael.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Trig wieners ...
« Reply #3 on: July 07, 2007, 06:13:22 PM »
I see from your code you use Z, but it's not obvious from the Problem.

Really? I wrote 'Elevation' on both the pic and in the code header. How could I better indicate as such (genuine inquiry)?

Thanks KB.

Michael.

just making sure that upendicular was actually up. ie a 3d problem rather than a planar one.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Trig wieners ...
« Reply #4 on: July 07, 2007, 06:24:52 PM »
upendicular

Bwaaa! I like.

 :-D

... ie a 3d problem rather than a planar one.

It is a 3D problem that can be solved by planar math.

:)

Edit: But could likely be solved another (more efficient) way -- which is welcomed.
« Last Edit: July 07, 2007, 06:32:09 PM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Trig wieners ...
« Reply #5 on: July 07, 2007, 07:24:08 PM »
In the remote chance anyone else deals with AutoPlant structural piles and needs to determine normal (vertical) and battered (non vertical ) pile cutoff elevations (aka the greater context) feel free to abuse --

_GetPileCutoffElev

Code: [Select]
(defun _GetPileCutoffElev ( pile / shapeinfo points result )

    ;;  Library Dependency(s): _GetBatteredPileCutOffElev.
    ;;  ---------------------------------------------------
    ;;  Caller's responsibility to ensure a valid AutoPlant
    ;;  structral object is passed as well as ensuring Auto-
    ;;  Plant structural enabler arx/dbx file(s) are loaded
    ;;  before calling this function or splat: rake in face.

    (setq shapeinfo
        (vlax-create-object
            "PSCOMWRAPPER.Ks_ComShapeInfo"
        )
    )

    (vlax-invoke
        shapeinfo
       'SetObject
        pile
    )

    (vlax-invoke
        shapeinfo
       'Getinfo
    )

    (setq result

        (if

            (<
                (apply 'distance
                    (mapcar
                       '(lambda (p) (list (car p) (cadr p)))
                        (setq points
                            (mapcar
                               '(lambda (x) (vlax-get shapeinfo x))
                               '(MidLineStart MidLineEnd)
                            )
                        )

                    )
                )
                0.001
            )

            ;;  it's a normal pile, get the highest z value   

            (apply 'max (mapcar 'last points))

            ;;  it's a battered pile, get the normalized z value

            (_GetBatteredPileCutOffElev
                (car points)
                (cadr points)
                (/ (vlax-get pile 'Width) 2.0)
            )
        )   
    )               

    (vlax-release-object shapeinfo)

    result

)

_GetBatteredPileCutOffElev

Code: [Select]
(defun _GetBatteredPileCutOffElev ( p1 p2 radius /  elevations points )

    ;;  Library Dependency(s): none.
    ;;  ----------------------------------------------------
    ;;  ASCII representation is idealized elevation, side ab
    ;;  is the CL of the pile; p1 = point a, p2 = point b.
    ;;
    ;;             elev               
    ;;            ------ + b (p2)
    ;;                  /|\
    ;;                 / | \     
    ;;                /  |  \     result
    ;;               / e +---+ d --------
    ;;              /    |
    ;;      (p1) a +-----+ c
    ;;
    ;;  Angles in representation are not proportionate: Angle
    ;;  a-b-d = 90, whereas angle e-b-d equals angle c-a-b.
    ;;
    ;;  Side bd is the radius of the pile.
    ;;
    ;;  Elevation at point 'e' is the desired result.

    (-

        (apply 'max                                 ;; start elev 
            (setq elevations                               
                (mapcar 'last                               
                    (setq points                           
                        (list p1 p2)                       
                    )                                       
                )                                           
            )                                               
        )                                                   

        (*                                          ;; side be       
            radius                                  ;; side bd
            (cos                                    ;; cos angle a
                (atan                               ;; angle a
                    (/                              ;; tan angle a
                        (abs (apply '- elevations)) ;; side bc
                        (apply 'distance            ;; side ac
                            (mapcar                 
                               '(lambda (point)     ;; xy of point
                                    (list
                                        (car point)
                                        (cadr point)
                                    )
                                )
                                points
                            )
                        )
                    )
                )
            )
        )
    )
)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Trig wieners ...
« Reply #6 on: July 07, 2007, 07:37:02 PM »
How about
Code: [Select]
(DEFUN _GetBatteredPileCutOffElev-01 (a b r)
    (- (LAST b)
       (* r
          (/ (DISTANCE (CDR (REVERSE a)) (CDR (REVERSE b))) (DISTANCE a b))
       )
    )
)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Trig wieners ...
« Reply #7 on: July 07, 2007, 07:38:40 PM »
I tried a Vector solution but I would have needed to take a packed lunch just to read it ..
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Trig wieners ...
« Reply #8 on: July 07, 2007, 07:50:17 PM »
How about ...
Code: [Select]
(DEFUN _GetBatteredPileCutOffElev-01 (a b r)
    (- (LAST b)
       (* r
          (/ (DISTANCE (CDR (REVERSE a)) (CDR (REVERSE b))) (DISTANCE a b))
       )
    )
)

If you go that route (which is pretty good) you have to ensure you start with the highest of the two points:

Code: [Select]
(defun _GetBatteredPileCutOffElev ( p1 p2 radius )
    (-  (apply 'max (mapcar 'last (list p1 p2)))
        (* radius
            (/
                (distance (cdr (reverse p1)) (cdr (reverse p2)))
                (distance p1 p2)
            )
        )
    )
)

Thanks for the edumacation KB.

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Trig wieners ...
« Reply #9 on: July 07, 2007, 08:14:48 PM »
This is what I'm going with for now.

Code: [Select]
(defun _GetBatteredPileCutOffElev ( p1 p2 radius )
    (-  (apply 'max (mapcar 'last (list p1 p2)))
        (*  radius
            (/  (distance p1 (list (car p2) (cadr p2)))
                (distance p1 p2)
            )
        )
    )
)

Thanks again KB.

Michael.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Trig wieners ...
« Reply #10 on: July 07, 2007, 08:27:58 PM »
cleaner, yep !


warning to those at home :
don't pass any of these samples a 2d point and expect it to work :-)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Trig wieners ...
« Reply #11 on: July 07, 2007, 08:41:45 PM »
Michael,

Here's a philosophical question.

If the signature specifies <LowerPoint> <HigherPoint> <radius>
why do we need to test for the MAx Z ??

///kwb
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Trig wieners ...
« Reply #12 on: July 07, 2007, 09:24:41 PM »
If the signature specifies <LowerPoint> <HigherPoint> <radius>
why do we need to test for the MAx Z ??

Good question Kerry.

The way AutoPlant creates the piles there is no guarantee that
either the MidLineStart or MidLineEnd property is higher or lower
than the other, simply that they are at opposite ends of the
pile. Since it has to be determined somewhere it might as well
be _GetBatteredPileCutOffElev.

PS: Does 'A' imply it is a lower (or higher) point than 'B'?

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Trig wieners ...
« Reply #13 on: July 07, 2007, 09:32:25 PM »
...................PS: Does 'A' imply it is a lower (or higher) point than 'B'?

:)

I thought I read it in the docs :D


Quote
"B" is the 'Battered' end.

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Trig wieners ...
« Reply #14 on: July 07, 2007, 09:35:23 PM »
Ha!

Question: Is it hotter in Brisbane or summer?

 :lol:
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst