tag:blogger.com,1999:blog-33820866841364656542017-08-16T03:10:07.354+02:00Aha's HP Calculator BlogWhatever I do get into related to the vintage and contemporary HP handheld computersArne Halvorsenhttps://plus.google.com/102376059110739689820noreply@blogger.comBlogger42125tag:blogger.com,1999:blog-3382086684136465654.post-67855720389484206522008-10-24T15:09:00.005+02:002008-10-24T15:32:15.761+02:00HP Vintage Calculator Collection on National TV And A National Tragedy!<span style="font-size:100%;">Norwegian Broadcasting Corporation (NRK) had in it's series about all kinds of collections and collectors <a href="http://www.isene.com/artweb.cgi?geir">Geir Isene</a></span> show his great collection of HP calculators (he had TIs also, but the HP ones steals the show :-). The episode can be viewed by following <a href="http://www1.nrk.no/nett-tv/klipp/423734">this</a> link, the calculators appear around 17:18 into the program I found.<br /><br />Now to the tragedy: That collection is no longer, it was lost in a fire! That is realy to bad...Arne Halvorsenhttps://plus.google.com/102376059110739689820noreply@blogger.com4tag:blogger.com,1999:blog-3382086684136465654.post-43424382105240406772008-10-17T11:57:00.002+02:002008-10-17T12:01:17.750+02:00HP Stuff at Work<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_PBTeHmUPYU8/SPhiDeVwNhI/AAAAAAAAATw/UAAcD8FoRKc/s1600-h/hp-stuff.JPG"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://4.bp.blogspot.com/_PBTeHmUPYU8/SPhiDeVwNhI/AAAAAAAAATw/UAAcD8FoRKc/s320/hp-stuff.JPG" alt="" id="BLOGGER_PHOTO_ID_5258060376778487314" border="0" /></a><br />Just uploaded so could participate in a 'show your stuff' thread at the museum...Arne Halvorsenhttps://plus.google.com/102376059110739689820noreply@blogger.com0tag:blogger.com,1999:blog-3382086684136465654.post-83413358042695120962008-01-14T19:40:00.001+01:002008-01-21T21:02:17.539+01:00Happy new year!Happy new year to any that may pass here! Yea, I know I bit late, but, hey, happy new year!<br /><br />Good time to start of the new year with what I <span style="font-style: italic;">hope</span> to blog about here in the year to come...<br /><br />1. Document Euclid for 35s. Particular I would like to make somekind of cheat sheet that shows what labels are assigned to which programs, what variables are used to what and user input/output. I realy missed this a while ago when wanted to use program at day time job. Good thing I had this blog then!<br /><br />2. Learn to use and program the 50g. I started out fine, but then holidays happened and real job has been keeping me busy so fare in 08. First programming project will propably be a UserRPL Euclid. Later I hope to look into C programming on it. I make my living hacking Java these days, but I started out as a C programmer, this could be way to get to do some good old C hacking again :-).<br /><br />3. I realy would enjoy to program the <a href="http://aha-hp-calcs.blogspot.com/2007/11/fine-machine-reports-for-duty-again.html">41CV</a> to, say ... ahem ... make an Euclid version for that to. What I would like with the 41CV compared to the 35s is the ability to name programs and assigne program to keys while in user mode. For these types of problem I for sure is going to miss 35s' vector type...<br /><br />Well, see if get time to do any of this sometimes (may be a bit quiet here for a while...).Arne Halvorsenhttps://plus.google.com/102376059110739689820noreply@blogger.com0tag:blogger.com,1999:blog-3382086684136465654.post-60088489765444320912007-11-12T15:31:00.000+01:002007-11-14T21:57:05.826+01:00Fixing the HP-41CV - IV : More HP calculator stuff from the past recoveredAfter got back the HP-41CV in as good as new condition I got motivated to dig into the old stuff stored away at my parents place to see what else could be found from the good old days. After this time's digging my HP inventory (not counting the 35s) is:<br /><br /><span style="font-weight: bold;">Machines</span><br /><br />One working HP-41CV (thanks to FixThatCalc).<br /><br />One not working HP-29C (details at the end of this blog entry) with manuals (in Swedish).<br /><br /><span style="font-weight: bold;">HP-41 manuals</span><br /><br /><span style="font-style: italic;">Instruktionsbok Och Programmeringshandledning</span> - The instruction and programming manual in Swedish! Apperently they did not bother to do a translation to Norwegian!<br /><br /><span style="font-style: italic;">Hur man använder kalkulatorer från HP</span> - Small booklet explaining the RPN paradigm, also in sweedish.<br /><br /><span style="font-style: italic;">HP-41C Standard Applications</span><br /><br /><span style="font-weight: bold;">HP-41</span> <span style="font-weight: bold;">accessories</span><br /><br />Modules:<br /><ul><li><span style="font-style: italic;">Math I</span>, with manual, quick reference card and keyboard overlays.</li><li><span style="font-style: italic;">X Functions</span>, manual missing.</li><li><span style="font-style: italic;">Games</span>, with manual and keyboard overlays.</li></ul>A card reader (with (in swedish ofcourse!) manual) that propably is not working that great anymore (details at the end of this blog entry).<br /><br /><b>Miscellaneous<br /><br /></b>A module holder with my two missing port 'protectors' :-)<br /><br />Keyboard layovers for the modules AND two blank ones and one unidentified one!<br /><span style="font-weight: bold;"><br />Comments<br /><br /><span style="font-weight: bold;"></span></span>I know I got magnetic cards laying around somewhere so I would be interesting <span style="font-style: italic;">in using</span> the card reader. Actual found some cards that I remembered put aside because damaged. However, still the way reader behaved on them may suggest it is suffering from old age (that and the fact they usual do). The good news (yep been chating with FixThatCalc) is that it can fixed, may very well soon be another package on it's way...<br /><br />The 29C sadly is not for any practical reasons repairable I have been assured. It look brand new (did not have a long and active life), it may have a future as spare parts!<br /><br />It bugs me that manual for the X functions is missing. I never got much time to play around with those and there is some I would like to utilize in my nowadays programming. Well, it may still turn up and anyway eventual I am going to get the <a href="http://www.hpmuseum.org/cd/cddesc.htm">museum's dvd set</a> which includes the manual.Arne Halvorsenhttps://plus.google.com/102376059110739689820noreply@blogger.com0tag:blogger.com,1999:blog-3382086684136465654.post-72328139977662509332007-11-10T13:48:00.000+01:002007-11-10T14:36:48.278+01:00Fixing the HP-41CV - III : An old machine reports for duty again!Got it (HP-41CV <a href="http://www.hpmuseum.org/collect.htm#numbers">serial nr.</a> 2103A07854) back from <a href="http://www.fixthatcalc.com/index.htm">FixThatCalc</a>!<br /><br />Belive they did a great job, seems to be working just fine AND they do a fantastic job cleaning the machines: Can not remember it have looked this good. Sure it must have when I got it, but that is 26 years ago!<br /><br />There is a note returned with the machine telling me I should not put it back in it's pouch since it has started to deteriorate and it may harm the calculator. It has the undertone of a caring mother telling children to take good care of their fine toys... I belive we who cares for these devices are very lucky that FixThatCalc exists!Arne Halvorsenhttps://plus.google.com/102376059110739689820noreply@blogger.com0tag:blogger.com,1999:blog-3382086684136465654.post-38139802859617805822007-11-08T19:34:00.000+01:002007-11-09T12:08:26.605+01:00Got my hands on a HP-48GXA co-worker discovered my interest for HP calculators and remembered he had some kind of <span style="font-style: italic;">graphing</span> calculator while at engineering shool. Belived it was some kind of a <a href="http://en.wikipedia.org/wiki/Texas_Instruments">TI</a> model. Turned out he had a <a href="http://en.wikipedia.org/wiki/HP-48_series">HP-48</a>GX collecting dust home!<br /><br />To cut a short story shorter, he has kindly borrowed me the machine. Later this year I will get my self a HP-50g and this will allow me to learn the <a href="http://www.hpmuseum.org/rpl.htm">RPL language</a> up front!<br /><br />I <span style="font-style: italic;">may</span> do a RPL port of the HP-35s <a href="http://aha-hp-calcs.blogspot.com/2007/09/euclid-pack-geometric-calculator.html">Euclid Pack</a> implementation...<br /><br />Resources related to getting to know the RPL series of machines:<br /><br /><span style="font-style: italic;">Manuals downloadable from </span><a style="font-style: italic;" href="http://www.educalc.net/">Educalc.net</a><span style="font-style: italic;"> </span><a style="font-style: italic;" href="http://www.educalc.net/149032.page">here</a><span style="font-style: italic;">.<br /></span><span style="font-size:100%;"><span style="font-style: italic;">HP 48G Series Advanced User's Reference Manual available <a href="http://www.hpcalc.org/details.php?id=6036">here</a> at <a href="http://www.hpcalc.org/">hpcalc.org</a>.<br />Short but good <a href="http://www.hpmuseum.org/rpl.htm">introduction to RPL</a> at the <a href="http://www.hpmuseum.org/">museum</a>.<br /></span><strong style="font-style: italic; font-weight: normal;"><a href="http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/articles.cgi?read=731">UserRPL stack commands</a>, article at the museum.<br />The <a href="http://groups.google.com/group/comp.sys.hp48/topics">usenet group</a> ofcourse.<br /><a href="http://www.faqs.org/faqs/hp/">FAQ</a>s found at the <a href="http://www.faqs.org/faqs/">Internet FAQ Archieves</a>.<br /></strong></span>Arne Halvorsenhttps://plus.google.com/102376059110739689820noreply@blogger.com0tag:blogger.com,1999:blog-3382086684136465654.post-65573873546600852172007-11-06T19:56:00.000+01:002007-11-06T21:39:01.215+01:00A HP-35s hacker<a href="http://www.stefanv.com/calculators/index.html">Stefan</a> is a HP calculator enthusiast that got himself a HP-35s and have a done a man's work providing two (so fare) rather lengthy programs for <a href="http://www.stefanv.com/calculators/hp35s_curve_fitting.html"><span style="font-style: italic;">Curve Fitting</span></a> and <a href="http://www.stefanv.com/calculators/hp35s_matrix_multitool.html"><span style="font-style: italic;">Matrix Operations</span></a> on the HP-35s.<br /><br />Mind you, as <a href="http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/forum.cgi?read=127861">this</a> thread (about Stefan's matrix program) at the MoHPC forum shows: If you need to do serious matrix work, clearly you should consider a <a href="http://en.wikipedia.org/wiki/RPL_%28programming_language%29">RPL machine</a>.<br /><br />By the way, <span style="font-style: italic;">do</span> check out Stefan web content, he is an inspiration to any kind of web author and also he turns out to be a <a href="http://www.dokpro.uio.no/perl/ordboksoek/ordbok.cgi?OPP=norgesvenn"><span style="font-style: italic;">norgesvenn</span></a>!Arne Halvorsenhttps://plus.google.com/102376059110739689820noreply@blogger.com1tag:blogger.com,1999:blog-3382086684136465654.post-85625474361075481432007-10-22T16:49:00.000+02:002007-10-29T19:43:49.585+01:00A programmer's HP-35s reviewSome thoughts on the HP-35s <span style="font-style: italic;">after</span> been <span style="font-style: italic;">programming</span> it for a while: Doing the HP-35s <a href="http://aha-hp-calcs.blogspot.com/2007/09/euclid-pack-geometric-calculator.html">Euclid Pack implementation</a>.<br /><br />Two features I learned to love when programming the 35s: Vector type and equations.<br /><br /><span style="font-style: italic;">Vector type</span><br /><br />The vector type has been critizised for missing key features:<br /><ol><li>No cross product. Must make a <a href="http://aha-hp-calcs.blogspot.com/2007/09/cross-product-and-normalizing-vector-on.html">program</a>.<br /></li><li>No native way to unpack or address vector components. Must use 'dot product mask vectors'.</li><li>No operation to tell a vector's dimension (dim or size).</li></ol>Despite these drawbacks (of which the two first can be worked around), I find the vector type a <span style="font-style: italic;">very</span> valuable feature because of it's data packing capabilities.<br /><br />Some focus has been on using 3D vectors to augment the machine's 800 indirect registers. For the things I do and the fact that it is a closed system (no I/O), I can't imagine applications using a large fraction of the 800 registers even <span style="font-style: italic;">without</span> packing 3 real numbers in one register!<br /><br />But, I find the data packing offered by 3D vectors to be very valuable in the 'more valuable real estate territories' of <span style="font-style: italic;">near end user</span> variable registers (A-Z) and working registers (stack and lastx).<br /><br />For example, for the design of the <span style="font-style: italic;">euclid</span> <span style="font-style: italic;">pack</span> project I ended up with wanting to store definition of two lines (four 2D or 3D points), two planes (two 3D points and two normal vectors) and one triangle (three 3D points) in <span style="font-style: italic;">variables</span>.<br /><br />If all data entered is in 3D, that would require minimum use 33 registers! And this is data I would like to be close to the end user, so I would like to use variables: Unless had vector type would not have room. Since have the vector type minimum register use is 11.<br /><br />And implementation actual ended up storing additional data in variables to make certain computations easy and results handy. And I still did not use up all variable registers...<br /><br />Also now we can have 12 real numbers on the stack! That becomes usefull when <span style="font-style: italic;">using</span> programs that take more than 4 numbers as input. For example to define a 3D triangle (the <a href="http://aha-hp-calcs.blogspot.com/2007/10/hp-35s-euclid-implementation-xiii.html">T program</a>) end user must give in nine numbers (three 3D numbers), without the ability to just put the points on the stack and run the program, the program would had to prompt for the data.<br /><br />Also the vector type, RPN paradigm and the use of equation is very powerfull when programming:<br /><br /><span style="font-style: italic;">Equations in programs</span><br /><br />I find programming complex calculations in need of much intermediate results to be easy on the 35s by combining the RPN paradigm, vector type and equations:<br /><ul><li>The vector type allows 12 values to be stored on the stack.</li><li>Equations in programs can use all these number while being evaluated, only when done is maximum three numbers lost on the stack: A 3D vector in the T stack register.</li><li>The result of evaluating an equation may very well be a 3D vector: A single line in a program may execute three equation which result raises the stack only once.</li></ul>I think second half of the last <a href="http://aha-hp-calcs.blogspot.com/2007/10/hp-35s-euclid-implementation-xv.html">program</a> (lines 28 to 35) I made in this series realy utilize this programming style, there is eight lines of equations in sequence!<br /><br />A very nice feature of the HP 35s that helps programming this way is that when in programming mode and to insert a stack register as a variable in an equation using the RDN key one sees the content of the registers <span style="font-style: italic;">user side</span>. If one has a worked example of the problem being programmed and is programming equation by equation and running the program before programming a new equation then when programming the equation it is easy to see where on the stack needed numbers are.<br /><br />One drawback of this style of programming is that the evaluation of equation makes for much slower execution then a pure RPN version. For programs that intention is to be called a large (or small...) number of times as subroutines by other programs this style of programming may not be appropiate.<br /><br />On an improved HP 35s (HP 35s+ :-) perhaps one could have some kind of equation compilation?<br /><br />No need for me to get into any of the now well known short commings or bugs of the device documented by the community of the <a href="http://www.hpmuseum.org/">MoHPC</a> <a href="http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/articles.cgi?read=735">here</a>, except to say that the reported vector syntax bug is indeed real <span style="font-style: italic;">on<span style="font-style: italic;"> some machines</span></span> and makes this type of programming much harder than needed. I know, I got one... Still I have been able to do whatever I did without ever needing to reset the thing.Arne Halvorsenhttps://plus.google.com/102376059110739689820noreply@blogger.com0tag:blogger.com,1999:blog-3382086684136465654.post-90042865874439234052007-10-21T21:22:00.000+02:002007-10-30T18:50:33.950+01:00HP-35s Euclid Implementation - XV : The inscribed and circumscribed circle of a triangleThe final program to fullfill the <a href="http://aha-hp-calcs.blogspot.com/2007/09/euclid-pack-geometric-calculator.html">requirements</a>! Problem 16 and 17: Finding the inscribed (incircle) and circumscribed (circumcircle) circles of a triangle.<br /><br />Finding the inscribed circle is the same as solving the problem of finding the circle tangent to three lines (lines defined by the triangle edges) and finding the circumscribed circle is the same as solving the problem of finding the circle that passes through three points (triangle's vertexes).<br /><br />The triangle in question has been entered using the <a href="http://aha-hp-calcs.blogspot.com/2007/10/hp-35s-euclid-implementation-xiii.html">T program</a>.<br /><pre><br /> v3<br /> / \<br /> / \<br /> / \ <br /> v1------v2<br /></pre>Refering to the above triangle I give the formulas used in the HP-35s program presented here:<br /><br /><span style="font-style: italic;">Inscribed circle:</span><br /><br />The barycentric coordinates for the incenter are:<br /><pre>(l1/p, l2/p, l3/p)<br /></pre>Where p is the perimeter of the triangle (sum of all edges lengths) and l1 is the length of the edge v3-v2, l2 is the length of the edge v1-v3 and l3 is the length of the edge v2-v1.<br /><br />The radius of the inscribed circle is:<br /><pre>(2A)/p<br /></pre>Where A is the area of the triangle.<br /><br /><span style="font-style: italic;">Circumscribed circle:</span><br /><br />With the intermediate results<br /><pre>d1=-e2*e3<br />d2=-e3*e1<br />d3=-e1*e2<br /><br />(e1=v3-v2, e2=v1-v3, e3=v2-v1, * is the dot product)<br /><br />c1=d2d3<br />c2=d3d1<br />c3=d1d2<br /><br />c=c1+c2+c3<br /></pre>the barycentric coordinates for the circumcenter are:<br /><pre>((c2+c3)/2c, (c3+c1)/2c, (c1+c2)/2c)<br /></pre>The radius of the circumscribed circle is:<br /><pre>sqrt((d1+d2)(d2+d3)(d3+d1)/c)/2<br /></pre>These formulas are taken from the excelent book <span style="font-style: italic;">3D Math Primer for Graphics and Game Development</span> that also provide background for much of the geometric problems in the <a href="http://aha-hp-calcs.blogspot.com/2007/09/euclid-pack-geometric-calculator.html">Euclid Pack specification</a>.<br /><br /><span style="font-weight: bold;">Stack Input/Output:</span><br /><pre>No input on stack-> XEQ O ->[[bc1, bc2, bc3], cr, [bi1, bi2, bi3], ir | L]<br /></pre>Where (bc1, bc2, bc3) are the barycentric coordinates for the circumscribed circle's center (circumcenter) , cr is its radius, (bi1, bi2, bi3) are the barycentric coordinates for the inscribed circle's center (incenter) and ir is its radius.<br /><br /><span style="font-weight: bold;">Variables:</span><br /><br />Reads:<br /><pre>K : First vertex (3D vector). Populated by the <a href="http://aha-hp-calcs.blogspot.com/2007/10/hp-35s-euclid-implementation-xiii.html">T program</a>.<br />L : Second vertex (3D vector). Populated by the <a href="http://aha-hp-calcs.blogspot.com/2007/10/hp-35s-euclid-implementation-xiii.html">T program</a>.<br />M : Third vertex (3D vector). Populated by the <a href="http://aha-hp-calcs.blogspot.com/2007/10/hp-35s-euclid-implementation-xiii.html">T program</a>.</pre>Writes:<br /><pre>Z : Scratch data.<br /></pre><span style="font-weight: bold;">Program:</span><br /><pre>O001 LBL O<br />O002 5<br />O003 STO I<br />O004 STO(I)<br />O005 4<br />O006 STO I<br />O007 LASTX<br />O008 STO(I)<br />O009 eq M-L<br />0O10 eq M-K<br />O011 eq [ABS(REGY),ABS(REGX),ABS(L-K)]<br />O012 STO Z<br />O013 eq REGX/([1,0,0]xREGX+[0,1,0]xREGX+[0,0,1]xREGX)<br />O014 R^<br />O015 R^<br />O016 XEQ X001<br />O017 R^<br />O018 X<>Y<br />O019 ABS<br />O020 eq REGX/([1,0,0]xZ+[0,1,0]xZ+[0,0,1]xZ)<br />O021 X<>Y<br />O022 RDN<br />O023 X<>Y<br />O024 RCL(I)<br />O025 ABS<br />O026 RDN<br />O027 XEQ U001<br />O028 eq M-L<br />O029 eq K-M<br />O030 eq L-K<br />O031 eq [-REGYxREGX,-REGXxREGZ,-REGZxREGY]<br />O032 eq [([0,1,0]xREGX)x([0,1,0]xREGX),<br /> ([0,0,1]xREGX)x([1,0,0]xREGX),<br /> ([1,0,0]xREGX)x([0,1,0]xREGX)]<br />O033 eq [1,0,0]xREGX+[0,1,0]xREGX+[0,0,1]xREGX<br />O034 eq 0.5xSQRT((([1,0,0]xREGZ+[0,1,0]xREGZ)x<br /> ([0,1,0]xREGZ+[0,0,1]xREGZ)x<br /> ([0,0,1]xREGZ+[1,0,0]xREGZ))/REGX)<br />O035 eq [([0,1,0]xREGZ)+([0,0,1]xREGZ),<br /> ([0,0,1]xREGZ)+([1,0,0]xREGZ),<br /> ([1,0,0]xREGZ)+([0,1,0]xREGZ)]/(2xREGY)<br />O036 XEQ U079<br />O037 RTN<br /></pre><span style="font-weight: bold;">Comments:</span><br /><br /><a href="http://aha-hp-calcs.blogspot.com/search/label/Disclaimer">Terms of use.</a><br /><br />Mnemonics: O since letter is a circle (or more or less depeding on font, rather circular on the 35s).<br /><br />Reason for not converting to cartesian coordinates is that since the barycentric coordinates are relative to the vertices it is much easier to 'see' where the center points are relative to the triangle. If one where to be presented the cartesian coordinates one must remember the nine vertex coordinates to know where (relative to triangle) the center points are. Particular one see at once if the circumscribed circle's center is inside or outside the triangle.<br /><br />Cartesian coordinates are easily obtained using the <a href="http://aha-hp-calcs.blogspot.com/2007/10/hp-35s-euclid-implementation-xiv.html">A program</a> by the following key sequence:<br /><pre>XEQ A<br />RDN<br />RDN<br />XEQ A<br />RDN<br />RDN<br /></pre>The last two RDN are only provided to get content of stack in same order as before except that barycentric positional vectors are now replaced with cartesian ones.Arne Halvorsenhttps://plus.google.com/102376059110739689820noreply@blogger.com0tag:blogger.com,1999:blog-3382086684136465654.post-39280477642065518882007-10-18T20:53:00.000+02:002007-10-18T23:03:41.762+02:00HP-35s Euclid Implementation - XIV : Barycentric to Cartesian coordinatesGoing from barycentric to cartesian coordinates (problem 15 in the <a href="http://aha-hp-calcs.blogspot.com/2007/09/euclid-pack-geometric-calculator.html">requirements</a>) is the easy part of Cartesian<->Barycentric 2D/3D conversion, this will be a much shorter blog entry than <a href="http://aha-hp-calcs.blogspot.com/2007/10/hp-35s-euclid-implementation-xiii.html">this</a> one!<br /><br /><span style="font-weight: bold;">Stack Input/Output:</span><br /><pre>3D case: [[b1, b2, b3], Y, Z, T | L]-> XEQ A ->[[x, y, z], Y, Z, T | [b1, b2, b3]]<br /><br />2D case: [[b1, b2, b3], Y, Z, T | L]-> XEQ A ->[[x, y], Y, Z, T | [b1, b2, b3]]<br /></pre><span style="font-weight: bold;">Variables:</span><br /><br />Reads:<br /><pre>K : First vertex (3D vector), in 3D case. Populated by the <a href="http://aha-hp-calcs.blogspot.com/2007/10/hp-35s-euclid-implementation-xiii.html">T program</a>.<br />L : Second vertex (3D vector), in 3D case. Populated by the <a href="http://aha-hp-calcs.blogspot.com/2007/10/hp-35s-euclid-implementation-xiii.html">T program</a>.<br />M : Third vertex (3D vector), in 3D case. Populated by the <a href="http://aha-hp-calcs.blogspot.com/2007/10/hp-35s-euclid-implementation-xiii.html">T program</a>.<br />U : First vertex of triangle projected to 2D (2D vector), in 2D case. Populated by the <a href="http://aha-hp-calcs.blogspot.com/2007/10/hp-35s-euclid-implementation-xiii.html">T program</a>.<br />V : Second vertex of triangle projected to 2D (2D vector), in 2D case. Populated by the <a href="http://aha-hp-calcs.blogspot.com/2007/10/hp-35s-euclid-implementation-xiii.html">T program</a>.<br />W : Third vertex of triangle projected to 2D (2D vector), in 2D case. Populated by the <a href="http://aha-hp-calcs.blogspot.com/2007/10/hp-35s-euclid-implementation-xiii.html">T program</a>.</pre><span style="font-weight: bold;">Program:</span><br /><pre>A001 LBL A<br />A002 ABS<br />A003 RDN<br />A004 FS? 2<br />A005 GTO A008<br />A006 eq Kx([1,0,0]xLASTX)+Lx([0,1,0]xLASTX)+Mx([0,0,1]xLASTX)<br />A007 RTN<br />A008 eq Ux([1,0,0]xLASTX)+Vx([0,1,0]xLASTX)+Wx([0,0,1]xLASTX)<br />A009 RTN<br /></pre><span style="font-weight: bold;">Comments:</span><br /><br /><a href="http://aha-hp-calcs.blogspot.com/search/label/Disclaimer">Terms of use.</a><br /><br />Mnemonics: None realy, but letter is left to B, the program label for Barycentric to Cartesian conversion.<br /><br />If we are working in 2D (flag 2 set) we are applying the weights (barycentric coordinates) to the 2D coordinate's of the projected triangle (line A008) else applying the weights to the vertexes 3D coordinates (line A006).Arne Halvorsenhttps://plus.google.com/102376059110739689820noreply@blogger.com0tag:blogger.com,1999:blog-3382086684136465654.post-32736679609794799002007-10-17T15:09:00.000+02:002007-11-10T14:34:34.065+01:00Fixing the HP-41CV - II : Sending itFinaly got around to post the HP-41CV to <a href="http://www.fixthatcalc.com/index.htm">Fix That Calc</a>!Arne Halvorsenhttps://plus.google.com/102376059110739689820noreply@blogger.com0tag:blogger.com,1999:blog-3382086684136465654.post-51095116789376889162007-10-15T14:53:00.001+02:002007-10-21T22:32:52.850+02:00HP-35s Euclid Implementation - XIII : Cartesian to Barycentric coordinatesArrived at problem 14 of the <a href="http://aha-hp-calcs.blogspot.com/2007/09/euclid-pack-geometric-calculator.html">requirements</a>: Computing barycentric coordinates given cartesian coordinates.<br /><br /><a href="http://en.wikipedia.org/wiki/Barycentric_coordinates_%28mathematics%29">Barycentric coordinates</a> [b1, b2, b3] of a point in a plane are coordinates defined by a triangle in the plane (defines the plane) where the triangle's first vertex's barycentric coordinates are [1,0,0], second vertex's are [0,1,0], third vertex's are [0,0,1] and one have that b1+b2+b3=1.<br /><br />Coordinates of any point in the plane can be expressed as the weighted average of the triangle's vertices coordinates, these weights are the barycentric coordinates:<br /><pre> Barycentric Cartesian<br />(b1, b2, b3)<=>b1<span style="font-weight: bold;">v1</span>+b2<span style="font-weight: bold;">v2</span>+b3<span style="font-weight: bold;">v3</span><br /></pre>Where <span style="font-weight: bold;">v</span><span style="font-style: italic; font-weight: bold;">i</span> is the positional vector for vertex <span style="font-style: italic;">i</span>.<br /><br />Barycentric coordinates has several uses and are of theoretical importance outside the scope of this blog entry. Here I give two practical uses:<br /><ol><li>Provides a robust test for if a point in triangle's plane with barycentric coordinates [b1, b2, b3] is inside the triangle, on one of the triangle's edge or outside the triangle: If all components are in the range[0,1] point is inside, if b<span style="font-style: italic;">i</span> is 0 and the two others are in the [0,1] range then the point is on the edge oposite of triangle's vertice <span style="font-style: italic;">i, </span>and finaly if at least one component is not in the [0,1] range then point is outside triangle.</li><li>If a function's values is known at the triangle's vertices one can perform linear interpolation inside the triangle at the point: v1*b1+v2*b2+v3*b3. Where v<span style="font-style: italic;">i</span> is the value at vertex <span style="font-style: italic;">i</span> and [b1, b2, b3] is the barycentric coordinates for point to evaluate at. Note that converting from barycentric coordinates to cartesian coordinates is a special case of this.<br /></li></ol>I choose to convert from cartesian coordinates to barycentric by programming the solution to the equations for the 2D cartesian to barycentric coordinates case:<br /><pre>Q=(y1-y3)*(x2-x3)+(y2-y3)*(x2-x1)<br /><br />b1=((y-y3)*(x2-x3)+(y2-y3)*(x3-x))/Q<br />b2=((y-y1)*(x3-x1)+(y3-y1)*(x1-x))/Q<br />b3=((y-y2)*(x1-x2)+(y1-y2)*(x2-x))/Q<br /></pre>Where (x<span style="font-style: italic;">i</span>, y<span style="font-style: italic;">i</span>) are cartesian coordinates for triangle's <span style="font-style: italic;">i</span>'th vertex and (x, y) is the cartesian coordinates of the point in question. This is the solution to the equation set of three uknown (b1, b2, b3):<br /><pre>x=b1*x1+b2*x2+b3*x3<br />y=b1*y1+b2*y2+b3*y3<br />1=b1+b2+b3<br /></pre>To solve 3D cartesian to barycentric I project the triangle and point in question to 2D and solve as a 2D problem.<br /><br />Implementation is done in two steps:<br /><ol><li>Modify the T program so it: <span style="font-weight: bold;">A)</span> Also accept a 2D triangle (flag 2 set='2D mode'. <span style="font-weight: bold;">B)</span> Project the triangle to the cardinal plane that gives the largest area, this is the triangle used for computing barycentric coordinates. <span style="font-weight: bold;">C)</span> Computes the quotient Q in the above equations.</li><li>Implement a program labeled B to accepts a 2D or 3D cartesian tuple and use result from <span style="font-weight: bold;">B</span> and <span style="font-weight: bold;">C</span><span style="font-weight: bold;"></span> above to compute barycentric coordinates.</li></ol><span style="font-weight: bold;">Step 1 : </span><span style="font-weight: bold;">The modified T program<br /><br /></span><span style="font-weight: bold;">Stack Input/Output:</span><br /><pre>2D case: [[x2, y2], [x1, y1], [x0, y0] | L]->XEQ T->[[nx, ny, nz], [x2, y2], [x1, y1], [x0, y0] | L]<br /><br />3D case: [[x2, y2, z2], [x1, y1, z1], [x0, y0, z0] | L]->XEQ T->[[nx, ny, nz], [x2, y2, z2], [x1, y1, z1], [x0, y0, z0] | L]<br /></pre>Where v0=(x0, y0, z0) is first, v1=(x1, y1, z1) is second, v2=(x2, y2, z2) is the third triangle vertex and [nx, ny, nz] is the cross product (v1-v0)x(v2-v0).<br /><br /><span style="font-weight: bold;">Variables:</span><br /><br />Writes:<br /><pre>K : First vertex (3D vector).<br />L : Second vertex (3D vector).<br />M : Third vertex (3D vector).<br />Q : Quotient (y1-y3)*(x2-x3)+(y2-y3)*(x2-x1).<br />U : First vertex of triangle projected to 2D (2D vector).<br />V : Second vertex of triangle projected to 2D (2D vector).<br />W : Third vertex of triangle projected to 2D (2D vector).<br />X : Index of coordinate discarded in 3D->2D projection.<br /></pre><span style="font-weight: bold;">Program:</span><br /><pre>T001 LBL T<br />T002 XEQ U001<br />T003 FS? 2<br />T004 XEQ X068<br />T005 STO M<br />T006 RDN<br />T007 FS? 2<br />T008 XEQ X068<br />T009 STO L<br />T010 RDN<br />T011 FS? 2<br />T012 XEQ X068<br />T013 STO K<br />T014 R^<br />T015 X<>Y<br />T016 -<br />T017 RDN<br />T018 RDN<br />T019 LASTX<br />T020 -<br />T021 X<>Y<br />T022 RDN<br />T023 XEQ X001<br />T024 ABS<br />T025 1E-6<br />T026 X>Y?<br />T027 GTO T065<br />T028 LASTX<br />T029 XEQ X025<br />T030 STO X<br />T031 RCL K<br />T032 X<>Y<br />T033 XEQ X052<br />T034 STO U<br />T035 RDN<br />T036 RCL L<br />T037 X<>Y<br />T038 XEQ X052<br />T039 STO V<br />T040 RDN<br />T041 RCL M<br />T042 X<>Y<br />T043 XEQ X052<br />T044 STO W<br />T045 eq ([0,1]xU-[0,1]xW)x([1,0]xV-[1,0]xW)+<br /> ([0,1]xV-[0,1]xW)x([1,0]xW-[1,0]xU)<br />T046 STO Q<br />T047 LASTX<br />T048 4<br />T049 STO I<br />T050 RDN<br />T051 RCL(I)<br />T052 ABS<br />TO53 RDN<br />T054 FS? 2<br />T055 GTO T060<br />T056 RCL K<br />T057 RCL L<br />T058 RCL M<br />T059 GTO T063<br />T060 RCL U<br />T061 RCL V<br />T062 RCL W<br />T063 R^<br />T064 RTN<br />T065 SF 10<br />T066 eq DEGENERATED<br />T067 PSE<br />T068 CF 10<br />T069 XEQ U029<br />T070 RTN<br /></pre><span style="font-weight: bold;">Comments:</span><br /><br /><a href="http://aha-hp-calcs.blogspot.com/search/label/Disclaimer">Terms of use.</a><br /><br />Mnemonics: T for Triangle.<br /><br />Uses the <a href="http://aha-hp-calcs.blogspot.com/2007/10/short-program-to-convert-2d-vector-to.html">X068 subroutine</a> to place 2D triangle in th XZ plane if flag 2 set and the <a href="http://aha-hp-calcs.blogspot.com/2007/10/3d-to-2d-projection-utility-subroutine.html">X025 routine</a> to find out which coordinate to discard for the 3D to 2D projection and finaly the <a href="http://aha-hp-calcs.blogspot.com/2007/10/hp-35s-3d-to-2d-projection-utility.html">X052 routine</a> to actual do the 3D to 2D conversion. In the 2D case this is a rather roundabout way to get end user's input into the variables U, V and W! But I think this worked out quite well in order to have one program for both the 2D and 3D case:<br /><br />One can compute barycentric coordinates in 3D using four cross product, four dot product and three scalar division operations avoiding projection from 3D to 2D, but involves more scalar math operations than the implemented method. On a vector architecture it may be a better choice, on the HP-35s architecture I think this is a good solution!<br /><br />The index of the coordinate discarded to do the 3D to 2D projection is remembered in variabe X so the next program to actual compute barycentric coordinates know which coordinate to discard from input.<br /><br />An unrelated change done to the T program is that it now check if the computed plane normal vector is considered to be of zero length: Then all points are the same or colinear, the message "DEGENERATED" is then shortly displayed and stack registers restored.<br /><br />Note that one get a cross product calculated normal vector also in the 2D case (direction<br />[0, 1, 0]), length still twice triangle's area.<br /><br /><span style="font-weight: bold;">Step 2 : Program to convert from Cartesian to Barycentric Coordinates<br /><br /></span><span style="font-weight: bold;">Stack Input/Output:</span><br /><pre>[[x, y, z], Y, Z, T | L]->XEQ B->[[b1, b2, b3], Y, Z, T | [x, y, z]]<br /></pre>Where (x, y, z) are cartesian coordinates for point in question and (b1, b2, b3) are computed barycentric coordinates.<br /><br /><span style="font-weight: bold;">Variables:</span><br /><br />Reads:<br /><pre>Q : Quotient (y1-y3)*(x2-x3)+(y2-y3)*(x2-x1). Populated by the P program.<br />U : First vertex of triangle projected to 2D (2D vector). Populated by the P program.<br />V : Second vertex of triangle projected to 2D (2D vector). Populated by the P program.<br />W : Third vertex of triangle projected to 2D (2D vector). Populated by the P program.<br />X : Index of coordinate discarded in 3D->2D projection. Populated by the P program. </pre><span style="font-weight: bold;">Program:</span><br /><pre>B001 LBL B<br />B002 XEQ U001<br />B003 FS? 2<br />B004 GTO B007<br />B005 RCL X<br />B006 XEQ X052<br />B007 eq [([0,1]xREGX-[0,1]xW)x([1,0]xV-[1,0]xW)+<br /> ([0,1]xV-[0,1]xW)x([1,0]xW-[1,0]xREGX),<br /><br /> ([0,1]xREGX-[0,1]xU)x([1,0]xW-[1,0]xU)+<br /> ([0,1]xW-[0,1]xU)x([1,0]xU-[1,0]xREGX),<br /><br /> ([0,1]xREGX-[0,1]xV)x([1,0]xU-[1,0]xV)+<br /> ([0,1]xU-[0,1]xV)x([1,0]xV-[1,0]xREGX)]/Q<br />B008 XEQ U050<br />B009 RTN<br /></pre><span style="font-weight: bold;">Comments:</span><br /><br /><a href="http://aha-hp-calcs.blogspot.com/search/label/Disclaimer">Terms of use.</a><br /><br />Mnemonics: B for Barycentric.<br /><br />If the input is a 2D (flag 2 set) then goes straight to the equation that calculates baycentric coordinates using the data precomputed by the modified T program, else first project the 3D input to 2D using <a href="http://aha-hp-calcs.blogspot.com/2007/10/hp-35s-3d-to-2d-projection-utility.html">subroutine X052</a> and information found in the X variable.Arne Halvorsenhttps://plus.google.com/102376059110739689820noreply@blogger.com0tag:blogger.com,1999:blog-3382086684136465654.post-22799277917115244412007-10-15T01:20:00.000+02:002007-10-16T20:50:00.315+02:00HP-35s 2D to 3D vector conversionShort program to convert a 2D vector to a 3D by placing it in the z=0 plane. Usefull when want to utilize 3D solutions to 2D data, for example taking cross product of two 2D vectors.<br /><br /><span style="font-weight: bold;">Stack Input/Output:</span><br /><pre>[[u, v], Y, Z, T | L]-> XEQ 068 ->[[u, v, 0], Y, Z, T | [u, v]]</pre><span style="font-weight: bold;">Program:</span><br /><pre>X068 ABS<br />X069 RDN<br />X070 eq [[1,0]xLASTX,[0,1]xLASTX,0]<br />X071 RTN<br /></pre><span style="font-weight: bold;">Comments:</span><br /><br /><a href="http://aha-hp-calcs.blogspot.com/search/label/Disclaimer">Terms of use.</a><br /><br />Placed in the X 'library' since a vector utlity, from before have <a href="http://aha-hp-calcs.blogspot.com/2007/10/hp-35s-3d-to-2d-projection-utility.html">projecting to a cardinal plane</a>, <a href="http://aha-hp-calcs.blogspot.com/2007/10/3d-to-2d-projection-utility-subroutine.html">finding the component of a 3D vector with max absolute value</a>, <a href="http://aha-hp-calcs.blogspot.com/2007/10/hp-35s-3d-and-2d-vector-unpack.html">vector unpack routines</a>, <a href="http://aha-hp-calcs.blogspot.com/2007/09/cross-product-and-normalizing-vector-on.html">cross product and normalization</a>.Arne Halvorsenhttps://plus.google.com/102376059110739689820noreply@blogger.com0tag:blogger.com,1999:blog-3382086684136465654.post-49734773807931995162007-10-14T13:56:00.000+02:002007-10-16T20:50:46.862+02:00HP-35s 3D to 2D projection utility subroutines - IISubroutine to project a 3D vector to 2D by paralell projection to one of the cardinal planes; discards one coordinate.<br /><br /><span style="font-weight: bold;">Stack Input/Output</span><br /><pre>[n, [u,v,w], Z, T | L]-> X047 ->[[x,y], n, [u,v,w], Z | L]</pre>Where n tells which coordinate to discard: [x=v, y=w] if n=1, [x=u, y=w] if n=2 and [x=u, y=v] if n=3.<br /><br /><span style="font-weight: bold;">Program:</span><br /><pre>X052 1<br />X053 X=Y?<br />X054 GTO X062<br />X055 RDN<br />X056 2<br />X057 X=Y?<br />X058 GTO X065<br />X059 RDN<br />X060 eq [[1,0,0]xREGY,[0,1,0]xREGY]<br />X061 RTN<br />X062 RDN<br />X063 eq [[0,1,0]xREGY,[0,0,1]xREGY]<br />X064 RTN<br />X065 RDN<br />X066 eq [[1,0,0]xREGY,[0,0,0]xREGY]<br />X067 RTN<br /></pre><span style="font-weight: bold;">Comments:<br /></span><br /><a href="http://aha-hp-calcs.blogspot.com/search/label/Disclaimer">Terms of use.</a><br /><br />The parameter n is typical found using the X025 subroutine.<br /><br />Placed in the X 'library' since a vector utlity, from before have <a href="http://aha-hp-calcs.blogspot.com/2007/10/3d-to-2d-projection-utility-subroutine.html">finding the component of a 3D vector with max absolute value</a>, <a href="http://aha-hp-calcs.blogspot.com/2007/10/hp-35s-3d-and-2d-vector-unpack.html">vector unpack routines</a>, <a href="http://aha-hp-calcs.blogspot.com/2007/09/cross-product-and-normalizing-vector-on.html">cross product and normalization</a>.<br /><br /><span style="font-weight: bold;">Change history:<br /><br /></span>20071014:1723UTC : Because of change in the <a href="http://aha-hp-calcs.blogspot.com/2007/10/3d-to-2d-projection-utility-subroutine.html">X025 subroutine</a> line numbers changed here. Entry point used to be X047 but is now X052.Arne Halvorsenhttps://plus.google.com/102376059110739689820noreply@blogger.com0tag:blogger.com,1999:blog-3382086684136465654.post-22702500232138637912007-10-12T18:50:00.000+02:002007-10-17T19:00:22.058+02:00HP-35s 3D to 2D projection utility subroutines - IUtility 3D vector subroutine to tell which component that has the largest absolute value.<br /><br />This is of use when projecting points in an arbitary plane to one of the three cardinal planes in order to reduce a 3D problem to a 2D problem (when possible). Use this subroutine on the arbitary plane's normal vector in order to decide which 3D coordinate to discard in order to avoid all points to be projected on a line if arbitary plane is perpendicular to the choosen cardinal plane or to avoid floating precision problems in case they are nearly perpendicular:<br /><br />Examine the arbitary plane's normal vector (using this subroutine) and discard the coordinate that has the maximum absolute value.<br /><br /><span style="font-weight: bold;">Stack Input/Output:</span><br /><pre>[[u, v, w], Y, Z, T | L]-> XEQ X025 ->[n, -, -, - | [u, v, w]]</pre>Where [u, v, w] is the vector in question and n is 1 if u has largest absolute value, 2 if v has and 3 if w has.<br /><br /><span style="font-weight: bold;">Program:</span><br /><pre>X025 XEQ X008<br />X026 LASTX<br />X027 RDN<br />X028 ABS<br />X029 RDN<br />X030 ABS<br />X031 RDN<br />X032 ABS<br />X033 X<>Y<br />X034 ABS<br />X035 X<>Y<br />X036 R^<br />X037 X>=Y?<br />X038 GTO X047<br />X039 X<>Y<br />X040 R^<br />X041 X<Y?<br />X042 GTO X045<br />X043 3<br />X044 RTN<br />X045 1<br />X046 RTN<br />X047 R^<br />X048 X>=Y?<br />X049 GTO X043<br />X050 2<br />X051 RTN<br /></pre><span style="font-weight: bold;">Comments:<br /><br /></span><a href="http://aha-hp-calcs.blogspot.com/search/label/Disclaimer">Terms of use.</a><br /><br />Placed in the X 'library' since a vector utlity, from before have <a href="http://aha-hp-calcs.blogspot.com/2007/10/hp-35s-3d-and-2d-vector-unpack.html">vector unpack routines</a>, <a href="http://aha-hp-calcs.blogspot.com/2007/09/cross-product-and-normalizing-vector-on.html">cross product and normalization</a>.<br /><br /><span style="font-weight: bold;">Change history:<br /></span><br />20071014:1723UTC : Problem that vector lost, changed so vector now can be found in LASTX register. <span style="font-style: italic;">This also effects the <a href="http://aha-hp-calcs.blogspot.com/2007/10/hp-35s-3d-to-2d-projection-utility.html">X047 subroutine now X052 subroutine</a> and those using that: Entry point address changed to X052.</span>Arne Halvorsenhttps://plus.google.com/102376059110739689820noreply@blogger.com1tag:blogger.com,1999:blog-3382086684136465654.post-34780014504594349742007-10-11T22:53:00.001+02:002007-10-22T17:14:03.668+02:00HP-35s Euclid Implementation - XII : Plane Plane IntersectionThe intersection between two non paralell planes is a line (problem 13 of the <a href="http://aha-hp-calcs.blogspot.com/2007/09/euclid-pack-geometric-calculator.html">requirements</a>).<br /><br />The program here computes two points that defines the intersection line between the plane defined by the <a href="http://aha-hp-calcs.blogspot.com/2007/09/hp-35s-euclid-implementation-vii.html">P program</a> and a second plane given as input to this program.<br /><br /><span style="font-weight: bold;">Stack Input/Output:</span><br /><pre>[[nx, ny, nz], [px, py, pz], Z, T | L]-> XEQ V ->[[x1, y1, z1], [x0, y0, z0], [nx, ny, nz], [px, py, pz] | L]<br /></pre>The input of the second plane is similar to defining the first plane using the <a href="http://aha-hp-calcs.blogspot.com/2007/09/hp-35s-euclid-implementation-vii.html">P program</a>: [nx, ny, nz] in X stack register is a vector normal to the second plane and (px, py, pz) in Y stack register is a point in the second plane. The result in the case the planes are not paralell is two points defining the line: (x0, y0, z0) and (x1, y1, z1).<br /><br />In the case the planes are paralell the message "PARALELL" is displayed shortly, stack and LASTX registers are then left unchanged.<br /><br /><span style="font-weight: bold;">Variables:<br /><br /></span>Writes:<br /><pre>R : Normalized normal vector.<br />S : Distance from origo (0,0,0) to plane.<br />T : Defining point in the plane.<br />Z : Scratch data.<br /></pre><span style="font-weight: bold;">Program:</span><br /><pre>V001 LBL V<br />V002 XEQ U001<br />V003 XEQ X004<br />V004 STO R<br />V005 X<>Y<br />V006 STO T<br />V007 X<>Y<br />V008 x<br />V009 +/-<br />V010 STO S<br />V011 RCL N<br />V012 LASTX<br />V013 XEQ X001<br />V014 STO Z<br />V015 ABS<br />V016 1E-6<br />V017 X>Y?<br />V018 GTO M041<br />V019 LASTX<br />V020 XEQ X025<br />V021 1<br />V022 X=Y?<br />V023 GTO V032<br />V024 RDN<br />V025 2<br />V026 X=Y?<br />V027 GTO V036<br />V028 eq (Sx([0,1,0]xN)-Ox([0,1,0]xR))/([0,0,1]xZ)<br />V029 eq (Ox([1,0,0]xR)-Sx([1,0,0]xN))/([0,0,1]xZ)<br />V030 0<br />V031 GTO VO39<br />V032 0<br />V033 eq (Sx([0,0,1]xN)-Ox([0,0,1]xR))/([1,0,0]xZ)<br />V034 eq (Ox([0,1,0]xR)-Sx([0,1,0]xN))/([1,0,0]xZ)<br />V035 GTO V039<br />V036 eq (Ox([0,0,1]xR)-Sx([0,0,1]xN))/([0,1,0]xZ)<br />V037 0<br />V038 eq (Sx([1,0,0]xN)-Ox([1,0,0]xR))/([0,1,0]xZ)<br />V039 eq [REGZ,REGY,REGX]<br />V040 ENTER<br />V041 ENTER<br />V042 RCL+ Z<br />V043 XEQ U079<br />V044 RTN<br /></pre><span style="font-weight: bold;">Comments:<br /><br /></span><a href="http://aha-hp-calcs.blogspot.com/search/label/Disclaimer">Terms of use.</a><br /><br />Mnemonic: None.<br /><br />The program stores the normalized implicit equation for the second plane and it's defining point in the calculator the same way as the <a href="http://aha-hp-calcs.blogspot.com/2007/09/hp-35s-euclid-implementation-vii.html">P program</a> does for the first plane: The normalized normal vector is stored in variable R, distance to origo in variable S and defining point in variable T. Mnemonics for these are that the keys associated with these variables are below and to the left of the keys assigned to the variables N, O and P where the same values are stored for the plane defined using the program P. This makes the relation between the <a href="http://aha-hp-calcs.blogspot.com/2007/09/hp-35s-euclid-implementation-vii.html">P program</a> and V program similar to the relation between the <a href="http://aha-hp-calcs.blogspot.com/2007/09/hp-35s-euclid-implementation-i.html">L program</a> and the <a href="http://aha-hp-calcs.blogspot.com/2007/09/hp-35s-euclid-implementation-vi.html">M program</a>.<br /><br />This program needs to compute and store the cross product of the two plane's normal vector: If this vector is of zero length the planes are paralell else it is a directional vector for the intersection line. This vector is stored in the Z variable.<br /><br />This shares the show "PARALELL" message and stack restore code with the <a href="http://aha-hp-calcs.blogspot.com/2007/09/hp-35s-euclid-implementation-vi.html">M program</a> in the no solution case.<br /><br /><span style="font-weight: bold;">Change history:<br /></span><br />20071013:1415UTC : This program was implemented before the <a href="http://aha-hp-calcs.blogspot.com/2007/10/3d-to-2d-projection-utility-subroutine.html">X025 routine</a> that finds the component of a 3D vector with largest absolute value. This program did that inline, now gone back and modified this program to use <a href="http://aha-hp-calcs.blogspot.com/2007/10/3d-to-2d-projection-utility-subroutine.html">X025</a>.Arne Halvorsenhttps://plus.google.com/102376059110739689820noreply@blogger.com0tag:blogger.com,1999:blog-3382086684136465654.post-47612377611110326212007-10-11T22:31:00.001+02:002007-10-11T22:35:25.861+02:00Addition to the HP-35s stack save/restore program - IIIAddition to the <a href="http://aha-hp-calcs.blogspot.com/2007/10/addition-to-stack-saverestore-program.html">U program</a> when in need to restore LASTX register and push two new values on the stack:<br /><pre>[X, Y, Z, T | L]-> Program invoking U001 first and U070 last ->[X', Y', X, Y | L]</pre>Where X' is new content of X stack register present in the X stack register before U079 is executed and Y' is new content of Y stack register present in Y stack register before U079 is executed.<br /><br />Of interest for programs that do not take stack register input but produces a result in the X and Y stack register.<br /><br /><span style="font-weight: bold;">Program:</span><br /><pre>U079 4<br />U080 STO I<br />U081 RDN<br />U082 RCL(I)<br />U083 ABS<br />U084 RDN<br />UO85 XEQ U041<br />U086 R^<br />U087 R^<br />U088 RTN</pre><span style="font-weight: bold;">Comments:<br /></span><br /><a href="http://aha-hp-calcs.blogspot.com/search/label/Disclaimer">Terms of use.</a><br /><br />So now we have the subroutines:<br /><ol><li>XEQ U001 to save the stack and LASTX.</li><li>XEQ U029 to restore the stack and LASTX given U001 has been used to save.</li><li>XEQ U050 to implement operation native unary operation stack and LASTX behaviour given U001 has been used to save.</li><li>XEQ U070 to push single value on the stack and preserve LASTX given U001 has been used to save.</li><li>XEQ U079 to push two values on the stack and preserve LASTX given U001 has been used to save.</li></ol>Arne Halvorsenhttps://plus.google.com/102376059110739689820noreply@blogger.com0tag:blogger.com,1999:blog-3382086684136465654.post-61709356635574003372007-10-09T21:41:00.000+02:002007-10-10T16:31:23.155+02:00Communicating RPN stack and LASTX register transitions, a notationI will try using the following notation to communicate program's effect on the stack and LASTX register:<br /><pre>[X, Y, Z, T | L]-> opr. desc. ->[X', Y', Z', T' | L']</pre>So for example to describe sqrt:<br /><pre>[X, Y, Z, T | L]-> sqrt ->[sqrt(X), Y, Z, T | X]</pre>and addition:<br /><pre>[X, Y, Z, T | L]-> + ->[Y+X, Z, T, T | X]</pre>Arne Halvorsenhttps://plus.google.com/102376059110739689820noreply@blogger.com0tag:blogger.com,1999:blog-3382086684136465654.post-69352108740767472592007-10-07T11:34:00.000+02:002007-10-16T21:04:14.379+02:00HP-35s 3D and 2D vector unpack subroutinesSubroutines to unpack 3D and 2D vectors when need to work on individual components.<br /><br /><span style="font-weight: bold;">Stack Input/Output:</span><br /><pre>3D case: [[u0, u1, u2], Y, Z, T | L]-> X008 ->[u2, u1, u0, u0 | [u0, u1, u2]]<br /><br />2D case: [[u0, u1], Y, Z, T | L]-> X018 ->[u1, u0, Y, Y | [u0, u1]]<br /></pre><span style="font-weight: bold;">Program:</span><br /><pre>XOO8 [1,0,0]<br />X009 X<>Y<br />X010 x<br />X011 [0,1,0]<br />X012 LASTX<br />X013 x<br />X014 [0,0,1]<br />X015 LASTX<br />X016 x<br />X017 RTN<br />X018 [1,0]<br />X019 X<>Y<br />X020 x<br />X021 [0,1]<br />X022 LASTX<br />X023 x<br />X024 RTN<br /></pre><span style="font-weight: bold;">Comments:<br /><br /></span><a href="http://aha-hp-calcs.blogspot.com/search/label/Disclaimer">Terms of use.</a><br /><br />Uses the X label for vector utility programs/routines, from before have <a href="http://aha-hp-calcs.blogspot.com/2007/09/cross-product-and-normalizing-vector-on.html">cross product and normalization</a>.Arne Halvorsenhttps://plus.google.com/102376059110739689820noreply@blogger.com0tag:blogger.com,1999:blog-3382086684136465654.post-34536738055487368342007-10-03T20:11:00.000+02:002007-10-17T10:46:16.129+02:00HP-35s Euclid Implementation - XI : Line Plane IntersectionThe point of intersection between a line and a plane (problem 12 in the <a href="http://aha-hp-calcs.blogspot.com/2007/09/euclid-pack-geometric-calculator.html">requirements</a>) is given by the parameter (to it's parametric equation) t=-(ax0+by0+cz0+d)/n*(p1-p0) (* is here the dot product) where p0=(x0, y0, z0) and p1 are the two points defining the line.<br /><br />The following program finds the intersection between the 3D line defined using the <a href="http://aha-hp-calcs.blogspot.com/2007/09/hp-35s-euclid-implementation-i.html">L program</a> (p0 stored in variable A and p1 stored in variable B) and the plane defined using the <a href="http://aha-hp-calcs.blogspot.com/2007/09/hp-35s-euclid-implementation-vii.html">P program</a> ([a, b, c] stored in variable N and d stored in variable O).<br /><br /><span style="font-weight: bold;">Stack Input/Output:</span><br /><pre>No input on stack-> XEQ R ->[t, X, Y, Z | L]</pre>Where t is the parameter defining intersection point using line <span style="font-style: italic;">l's </span>parametric equation.<br /><br />If n*(p1-p0)=0 then the line and the plane are paralell and there is no intersection point. In that case the message "PARALELL" is displayed shortly, stack and LASTX registers are then left unchanged.<br /><br /><span style="font-weight: bold;">Variables:<br /><br /></span>Reads:<br /><pre>A : Line's first defining point. Populated by the <a href="http://aha-hp-calcs.blogspot.com/2007/09/hp-35s-euclid-implementation-i.html">L program</a>.<br />B : Line's second defining point. Populated by the <a href="http://aha-hp-calcs.blogspot.com/2007/09/hp-35s-euclid-implementation-i.html">L program</a>.<br />N : Plane's normalized normal vector. Populated by the <a href="http://aha-hp-calcs.blogspot.com/2007/09/hp-35s-euclid-implementation-vii.html">P program</a><span style="font-weight: bold;"></span>.<br />O : Plane's distance to origo (0, 0, 0). Populated by the <a href="http://aha-hp-calcs.blogspot.com/2007/09/hp-35s-euclid-implementation-vii.html">P program</a>.<br /></pre><span style="font-weight: bold;">Program:</span><br /><pre>R001 LBL R<br />R002 XEQ U001<br />R003 RCL N<br />R004 RCL B<br />R005 RCL A<br />R006 -<br />ROO7 x<br />R008 ABS<br />R009 1E-6<br />R010 X>Y?<br />R011 GTO M041<br />R012 RDN<br />R013 LASTX<br />R014 eq -(AxN+0)/REGX<br />R015 XEQ U070<br />R016 RTN<br /></pre><span style="font-weight: bold;">Comments:<br /><br /></span><a href="http://aha-hp-calcs.blogspot.com/search/label/Disclaimer">Terms of use.</a><br /><br />Mnemonic: None.<br /><br />Again when the result is a point on a line we produce the parameter giving the point, not the coordinates. So for example one learns that the <span style="font-style: italic;">line segment</span> A, B intersect the plane if result is in the range [0, 1]. To get the coordinates end user does <a href="http://aha-hp-calcs.blogspot.com/2007/09/hp-35s-euclid-implementation-iii.html">XEQ E</a>.<br /><br />Uses the new <a href="http://aha-hp-calcs.blogspot.com/2007/10/addition-to-stack-saverestore-program.html">subroutine U070</a> to raise the stack and preserve LASTX register content in the case there is a solution (line and plane not paralell).<br /><br />This shares the show "PARALELL" message and stack restore code with the <a href="http://aha-hp-calcs.blogspot.com/2007/09/hp-35s-euclid-implementation-vi.html">M program</a> in the no solution case.<br /><br /><span style="font-weight: bold;">Change history:<br /></span><br />20071004:1835UTC : Fixed typo in line R011, was GTO M014!<a href="http://aha-hp-calcs.blogspot.com/2007/10/hp-35s-euclid-implementation-x-closest.html"><br /></a>Arne Halvorsenhttps://plus.google.com/102376059110739689820noreply@blogger.com0tag:blogger.com,1999:blog-3382086684136465654.post-25869970141744116292007-10-03T15:42:00.000+02:002007-10-10T17:15:21.386+02:00Addition to the HP-35s stack save/restore program - IIExtenstion to the <a href="http://aha-hp-calcs.blogspot.com/2007/09/addition-to-stack-saverestore-program.html">U program</a> for the case when a result has been produced and should be <span style="font-style: italic;">pushed</span> on the stack:<br /><pre>[X, Y, Z, T | L]->Program invoking U001 first and U070 last ->[X', X, Y, Z | L]</pre>Where X' is new content of X stack register present in the X stack register before U070 is executed.<br /><br />Of interest for programs that do not take stack register input but produces a result in the X stack register.<br /><br /><span style="font-weight: bold;">Program:</span><br /><pre>U070 4<br />U071 STO I<br />U072 RDN<br />U073 RCL(I)<br />U074 ABS<br />U075 RDN<br />U076 XEQ U037<br />U077 R^<br />U078 RTN<br /></pre><span style="font-weight: bold;">Comments:<br /></span><br /><a href="http://aha-hp-calcs.blogspot.com/search/label/Disclaimer">Terms of use.</a><br /><br />So now we have the subroutines:<br /><ol><li>XEQ U001 to save the stack and LASTX.</li><li>XEQ U029 to restore the stack and LASTX given U001 has been used to save.</li><li>XEQ U050 to implement operation native unary operation stack and LASTX behaviour given U001 has been used to save.</li><li>XEQ U070 to push single value on stack and preserve LASTX given U001 has been used to save.</li></ol>Arne Halvorsenhttps://plus.google.com/102376059110739689820noreply@blogger.com0tag:blogger.com,1999:blog-3382086684136465654.post-6428362252112765612007-10-02T21:06:00.000+02:002007-10-02T21:31:55.597+02:00DisclaimerOh, since I'am posting code I guess I should have one of these....<br /><br /><b>You are welcome to use the programs you find on this site free of charge. While I hope these programs become rather bug free and robust I make no claim that they are. I am not liable for any damages, injuries, or losses that may result in using any of these programs. By using these programs or ones that you create based on them, you agree to these terms.</b>Arne Halvorsenhttps://plus.google.com/102376059110739689820noreply@blogger.com0tag:blogger.com,1999:blog-3382086684136465654.post-22525287044648602007-10-02T15:07:00.000+02:002007-10-17T10:50:32.309+02:00HP-35s Euclid Implementation - X : Closest point on a plane to a pointThe closest point on a plane to a point P is P-(P*N+d)*N where N is the plane's normalized normal vector and d is the plane's distance to origo (* is here the dot product).<br /><br />Since the <a href="http://aha-hp-calcs.blogspot.com/2007/09/hp-35s-euclid-implementation-vii.html">program P</a> stores N in variable N and d in variable O the following short program computes the closest point on the plane entered using <a href="http://aha-hp-calcs.blogspot.com/2007/09/hp-35s-euclid-implementation-vii.html">program P</a> if the point's positional vector is in the X stack register (problem 11 in the <a href="http://aha-hp-calcs.blogspot.com/2007/09/euclid-pack-geometric-calculator.html">requirements</a>).<br /><br /><span style="font-weight: bold;">Stack Input/Output:</span><br /><pre>[[x, y, z], Y, Z, T | L]-> XEQ Q ->[[cx, cy, cz], [x, y, z], Y, Z | L]</pre>Where (x, y, z) is point <span style="font-style: italic;">p </span>and (cx, cy, cz) is closest point in plane to <span style="font-style: italic;">p.<br /><br /></span><span style="font-weight: bold;">Variables:<br /><br /></span>Reads:<br /><pre>N : Plane's normalized normal vector. Populated by the <a href="http://aha-hp-calcs.blogspot.com/2007/09/hp-35s-euclid-implementation-vii.html">P program</a><span style="font-weight: bold;"></span>.<br />O : Plane's distance to origo (0, 0, 0). Populated by the <a href="http://aha-hp-calcs.blogspot.com/2007/09/hp-35s-euclid-implementation-vii.html">P program</a>.</pre><span style="font-weight: bold;">Program:</span><br /><pre>Q001 LBL Q<br />Q002 eq REGX-(REGXxN+O)xN<br />Q003 RTN<br /></pre><span style="font-weight: bold;">Comments:<br /></span><br /><a href="http://aha-hp-calcs.blogspot.com/search/label/Disclaimer">Terms of use.</a><br /><br />Mnemonic: Sorry, run out :-(<br /><br />Unless the input is a point in the plane (if this is the case the vectors in Y and X stack register are the same after execution) the line defined by the point in Y stack register and the point in X stack register defines the perpendicular line from point now in the Y stack register onto the plane entered using the <a href="http://aha-hp-calcs.blogspot.com/2007/09/hp-35s-euclid-implementation-vii.html">program P</a>. May be used as input to the <a href="http://aha-hp-calcs.blogspot.com/2007/09/hp-35s-euclid-implementation-i.html">L program</a> or <a href="http://aha-hp-calcs.blogspot.com/2007/09/hp-35s-euclid-implementation-vi.html">M program</a>.Arne Halvorsenhttps://plus.google.com/102376059110739689820noreply@blogger.com0tag:blogger.com,1999:blog-3382086684136465654.post-34454253871160377882007-10-01T18:05:00.000+02:002007-10-17T11:15:53.065+02:00HP-35s Euclid Implementation - IX : Signed distance from a plane to a pointThe plane <span style="font-style: italic;">is</span> the hyperplane of 3D (like a line in 2D divides the space a plane divide 3D space) so since <a href="http://aha-hp-calcs.blogspot.com/2007/09/hp-35s-euclid-implementation-vii.html">program P</a> stores the plane's <span style="font-style: italic;">normalized </span>implicit equation point p=(x, y, z)'s signed distance to the plane is ax+by+cz+d or (since [a, b, c] is stored in variable N and d is stored in variable O) <span style="font-style: italic;"> </span>N*p+O where * here is the dot product operator.<br /><br />I choose to modify the <a href="http://aha-hp-calcs.blogspot.com/2007/09/hp-35s-euclid-implementation-ii.html">S program</a> so that it computes the signed distance in 2D (as before) if flag 2 is set and else computes signed distance in 3D (to the plane defined by the P program); problem 10 of the <a href="http://aha-hp-calcs.blogspot.com/2007/09/euclid-pack-geometric-calculator.html">requirements</a>.<br /><br /><span style="font-weight: bold;">Stack Input/Output:<br /><br /></span>2D case:<br /><pre>[[x, y], Y, Z, T | L]-> XEQ S ->[d, Y, Z, T | [x, y]]</pre>3D case:<br /><pre>[[x, y, z], Y, Z, T | L]-> XEQ S ->[d, Y, Z, T | [x, y, z]]<br /></pre>Where (x, y) or (x, y, z) is point to find distance to and d is the signed distance.<br /><br /><span style="font-weight: bold;">Variables:<br /><br /></span>Reads:<br /><pre>C : [a, b, c], constants of line's normalized implicit equation. Populated by the <a href="http://aha-hp-calcs.blogspot.com/2007/09/hp-35s-euclid-implementation-i.html">L program</a>. Reads in 2D case (flag 2 set).<br />N : Plane's normalized normal vector. Populated by the <a href="http://aha-hp-calcs.blogspot.com/2007/09/hp-35s-euclid-implementation-vii.html">P program</a><span style="font-weight: bold;"></span>. Reads in 3D case.<br />O : Plane's distance to origo (0, 0, 0). Populated by the <a href="http://aha-hp-calcs.blogspot.com/2007/09/hp-35s-euclid-implementation-vii.html">P program</a>. Reads in 3D case. </pre><span style="font-weight: bold;">Program:</span><br /><pre>S001 LBL S<br />S002 ABS<br />S003 RDN<br />S004 FS? 2<br />S005 GTO 008<br />S006 eq LASTXxN+O<br />S007 RTN<br />S008 eq (([1,0,0]xC)x([1, 0]xLASTX))+(([0,1,0]xC)x([0,1]xLASTX))+[0,0,1]xC<br />S009 RTN</pre><span style="font-weight: bold;">Comments:</span><br /><br /><a href="http://aha-hp-calcs.blogspot.com/search/label/Disclaimer">Terms of use.</a><br /><br />As before point to find signed distance to in the X stack register: Again, if had an dim operator for vectors would not need for the end user to toggle the 2 flag, could branch on dimension of argument in the X stack register.Arne Halvorsenhttps://plus.google.com/102376059110739689820noreply@blogger.com0tag:blogger.com,1999:blog-3382086684136465654.post-24409434911845465942007-09-30T15:03:00.000+02:002007-10-18T20:52:11.526+02:00HP-35s Euclid Implementation - VIII : Defining a triangleYet another 'data entry' program, this one for defining a triangle in 3D space. It will be needed for solving triangle problems (14-17 of the <a href="http://aha-hp-calcs.blogspot.com/2007/09/euclid-pack-geometric-calculator.html">requirements</a>) but is also usefull to solve plane problems when the plane is defined by three points (problem 9 A of the <a href="http://aha-hp-calcs.blogspot.com/2007/09/euclid-pack-geometric-calculator.html">requirements</a>), so introducing it now.<br /><br />The program accepts triangle's first point in the Z stack register, second point in Y stack register and third point in the X stack register, all expected to be 3D vectors. Program performs two tasks:<br /><ol><li>Store the points in the variables K (first point), L (second point) and M (third point). These variables will be used later in solving triangle problems.<br /></li><li>Returns in the X stack register a vector normal to the plane defined by the triangle computed as (L-K)x(M-K) (x is here the cross product). This gives the area of the triangle since the length of this vector is twice the area (keystrokes: ABS, 2, /).</li></ol><span style="font-weight: bold;">Stack Input/Output:</span><br /><pre>[[x2, y2, z2], [x1, y1, z1], [x0, y0, z0] | L]->XEQ T->[[nx, ny, nz], [x2, y2, z2], [x1, y1, z1], [x0, y0, z0] | L]<br /></pre>Where v0=(x0, y0, z0) is first, v1=(x1, y1, z1) is second, v2=(x2, y2, z2) is the third triangle vertex and [nx, ny, nz] is the cross product (v1-v0)x(v2-v0).<br /><br /><span style="font-weight: bold;">Variables:</span><br /><br />Writes:<br /><pre>K : First vertex.<br />L : Second vertex.<br />M : Third vertex.<br /></pre><span style="font-weight: bold;">Program:</span><br /><pre>T001 LBL T<br />TOO2 5<br />T003 STO I<br />T004 STO(I)<br />T005 RDN<br />T006 4<br />T007 STO I<br />T008 RDN<br />T009 LASTX<br />T010 STO(I)<br />T011 RDN<br />T012 STO M<br />T013 RDN<br />T014 STO L<br />T015 RDN<br />T016 STO K<br />T017 R^<br />T018 X<>Y<br />T019 -<br />T020 RDN<br />T021 RDN<br />T022 LASTX<br />T023 -<br />T024 X<>Y<br />T025 RDN<br />T026 XEQ X001<br />T027 RCL(I)<br />T028 ABS<br />T029 RDN<br />T030 RCL K<br />T031 RCL L<br />T032 RCL M<br />T033 R^<br />T034 RTN<br /></pre><span style="font-weight: bold;">Comments:</span><br /><br /><a href="http://aha-hp-calcs.blogspot.com/search/label/Disclaimer">Terms of use.</a><br /><br />Mnemonic: T for triangle.<br /><br />If end user need to compute the plane's normalized implicit equation she may simply do XEQ P since X stack register contains a vector normal to the plane and Y register a point in the plane (triangle's third vertex).<br /><br /><span style="font-weight: bold;">Change history:<br /></span><br />20071018:1950UTC : This program has been <a href="http://aha-hp-calcs.blogspot.com/2007/10/hp-35s-euclid-implementation-xiii.html">modified</a> as a part of providing for Cartesion to Barycentric coordinate transformation.Arne Halvorsenhttps://plus.google.com/102376059110739689820noreply@blogger.com0