archive-com.com » COM » E » EFG2.COM

Total: 878

Choose link from "Titles, links and description words view":

Or switch to "Titles and links view".
  • efg's Mathematics Projects -- Maze Maker
    on the screen Press the Save button to create a BMP file The PixelFormat of the BMP file will be the same as the current display mode Change the appearance of the maze solution path using the PathStyle or PathColor RadioGroup selections and the Show Path CheckBox Click on the Color TShape object to change the definition of the Solid path color If the path is not shown the Show Path checkbox is not checked then red ellipses mark the start and end points of the maze If you select the Block Path Style you can flood fill the connected regions of the maze area by clicking on a point on the maze Reconstruct any maze by entering the random number generator Seed in the edit box Discussion The WMGetMinMaxInfo routine in the ScreenMazeMaker unit enforces a minimum window size as a response to a Windows wm GetMinMaxInfo message The UpdateMaze routine in the ScreenMazeMaker unit is called by the various controls whenever a value changes that affects the maze Direct entry of values in the SpinBoxes can cause problem when the SpinBox is blank Borland should make a TSpinBox more than an undocumented Sample especially by version 4 of Delphi The Maze Algorithm is in the MazeLibrary unit in the DrawMaze routine Each cell in the maze is represented by a 2 bit quantity a 0 3 type in a dynamically allocated two dimensional Cells array using the Delphi 4 SetLength routine Bit 0 is set if the cell has an East exit and bit 1 is set if it has a South exit To test if a North or West exit exists the appropriate adjacent cells must be considered The DrawMaze routine shows an interesting way to create a stack in Delphi In line assembly language was used

    Original URL path: http://www.efg2.com/Lab/Mathematics/MazeMaker.htm (2016-02-14)
    Open archived version from archive


  • efg's Mathematics Projects -- Gauss-Legendre Quadrature
    ComboBoxFunctionChange procedure Compile the GaussLegendreTest project in Delphi 3 or 4 Run the GaussLegendreTest program Experiment with various Integrand functions and definite integral limits Discussion The following data were taken using the GaussLegendreTest program using 15 point quadrature Integrand A B Observed Value Exact Value 1 x 1 0 2 0 0 69314 71806 27782 0 69314 71805 59945 exp x 0 0 1 0 1 71828 18286 2713 1 71828 18284 59045 e 1 sin x 0 0 3 141593 2 00000 00002 5578 2 This technique of integrand evaluation at n 1 functional values should yield the exact integral when the Integrand is a polynomial of degree 2n 1 or less This is because of the use of orthogonal Legendre polynomials A function can be passed as a parameter using a construct like the following TYPE TRealFunction FUNCTION CONST X DOUBLE DOUBLE FUNCTION GaussLegendreQuadrature CONST A B DOUBLE CONST N INTEGER CONST F TRealFunction DOUBLE The function F is passed to GaussLegendreQuadrature as the integrand of the definite integral evaluated from A to B For a commerical package take a look at Quadrature by Engineering Objects International Conclusions Gauss Lengendre is an efficient technique for numeric evaluation of

    Original URL path: http://www.efg2.com/Lab/Mathematics/GaussLegendre.htm (2016-02-14)
    Open archived version from archive

  • efg's Buffon's Needles Lab Report
    the Reset button is pressed or when the Setup algorithm is changed ResetState clears the toss and graph areas and draws the axes on the graph The parallel lines are drawn using the value specified in the Areas TSpinBox When there are N areas there are N 1 lines including the top and bottom lines of the toss area A ProgressBar and Cancel button appears when more than 100 needles are tossed Pressing the Cancel button sets a flag that is recognized inside the computation loop Application ProcessMessages is called when each 1 of the calculations have been completed Actually it s called after each 0 2 of calculations are completed when more than 1 000 000 tosses are made The computations can be completed much more quickly by unchecking the Graphics checkbox The ButtonTossClick method is called when the Toss button is pressed This method loops for the specified number of times and calls the TossBuffonNeedle method The TossBuffonNeedle procedure assumes L W 1 to avoid needless computations The value of D which is the distance from a parallel line to the midpoint of the needle is computed by D Random 0 5 D ranges from 0 5 below a line to 0 5 above a line The random orientation angle q ranges from 0 to 180 degrees p radians q is defined by calling the DirectionVectorRoutine which is a procedure variable that can have a value of Method1 Method2 Method3 or Method 4 These direction methods will be discussed later but each routine defines the values x y Sin q and Cos q A random direction vector is from 0 0 to x y and forms an angle q with the positive X axis See the diagrams below explaining the various random direction generation methods The Cos q value is only computed to display the toss Only Sin q is needed to compute whether a needle crosses a line update statistics INC TossCount IF ABS D 0 5 SinTheta THEN INC CrossCount Once the D and q values are computed and the statistics are updated the toss is moved to a random location on the display First the midpoint in the display space is determined randomly define midpoint of needle in throwing space xMid Random BitmapTosses Width 1 determine placement of needle midpoint yMid PixelsBetweenParallelLines Random 1 ParallelLineCount ROUND D PixelsBetweenParallelLines With this midpoint location the needle is drawn with a random color except white xDelta ROUND HalfLength CosTheta yDelta ROUND HalfLength SinTheta BitmapTosses Canvas Pen Color RGB Random 250 Random 250 Random 250 BitmapTosses Canvas MoveTo xMid xDelta yMid yDelta BitmapTosses Canvas LineTo xMid xDelta yMid yDelta To update the dot graph the ArcTan function is used to find the angle and the SimplePantograph is used to map the x y real world coordinates to i j pixel coordinates angle ArcTan2 y x SimplePantograph MapRealToPixel angle ABS D i j IF ABS D 0 5 SinTheta THEN BitmapGraph Canvas Pixels i j clRed ELSE BitmapGraph Canvas Pixels i j clBlack Using the Pixels property instead of Scanline for setting the red and black dots in the graph using an in memory bitmap wasn t that slow in this program Once a few hundred thousand needles are tossed every pixel is covered and the graphical image doesn t change that much anyway The in memory BitmapTosses and BitmapGraph are assigned in ButtonTossClick to update the display UpdateDisplay ImageTosses Picture Graphic BitmapTosses ImageGraph Picture Graphic BitmapGraph The estimate for p is updated in the UpdatePIvalue method PROCEDURE TFormBuffon UpdatePiValue VAR PiApprox DOUBLE BEGIN LabelTosses Caption FormatFloat 0 TossCount Plural TossCount Toss Tosses FormatFloat 0 CrossCount Plural CrossCount Crossing IF CrossCount 0 can t divide by zero THEN BEGIN PiApprox 2 0 TossCount CrossCount LabelPIApproxValue Caption Format 6f PiApprox LabelPIApprox Visible TRUE END ELSE BEGIN LabelPIApproxValue Caption LabelPIApprox Visible FALSE END END Note the Plural string function that displays the correct words toss or tosses and crossing or crossings Methods of Creating Random Direction Vectors The TDirectionVectorRoutine type is defined in the ScreenBuffon unit so that a variety of methods can be explored to compute the random direction angle type TDirectionVectorRoutine PROCEDURE VAR x y SinTheta CosTheta Single The TFormBuffon class includes a private DirectionVectorRoutine variable private DirectionVectorRoutine TDirectionVectorRoutine As mentioned earlier the TFormBuffon FormCreate routine assigns the default DirectionMethodRoutine Setup default random direction generator DirectionVectorRoutine DirectionMethod2 RadioButtonMethod2 Checked TRUE This assignment of a DirectionVectorRoutine is a much more elegant way in Delphi than the syntax used with function pointers in C C To force consistency the RadioButtonMethod2 RadioButton is Checked when the DirectionVectorRoutine assignment is made The only other way to change the DirectionMethodRoutine is by directly clicking on a RadioButton on the Setup tab procedure TFormBuffon RadioButtonMethodClick Sender TObject begin CASE Sender AS TRadioButton Tag OF 1 DirectionVectorRoutine DirectionMethod1 2 DirectionVectorRoutine DirectionMethod2 3 DirectionVectorRoutine DirectionMethod3 4 DirectionVectorRoutine DirectionMethod4 ELSE do nothing should never happen END ResetState end Now that the assignment of the DirectionVectorRoutine has been discussed let s look at each of the Random Direction Generation Methods Remember that since we are trying to compute p that none of the algorithms can depend directly on p Method 1 Naive and Incorrect Approach This was my original naive and INCORRECT approach to create a random angle it s still educational to consider A random x y value is chosen in the rectangle ranging from 1 to 1 in the X direction and 0 to 1 in the Y direction The Sin and Cos of the angle q between the X axis and the line from 0 0 to x y were easily computed My original naive and INCORRECT APPROACH Assume PI can t be used anywhere since that s what we re calculating Avoid use of SIN and COS PROCEDURE DirectionMethod1 VAR x y SinTheta CosTheta Single VAR hypotenuse SINGLE BEGIN define direction vector x y to assign needle orientation x 2 0 Random 0 5 1 0 x 1 0 y Random 0 0 y 1 0

    Original URL path: http://www.efg2.com/Lab/Mathematics/Buffon.htm (2016-02-14)
    Open archived version from archive

  • efg's Mathematics Projects -- Complex Numbers and Functions
    functions are also explained including square integer power real power complex power and roots of complex values Complex Trig Functions How to compute several complex trigonometric functions including cosine sine tangent secant cosecant and cotangent Complex Hyperbolic Functions How to compute several complex hyperbolic functions including hyperbolic cosine hyperbolic sine hyperbolic tangent hyperbolic secant hyperbolic cosecant and hyperbolic cotangent Complex Bessel Functions How to compute the Bessel Functions J 0

    Original URL path: http://www.efg2.com/Lab/Mathematics/Complex/index.html (2016-02-14)
    Open archived version from archive

  • efg's Mathematics Projects -- CRC Calculator
    62DD1DDF 15DA2D49 8CD37CF3 FBD44C65 4DB26158 3AB551CE A3BC0074 D4BB30E2 4ADFA541 3DD895D7 A4D1C46D D3D6F4FB 4369E96A 346ED9FC AD678846 DA60B8D0 44042D73 33031DE5 AA0A4C5F DD0D7CC9 5005713C 270241AA BE0B1010 C90C2086 5768B525 206F85B3 B966D409 CE61E49F 5EDEF90E 29D9C998 B0D09822 C7D7A8B4 59B33D17 2EB40D81 B7BD5C3B C0BA6CAD EDB88320 9ABFB3B6 03B6E20C 74B1D29A EAD54739 9DD277AF 04DB2615 73DC1683 E3630B12 94643B84 0D6D6A3E 7A6A5AA8 E40ECF0B 9309FF9D 0A00AE27 7D079EB1 F00F9344 8708A3D2 1E01F268 6906C2FE F762575D 806567CB 196C3671 6E6B06E7 FED41B76 89D32BE0 10DA7A5A 67DD4ACC F9B9DF6F 8EBEEFF9 17B7BE43 60B08ED5 D6D6A3E8 A1D1937E 38D8C2C4 4FDFF252 D1BB67F1 A6BC5767 3FB506DD 48B2364B D80D2BDA AF0A1B4C 36034AF6 41047A60 DF60EFC3 A867DF55 316E8EEF 4669BE79 CB61B38C BC66831A 256FD2A0 5268E236 CC0C7795 BB0B4703 220216B9 5505262F C5BA3BBE B2BD0B28 2BB45A92 5CB36A04 C2D7FFA7 B5D0CF31 2CD99E8B 5BDEAE1D 9B64C2B0 EC63F226 756AA39C 026D930A 9C0906A9 EB0E363F 72076785 05005713 95BF4A82 E2B87A14 7BB12BAE 0CB61B38 92D28E9B E5D5BE0D 7CDCEFB7 0BDBDF21 86D3D2D4 F1D4E242 68DDB3F8 1FDA836E 81BE16CD F6B9265B 6FB077E1 18B74777 88085AE6 FF0F6A70 66063BCA 11010B5C 8F659EFF F862AE69 616BFFD3 166CCF45 A00AE278 D70DD2EE 4E048354 3903B3C2 A7672661 D06016F7 4969474D 3E6E77DB AED16A4A D9D65ADC 40DF0B66 37D83BF0 A9BCAE53 DEBB9EC5 47B2CF7F 30B5FFE9 BDBDF21C CABAC28A 53B39330 24B4A3A6 BAD03605 CDD70693 54DE5729 23D967BF B3667A2E C4614AB8 5D681B02 2A6F2B94 B40BBE37 C30C8EA1 5A05DF1B 2D02EF8D Given the above lookup table the code for computing a CRC 32 is as follows see initialization finalization below Use CalcCRC32 as a procedure so CRCValue can be passed in but also returned This allows multiple calls to CalcCRC32 for the same CRC 32 calculation PROCEDURE CalcCRC32 p pointer ByteCount DWORD VAR CRCValue DWORD The following is a little cryptic but executes very quickly The algorithm is as follows 1 exclusive or the input byte with the low order byte of the CRC register to get an INDEX 2 shift the CRC register eight bits to the right 3 exclusive or the CRC register with the contents of Table INDEX 4 repeat steps 1 through 3 for all bytes VAR i DWORD q BYTE BEGIN q p FOR i 0 TO ByteCount 1 DO BEGIN CRCvalue CRCvalue SHR 8 XOR Table q XOR CRCvalue AND 000000FF INC q END END CalcCRC32 You can pass nearly any argument to this routine since the first parameter is a pointer For a string pass the address of the first character for example CalcCRC32 Addr s 1 LENGTH s CRC32 To avoid an access violation in Delphi 4 or later make sure Length s 0 I m not sure why Delphi 3 didn t complain This routine can be used to verify the CRC32 table of constants has not been accidentally modified The following code in the CRC32 unit initialization checks the 1024 byte array of DWORDs VAR CRC32Table DWORD BEGIN Verify the table used to compute the CRCs has not been modified Thanks to Gary Williams for this suggestion Jan 2003 CRC32Table FFFFFFFF CalcCRC32 Addr table 0 SizeOf table CRC32Table CRC32Table NOT CRC32Table IF CRC32Table 6FCF9E13 THEN ShowMessage CRC32 Table CRC32 is IntToHex Crc32Table 8 expecting 6FCF9E13 END CRC32 To compute the same CRC 32 as used in the PKZIP utility start with a CRCvalue of FFFFFFFF After calling CalcCRC32 above any number of times the finalization consists of a 1 s complement of the CRCvalue This can be computed with the expression NOT CRCvalue in Delphi See additional details in the next section Initialization and Finalization The initialization and finalization of the CRC computation are arbitrary Many years ago when I first started computing CRCs I set the initial value to 0 and did no finalization this is Method 1 described above under Expected Values CRC16 0 IF LENGTH s 0 Avoid access violation in D4 THEN CalcCRC16 Addr s 1 LENGTH s CRC16 The standard CRC 32 the one used by PKZIP starts with FFFFFFFF as the initial value and then performs a 1 s complement to yield the final value this is Method 2 described above under Expected Values Here s what is done in the CRC Calculator for CRC 32s CRC32 FFFFFFFF To match PKZIP IF LENGTH s 0 Avoid access violation in D4 THEN CalcCRC32 Addr s 1 LENGTH s CRC32 CRC32 NOT CRC32 TO match PKZIP In the CRC16 computation the initial value is FFFF with Method 2 Thanks to Rolf Gebhardt and Glen Harman for pointing out an inconsistency about how finalization was handled in an earlier version of this article CRC of a File All the bytes of a file must be passed to the CalcCRC routines i e CalcCRC16 and CalcCRC32 to compute the CRC of a file The older BlockRead I O primitive is used in the CalcFileCRC16 routine in the CRC16 unit since BlockRead at one point was the only way to read a binary stream of bytes CalcFileCRC32 uses the more contemporary memory stream to read the bytes of a file when the StreamIO conditional compilation is defined Use MemoryStream to read file in binary mode PROCEDURE CalcFileCRC32 FromName STRING VAR CRCvalue DWORD VAR TotalBytes TInteger8 VAR error WORD VAR Stream TMemoryStream BEGIN error 0 CRCValue FFFFFFFF Stream TMemoryStream Create TRY TRY Stream LoadFromFile FromName IF Stream Size 0 THEN CalcCRC32 Stream Memory Stream Size CRCvalue EXCEPT ON E EReadError DO error 1 END CRCvalue NOT CRCvalue TotalBytes Stream Size FINALLY Stream Free END END CalcFileCRC32 The above procedure assumes that the file will easily fit into memory in a TMemoryStream Unfortunately this can be a bad assumption especially when some files are bigger than physical memory For example processing a 1 GB file in a memory stream with only 512 MB of physical memory might at minimum will tax the virtual memory processing of the operating system For now this isn t much of a problem See Ted Tøraasen s modification for CRC 16s for buffers 64 KB FileCheck Program See the FileCheck Lab Report for information about creating CRCs of files directories or even whole volumes Meta CRCs that is CRCs of CRCs of a well ordered list of files used to detect changes in directories or whole disk volumes Command Line Programs The command line examples CRC16Dem and CRC32Dem can be compiled from a DOS Window assuming your path contains the Delphi bin directory by entering DCC32 CRC16Dem PAS or DCC32 CRC32Dem PAS Study

    Original URL path: http://www.efg2.com/Lab/Mathematics/CRC.htm (2016-02-14)
    Open archived version from archive

  • efg's Mathematics Projects -- CRC FileCheck
    like the scan of the root directory of a volume except that the volume label and volume serial number are stored as part of the information about a volume A volume scan always implies that all subdirectories should be scanned The Subdirs Checkbox allows one to specify whether subdirectories should be scanned in a Directory scan If multiple instances of FileCheck are run be sure that unique File List and Verify files are specified If you blank either of the fields for these files the corresponding file is not created The BitBtnScanClick method is called for a click on any of the Scan buttons The Tag value of each button is used to determine whether the scan is for the volume in the TDriveCombobox the directory in the TDirectoryListBox or the file in the TFileListBox A further helper routine ScanDirectoryTarget is called for processing a volume of directory scan The BitBtnVerifyFileClick method is called for the verify operation Many of the variables used for scanning are replicated within this routine so that in theory a scan and a verify could run simultaneously without interfering with each other See the CRC Calculator Lab Report for how to compute the CRC 16 CRC 32 of a character string including source code for a CalcFileCRC32 procedure from the CRC32 PAS unit Two versions of CalcFileCRC32 are available The StreamIO conditional compilation variable allows to select I O using Streams or with the older BlockRead routine Since I have observed that BlockRead is still faster than Stream LoadFileFrom the default is setting is NoStreamIO Here are the two possible ways the CRC32 of a file is computed using the CalcCRC32 procedure CalcFileCRC32 using a TMemoryStream Compile with StreamIO set See CRC32 PAS for details The CRC 32 value calculated here matches the one from the PKZIP program Use MemoryStream to read file in binary mode PROCEDURE CalcFileCRC32 FromName STRING VAR CRCvalue DWORD VAR TotalBytes TInteger8 VAR error WORD VAR Stream TMemoryStream BEGIN error 0 CRCValue FFFFFFFF Stream TMemoryStream Create TRY TRY Stream LoadFromFile FromName IF Stream Size 0 THEN CalcCRC32 Stream Memory Stream Size CRCvalue EXCEPT ON E EReadError DO error 1 arbitrarily set this for now END CRCvalue NOT CRCvalue TotalBytes Stream Size FINALLY Stream Free END END CalcFileCRC32 An Error code 1 is return from this procedure when an EReadException is encountered since the Exception Message string did have any additional useful information See IOResult values below with BlockRead CalcFileCRC32 using BlockRead Compile with NoStreamIO set See CRC32 PAS for details The CRC 32 value calculated here matches the one from the PKZIP program Use BlockRead to read file in binary mode PROCEDURE CalcFileCRC32 FromName STRING VAR CRCvalue DWORD VAR TotalBytes TInteger8 VAR error WORD CONST BufferSize 32768 TYPE BufferIndex 0 BufferSize 1 TBuffer ARRAY BufferIndex OF BYTE pBuffer TBuffer VAR BytesRead INTEGER FromFile FILE IOBuffer pBuffer BEGIN New IOBuffer TRY FileMode 0 Turbo default is 2 for R W 0 is for R O CRCValue FFFFFFFF ASSIGN FromFile FromName I RESET

    Original URL path: http://www.efg2.com/Lab/Mathematics/FileCheck.htm (2016-02-14)
    Open archived version from archive

  • efg's Mathematics Page
    value of p by randomly throwing short line segments e g needles toothpicks pencils etc onto a plane of equally spaced parallel lines e g brick sidewalks hardwood floors certain tiles table cloth etc The number of segments crossing the parallel lines is related to the value p Count Buffon first experimented with this method in the 1700s pi Monte Carlo method Count Buffon Random Plural TBitmap TImage Pixels MoveTo LineTo FillRect TextOut TSimplePantograph ShellExecute Application ProcessMessages Cancel button FormatFloat ArcTan2 RGB MessageBeep MB ICONEXCLAMATION Procedure variable Half Angle Formula Rotation Matrix f z Complex numbers and functions Complex values can be represented in either rectangular or polar form with conversions taking place as necessary or on request complex numbers imagainary numbers rectangular form polar form TComplex Euler formula complex addition complex subtraction complex multiplication complex division conjugate complex natural logarithm complex exponential complex powers complex roots complex trig functions cosine sine tangent secant cosecant cotangent complex hyperbolic functions hyperbolic cosine hyperbolic sine hyperbolic tangent hyperbolic secant hyperbolic cosecant hyperbolic cotangent Complex Bessel Functions J0 I0 Complex Gamma Function CRC CRC Calculator CRC 16 and CRC 32 calculations CRC16Dem and CRC32Dem are examples of command line programs that work in

    Original URL path: http://www.efg2.com/Lab/Mathematics/index.html (2016-02-14)
    Open archived version from archive

  • efg's Fractals And Chaos -- Fractals Show 2 Lab Report
    the three Quick Settings selections or individually specify the x and y min and max number of pixels in each dimension the number of iterations the name and the function parameters Here is a summary of the various Groups that may be chosen Group Description Number of Parameter Sets Beauty of Fractals Mandelbrot Images from the book The Beauty of Fractals 14 Beauty of Fractals Julia 16 Mandelbrot Evolution Mandelbrot Sequence z z x c for x 34 MiniMandelbrot Bifurcation In the Mandelbrot Evolution near x 2 a MiniMandelbrot can be seen to bifurcate split 34 Mandelbrot UFO In the Mandelbrot Evolution near x 3 89 a UFO can be seen to fly briefly 19 efg s Mandelbrot Gallery A variety of fractal images originally displayed in efg s Fractal Discovery Lab Gallery 28 efg s Julia Gallery 34 Press the Start button where the Continue button is above Interrupt continue the computation any number of times This Integer image was an experiment to see if raw binary data might make sense without any special coloring Each pixel is an integer in the range 0 MaxIterationCount But each integer is treated as the color 00rrggbb so often the blue pixels show up since iteration limits are often in the range from 256 1024 A further experiment using pf15bit bitmaps where each pixel is a word might also be interesting This step was introduced so the counting of iterations was a distinctly separate process from coloring of iterations Often fractal programs combine both of these operations in one step However this makes re coloring of images difficult when more than one iteration value is mapped to the same color Click on any of the color boxes above to change the box color using the standard color dialog This provides for a wide variety of color gradient combinations Captured and Escape colors are established via the selections above The Color Shift spin box on the Final Image tab also affects the color mapping The Color Scheme for the Reverse Gradient with a Shift of 645 appears like this This is the color scheme used for the Final Image tab shown below The Rainbow color scheme looks like this Computation of the rainbow colors are explained in more detail in the Spectra Lab Report Either the Gradient or the Rainbow can be broken in to a specified number of intervals by checking the Color Bands box For example specifying 5 steps yields the following color gradient Checking the Rotate box rotates the above colors A wide variety of color schemes is possible The following shows the biomorph Final Image using the reverse gradient with a shift of 645 Cliff Pickover put a similar image in his book Mazes for the Mind Computers and the Unexpected St Martin s Press 1992 Color plate before page 173 Press the Save button to store the image in a pf24bit BMP or a JPG Press the Color Shift spin box to gradually rotate gradient or rainbow colors

    Original URL path: http://www.efg2.com/Lab/FractalsAndChaos/FractalsShow2.htm (2016-02-14)
    Open archived version from archive



  •