Author Topic: C++ to lisp  (Read 9701 times)

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: C++ to lisp
« Reply #15 on: December 08, 2014, 04:45:38 AM »
pedroantonio124,
Which AutoCAD build are you using ?
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.

pedroantonio124

  • Guest
Re: C++ to lisp
« Reply #16 on: December 08, 2014, 04:54:23 AM »
AutoCad 2014

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: C++ to lisp
« Reply #17 on: December 08, 2014, 05:30:16 AM »
Hello irneb,

Thanks for your help  :-)

Unfortunately, I still receive the wrong result with the lisp code.
Maybe I can find the mistake if I know the result of every line.
Could you let me the C # run through over again code? Please
With a Console.WriteLine for every line.

Rather than a WriteLine per line ... just get hold of a DotNet IDE and debug step through it.

You can get a free IDE, either of these would do:
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: C++ to lisp
« Reply #18 on: December 08, 2014, 05:36:07 AM »
You want fries with this ?

Code - C#: [Select]
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace ToLatLon
  9. {
  10.     internal class Program
  11.     {
  12.         private static void Main(string[] args)
  13.         {
  14.             Console.Write("\n UTM to LatLon test.\n From theSwamp\n http://www.theswamp.org/index.php?topic=48330.0" );
  15.             Console.Write("\n\nEnter utmX value : " );
  16.             double utmX = double.Parse(Console.ReadLine());
  17.  
  18.             Console.Write("\nEnter utmY value : " );
  19.             double utmY = double.Parse(Console.ReadLine());
  20.  
  21.             Console.Write("\nEnterutmZone value : " );
  22.             string utmZone = Console.ReadLine();
  23.  
  24.             ToLatLon(utmX, utmY, utmZone);
  25.  
  26.             Console.ReadKey();
  27.         }
  28.  
  29.         public static void ToLatLon(double utmX, double utmY, string utmZone)
  30.         {
  31.             double latitude = 0;
  32.             double longitude = 0;
  33.  
  34.             bool isNorthHemisphere = utmZone.Last() >= 'N';
  35.  
  36.             var diflat = -0.00066286966871111111111111111111111111;
  37.             var diflon = -0.0003868060578;
  38.  
  39.             var zone = int.Parse(utmZone.Remove(utmZone.Length - 1));
  40.             var c_sa = 6378137.000000;
  41.             var c_sb = 6356752.314245;
  42.  
  43.             var e2 = Math.Pow((Math.Pow(c_sa, 2) - Math.Pow(c_sb, 2)), 0.5)/c_sb;
  44.             Console.WriteLine("\ne2:\t " + e2.ToString());
  45.  
  46.             var e2cuadrada = Math.Pow(e2, 2);
  47.             Console.WriteLine("\ne2cuadrada:\t " + e2cuadrada.ToString());
  48.  
  49.             var c = Math.Pow(c_sa, 2)/c_sb;
  50.             Console.WriteLine("\nc:\t " + c.ToString());
  51.  
  52.             var x = utmX - 500000;
  53.             Console.WriteLine("\nx:\t " + x.ToString());
  54.  
  55.             var y = isNorthHemisphere ? utmY : utmY - 10000000;
  56.             Console.WriteLine("\ny:\t " + y.ToString());
  57.  
  58.             var s = ((zone*6.0) - 183.0);
  59.             Console.WriteLine("\ns:\t " + s.ToString());
  60.  
  61.             var lat = y/(6366197.724*0.9996); // Change c_sa for 6366197.724
  62.             Console.WriteLine("\nlat:\t " + lat.ToString());
  63.  
  64.             var v = (c/
  65.                      Math.Pow(1 + (e2cuadrada*Math.Pow(Math.Cos(lat), 2)), 0.5))*
  66.                     0.9996;
  67.             Console.WriteLine("\nv:\t " + v.ToString());
  68.  
  69.             var a = x/v;
  70.             Console.WriteLine("\na:\t " + a.ToString());
  71.  
  72.             var a1 = Math.Sin(2*lat);
  73.             Console.WriteLine("\na1:\t " + a1.ToString());
  74.  
  75.             var a2 = a1*Math.Pow((Math.Cos(lat)), 2);
  76.             Console.WriteLine("\na2:\t " + a2.ToString());
  77.  
  78.             var j2 = lat + (a1/2.0);
  79.             Console.WriteLine("\nj2:\t " + j2.ToString());
  80.  
  81.             var j4 = ((3*j2) + a2)/4.0;
  82.             Console.WriteLine("\nj4:\t" + j4.ToString());
  83.  
  84.             var j6 = (5*j4 + a2*Math.Pow((Math.Cos(lat)), 2))/3.0;
  85.             // saque a2 de multiplicar por el coseno de lat y elevar al cuadrado
  86.             Console.WriteLine("\nj6:\t " + j6.ToString());
  87.  
  88.             var alfa = (3.0/4.0)*e2cuadrada;
  89.             Console.WriteLine("\nalfa:\t " + alfa.ToString());
  90.  
  91.             var beta = (5.0/3.0)*Math.Pow(alfa, 2);
  92.             Console.WriteLine("\nbeta:\t " + beta.ToString());
  93.  
  94.             var gama = (35.0/27.0)*Math.Pow(alfa, 3);
  95.             Console.WriteLine("\ngama:\t " + gama.ToString());
  96.  
  97.             var bm = 0.9996*c*(lat - alfa*j2 + beta*j4 - gama*j6);
  98.             Console.WriteLine("\nbm:\t " + bm.ToString());
  99.  
  100.             var b = (y - bm)/v;
  101.             Console.WriteLine("\nb:\t " + b.ToString());
  102.  
  103.             var epsi = ((e2cuadrada*Math.Pow(a, 2))/2.0)*
  104.                        Math.Pow((Math.Cos(lat)), 2);
  105.             Console.WriteLine("\nepsi:\t " + epsi.ToString());
  106.  
  107.             var eps = a*(1 - (epsi/3.0));
  108.             Console.WriteLine("\neps:\t " + eps.ToString());
  109.  
  110.             var nab = (b*(1 - epsi)) + lat;
  111.             Console.WriteLine("\nnab:\t " + nab.ToString());
  112.  
  113.             var senoheps = (Math.Exp(eps) - Math.Exp(-eps))/2.0;
  114.             Console.WriteLine("\nsenoheps:\t " + senoheps.ToString());
  115.  
  116.             var delt = Math.Atan(senoheps/(Math.Cos(nab)));
  117.             Console.WriteLine("\ndelt:\t " + delt.ToString());
  118.  
  119.             var tao = Math.Atan(Math.Cos(delt)*Math.Tan(nab));
  120.             Console.WriteLine("\ntao:\t " + tao.ToString());
  121.  
  122.             longitude = (delt/Math.PI)*180 + s;
  123.             latitude = (((lat +
  124.                           (1 + e2cuadrada*Math.Pow(Math.Cos(lat), 2) -
  125.                            (3.0/2.0)*e2cuadrada*Math.Sin(lat)*Math.Cos(lat)*
  126.                            (tao - lat))*(tao - lat)))/Math.PI)*180;
  127.             // era incorrecto el calculo
  128.  
  129.             Console.WriteLine("\nLatitud:\t " + latitude.ToString() +
  130.                 "\nLongitud:\t " + longitude.ToString());
  131.         }
  132.     }
  133. }
  134.  
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.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: C++ to lisp
« Reply #19 on: December 08, 2014, 06:05:44 AM »
Damn ... you're much to quick!

Anyhow, if you don't want to install anything new, you could use IDEone: http://ideone.com/5irS8R
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

pedroantonio124

  • Guest
Re: C++ to lisp
« Reply #20 on: December 08, 2014, 06:06:25 AM »
Thanks  :-D

This was the mistake in the Lisp code
It now works  :lol: :-P ^-^ :laugh: :blank:

Code: [Select]
Incorrect: (setq eps (* a (1-  (/ epsi 3.0)))))
OK: (setq eps (* a (- 1 (/ epsi 3.0)))))

pedroantonio124

  • Guest
Re: C++ to lisp
« Reply #21 on: December 08, 2014, 10:45:05 AM »
Thanks to irneb and Kerry  :-)

example:
(utm2latlong 451602.19 4519076.99 "33N")
->40.821287°  14.426080°

PedroAntonio  :evil: :-P


Code: [Select]
(defun utm2latlong (utmX utmY utmZone / latitude longitude isNorthHemisphere diflat diflon zone c_sa
c_sb e2 e2cuadrada c x y s lat v a a1 a2 j2 j4 j6 alfa beta gama bm b
epsi eps nab senoheps delta tao longitude latitude)

(defun tan (x / c)
(if (= (setq c (cos x)) 0.0)
(* (if (< x 0) -1 1) 1.7976931348623158e+308) ;Closest we can get to infinity using a double floating point
(/ (sin x) c)
)
)

(setq LATLONG nil)
(setq isNorthHemisphere (wcmatch utmZone "*[Nn]"))
(setq diflat -0.00066286966871111111111111111111111111)
(setq diflon -0.0003868060578)
(setq zone (atoi (substr utmZone 1 (1- (strlen utmZone)))))
(setq c_sa 6378137.0)
(setq c_sb 6356752.314245)
(setq e2 (/ (expt (- (expt c_sa 2.0) (expt c_sb 2.0)) 0.5) c_sb))    
(setq e2cuadrada (expt e2 2.0))
(setq c (/ (expt c_sa 2.0) c_sb))
(setq x (- utmX 500000))
(setq y (if isNorthHemisphere utmY (- utmY 10000000)))
(setq s (- (* zone 6.0) 183.0))
(setq lat (/ y (* 6366197.724 0.9996)))
(setq v (* (/ c (expt (+ 1 (* e2cuadrada (expt (cos lat) 2) )) 0.5) ) 0.9996))
(setq a (/ x v))
(setq a1 (sin (* 2.0 lat)))
(setq a2 (* a1 (expt (cos lat) 2.0)))
(setq j2 (+ lat (/ a1 2.0)))
(setq j4 (/ (+ (* 3.0 j2) a2) 4.0))
(setq j6 (/ (+ (* 5.0 j4) (* a2 (expt (cos lat) 2.0))) 3.0))
(setq alfa (* (/ 3.0 4.0) e2cuadrada))
(setq beta (* (/ 5.0 3.0) (expt alfa 2.0)))     
(setq gama (* (/ 35.0 27.0) (expt alfa 3.0)))
(setq bm (* 0.9996 c (- (+ (- lat (* alfa j2)) (* beta j4)) (* gama j6))))
(setq b (/ (- y bm) v))       
(setq epsi (* (/ (* e2cuadrada (expt a 2.0)) 2.0) (expt (cos lat) 2.0)))
(setq eps (* a (- 1 (/ epsi 3.0))))   
(setq nab (+ (* b (- 1 epsi)) lat))
(setq senoheps (/ (- (exp eps) (exp (- eps))) 2.0))
(setq delt (atan (/ senoheps (cos nab))))
(setq tao (atan (* (cos delt) (tan nab))))     
(setq longitude (+ (* (/ delt pi) 180.0) s))
(setq latitude (* (/ (+ lat (* (- (+ 1 (* e2cuadrada (expt (cos lat) 2.0))) (* (/ 3.0  2.0) e2cuadrada (sin lat) (cos lat) (- tao lat))) (- tao lat))) pi) 180.0))
   
(setq LATLONG (list latitude longitude ))
LATLONG
(princ)
)

mailmaverick

  • Bull Frog
  • Posts: 493
Re: C++ to lisp
« Reply #22 on: February 22, 2017, 02:44:37 AM »
Thanks to irneb and Kerry  :-)

example:
(utm2latlong 451602.19 4519076.99 "33N")
->40.821287°  14.426080°

PedroAntonio  :evil: :-P


Code: [Select]
(defun utm2latlong (utmX utmY utmZone / latitude longitude isNorthHemisphere diflat diflon zone c_sa
c_sb e2 e2cuadrada c x y s lat v a a1 a2 j2 j4 j6 alfa beta gama bm b
epsi eps nab senoheps delta tao longitude latitude)

(defun tan (x / c)
(if (= (setq c (cos x)) 0.0)
(* (if (< x 0) -1 1) 1.7976931348623158e+308) ;Closest we can get to infinity using a double floating point
(/ (sin x) c)
)
)

(setq LATLONG nil)
(setq isNorthHemisphere (wcmatch utmZone "*[Nn]"))
(setq diflat -0.00066286966871111111111111111111111111)
(setq diflon -0.0003868060578)
(setq zone (atoi (substr utmZone 1 (1- (strlen utmZone)))))
(setq c_sa 6378137.0)
(setq c_sb 6356752.314245)
(setq e2 (/ (expt (- (expt c_sa 2.0) (expt c_sb 2.0)) 0.5) c_sb))    
(setq e2cuadrada (expt e2 2.0))
(setq c (/ (expt c_sa 2.0) c_sb))
(setq x (- utmX 500000))
(setq y (if isNorthHemisphere utmY (- utmY 10000000)))
(setq s (- (* zone 6.0) 183.0))
(setq lat (/ y (* 6366197.724 0.9996)))
(setq v (* (/ c (expt (+ 1 (* e2cuadrada (expt (cos lat) 2) )) 0.5) ) 0.9996))
(setq a (/ x v))
(setq a1 (sin (* 2.0 lat)))
(setq a2 (* a1 (expt (cos lat) 2.0)))
(setq j2 (+ lat (/ a1 2.0)))
(setq j4 (/ (+ (* 3.0 j2) a2) 4.0))
(setq j6 (/ (+ (* 5.0 j4) (* a2 (expt (cos lat) 2.0))) 3.0))
(setq alfa (* (/ 3.0 4.0) e2cuadrada))
(setq beta (* (/ 5.0 3.0) (expt alfa 2.0)))     
(setq gama (* (/ 35.0 27.0) (expt alfa 3.0)))
(setq bm (* 0.9996 c (- (+ (- lat (* alfa j2)) (* beta j4)) (* gama j6))))
(setq b (/ (- y bm) v))       
(setq epsi (* (/ (* e2cuadrada (expt a 2.0)) 2.0) (expt (cos lat) 2.0)))
(setq eps (* a (- 1 (/ epsi 3.0))))   
(setq nab (+ (* b (- 1 epsi)) lat))
(setq senoheps (/ (- (exp eps) (exp (- eps))) 2.0))
(setq delt (atan (/ senoheps (cos nab))))
(setq tao (atan (* (cos delt) (tan nab))))     
(setq longitude (+ (* (/ delt pi) 180.0) s))
(setq latitude (* (/ (+ lat (* (- (+ 1 (* e2cuadrada (expt (cos lat) 2.0))) (* (/ 3.0  2.0) e2cuadrada (sin lat) (cos lat) (- tao lat))) (- tao lat))) pi) 180.0))
   
(setq LATLONG (list latitude longitude ))
LATLONG
(princ)
)

Dear Pedro,

Excellent LISP. Works great. Do you have reverse LISP i.e. to convert Lat , Long to UTM Coordinates ?


d2010

  • Bull Frog
  • Posts: 326
Re: C++ to lisp
« Reply #23 on: February 24, 2017, 06:59:03 AM »
You convert  huge math equations to autolisp -R14
You can convert 9999-maths-equations to autolispR14..full automatically.
Please you see details at.
Step1) You downloading the compilator
Step2) You insert  your math  equatiosn into file. ,Vlax as .Zip
Step3) You compile then vlax.
Allea gutes..

http://lisp2arx.3xforum.ro/post/19/1/VirtualC_Lisp/

http://www.puiubrat.3x.ro/adve2011/netilisq.html

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: C++ to lisp
« Reply #24 on: February 24, 2017, 07:13:24 AM »
You want fries with this ?
Damn. Nice visual too. :)

You guys amaze me.
TheSwamp.org  (serving the CAD community since 2003)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: C++ to lisp
« Reply #25 on: February 24, 2017, 08:33:46 AM »
An 809 day delay is also amazing. :-P

But yeah, mad props to KB.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: C++ to lisp
« Reply #26 on: February 24, 2017, 08:44:53 AM »
An 809 day delay is also amazing. :-P
LOL

better late than never!
TheSwamp.org  (serving the CAD community since 2003)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: C++ to lisp
« Reply #27 on: February 24, 2017, 09:00:01 AM »
I don't claim to be the record holder but a 1899 delay is a worthy contender.

Bwaaaaaa, lmao ... 5 years later proves useful.  :lmao:

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

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: C++ to lisp
« Reply #28 on: February 24, 2017, 10:26:55 AM »
I don't claim to be the record holder but a 1899 delay is a worthy contender.
 :-D
To funny. :)
TheSwamp.org  (serving the CAD community since 2003)