Jump to content

Recommended Posts

Posted

Hello,

 

I would like to select sun azimuth by block grip on my drawing.

1. I created a block with two grips (attached DWG)

2. LISP definition that gives an array of hour:minute and azimuth (radians).

 

So I need to update the value of attribute TIME1 and TIME2 when my grip changes. My problem can be probably solved by reactor. There is also a problem that the sun azimuth is defined from the north. Angle for grips in my block are defined in different way so i need to recalculate my azimuths.

 

I appreciate any responce.

 

Greetings

Marcin

 

 

(defun c:sun-azimuth-array ( / lat lon year month day jd jc gmst lst ha decl azimuth time-list)
  ;; Utility functions
  (defun deg-to-rad (deg) (* pi (/ deg 180.0)))
  (defun rad-to-deg (rad) (* 180.0 (/ rad pi)))
  (defun mod (a b) (- a (* b (fix (/ a b)))))
  
  ;; Inverse sine function
  (defun asin (x)
    (atan (/ x (sqrt (- 1 (* x x)))))
  )

  ;; Tangent function
  (defun tan (x)
    (/ (sin x) (cos x))
  )

  ;; Function to calculate Julian Date
  (defun julian-date (year month day hour minute second)
    (setq a (fix (/ (- 14 month) 12)))
    (setq y (+ year 4800 a))
    (setq m (+ month (* 12 a) -3))
    (+ day
       (/ (- (* 153 (+ m 1)) 2) 5)
       (* 365 y)
       (/ y 4)
       (/ (- y 100) 100)
       (/ y -400)
       -32045
       (/ (+ hour (/ minute 60.0) (/ second 3600.0)) 24.0)
    )
  )

  ;; Function to calculate Sun Azimuth
  (defun sun-azimuth (lat lon jd)
    ;; Calculate Julian Century
    (setq jc (/ (- jd 2451545.0) 36525.0))

    ;; Calculate Greenwich Mean Sidereal Time
    (setq gmst (mod (+ 280.46061837 (* 360.98564736629 (- jd 2451545.0)) (* 0.000387933 (* jc jc)) (/ (* jc jc jc) -38710000.0)) 360.0))

    ;; Local Sidereal Time
    (setq lst (mod (+ gmst (rad-to-deg lon)) 360.0))

    ;; Calculate Mean Anomaly of the Sun
    (setq m (mod (+ 357.5291 (* 35999.0503 jc)) 360.0))

    ;; Calculate Mean Longitude of the Sun
    (setq l0 (mod (+ 280.46646 (* 36000.76983 jc) (* 0.0003032 (* jc jc))) 360.0))

    ;; Calculate Ecliptic Longitude of the Sun
    (setq c (+ (* (sin (deg-to-rad m)) 1.914602) (* (sin (deg-to-rad (* 2 m))) 0.019993) (* (sin (deg-to-rad (* 3 m))) 0.000289)))
    (setq lambda (+ l0 c))

    ;; Calculate Declination of the Sun
    (setq eps (deg-to-rad (+ 23.439 (- (* 0.00000036 jc)))))
    (setq decl (asin (* (sin eps) (sin (deg-to-rad lambda)))))

    ;; Calculate Hour Angle
    (setq ha (- lst (rad-to-deg lambda)))

    ;; Convert Hour Angle and Latitude to Radians
    (setq ha (deg-to-rad ha))

    ;; Calculate Azimuth in Radians
    (setq azimuth (atan (/ (sin ha) (- (* (cos ha) (sin lat)) (* (tan decl) (cos lat))))))

    azimuth
  )

  ;; User inputs
  (setq lat (deg-to-rad (getreal "\nEnter latitude: ")))
  (setq lon (deg-to-rad (getreal "\nEnter longitude: ")))
  (setq year (getint "\nEnter year: "))
  (setq month (getint "\nEnter month: "))
  (setq day (getint "\nEnter day: "))

  ;; Initialize the list
  (setq time-list '())

  ;; Loop through each minute from 6:00 to 18:00
  (setq hour 6)
  (while (<= hour 18)
    (setq minute 0)
    (while (< minute 60)
      ;; Calculate Julian Date for the current time
      (setq jd (julian-date year month day hour minute 0))
      
      ;; Calculate Sun Azimuth
      (setq azimuth (sun-azimuth lat lon jd))
      
      ;; Create the time string and append to the list
      (setq time-str (strcat (itoa hour) ":" (if (< minute 10) (strcat "0" (itoa minute)) (itoa minute))))
      (setq time-list (append time-list (list (strcat time-str " " (rtos azimuth 2 6)))))
      
      ;; Increment minute
      (setq minute (+ minute 1))
    )
    ;; Increment hour
    (setq hour (+ hour 1))
  )

  ;; Print the list of time and azimuth values
  (foreach item time-list
    (prompt (strcat "\n" item))
  )

  (princ)
)

 

sun-azimuth.PNG

LS.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.

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...