Make a picture with a transparent hole in it in C#

[transparent hole]

The example Create oval images in C# shows how to make a transparent image with an oval-shaped picture in it. This example shows how to do the converse: it makes an image with a transparent hole in the middle of it.

There are several approaches that you might take. You might like to simply draw an ellipse filled with the color Color.Transparent on top of a picture. Unfortunately, when you use the color Color.Transparent, that tells the drawing system to not do anything. If you fill an ellipse with that color, then it simply isn’t drawn.

A second approach would be to use the Bitmap class’s MakeTransparent method to convert some other color into Color.Transparent. For example, you could fill an ellipse in the middle of the form with the color that has RGB components (0, 0, 1), which is practically black, and then use MakeTransparent to convert those pixels into Color.Transparent. Unfortunately, you would need to be sure that the image didn’t already contain any pixels with the color (0, 0, 1). If it did, then those pixels would come out transparent, too. You can work around that problem by first examining the original image’s pixels and converting any such pixels to black, which would be indistinguishable.

The approach that this post takes for making a transparent hole is to make a region representing all of the parts of the image except the hole. It then uses the region to fill a bitmap with the image, cropped to only act on the region.

The example Create oval images in C# explains the basic user interface: how the program handles mouse events and so forth. See that example for those details.

The big difference between that example and this one is the CutOutOval method that makes the image with the transparent hole. The following code shows that method.

private Bitmap CutOutOval(Point start_point, Point end_point)
{
    // Make a region covering the whole picture.
    Rectangle full_rect = new Rectangle(
        0, 0, OriginalImage.Width, OriginalImage.Height);
    Region region = new Region(full_rect);

    // Remove the ellipse from the region.
    Rectangle ellipse_rect =
        SelectedRect(start_point, end_point);
    GraphicsPath path = new GraphicsPath();
    path.AddEllipse(ellipse_rect);
    region.Exclude(path);

    // Draw.
    Bitmap bm = new Bitmap(OriginalImage);
    using (Graphics gr = Graphics.FromImage(bm))
    {
        gr.Clear(Color.Transparent);

        // Fill the region.
        gr.SetClip(region, CombineMode.Replace);
        gr.SmoothingMode = SmoothingMode.AntiAlias;
        using (TextureBrush brush =
            new TextureBrush(OriginalImage, full_rect))
        {
            gr.FillRectangle(brush, full_rect);
        }
    }
    return bm;
}

The code first makes a Rectangle that covers the image’s entire area. It uses the Rectangle to make a new Region object.

Next, the code creates a second Rectangle to represent the area where the transparent hole should go. It creates a GraphicsPath object and adds the ellipse to it. The code then uses the Region object’s Exclude method to exclude the ellipse from the Region.

At this point, the method starts drawing. It creates a new Bitmap that is a copy of the original image, and then makes an associated Graphics object. It clears the new Bitmap with the color Color.Transparent.

The code then calls the Graphics object’s SetClip method to set its clipping rectangle to the region. After this point, the Graphics object will only modify pixels that lie within the region.

The rest is relatively straightforward. The program uses the original image to make a brush and then uses the brush to fill the entire Bitmap. The elliptical area that was excluded from the region is not drawn, resulting in a transparent hole.

After it creates the image, the program draws a checkerboard and draws the image on top of it to show the transparent hole.

Download the example to see additional details.


Download Example   Follow me on Twitter   RSS feed   Donate




Posted in drawing, graphics, image processing | Tagged , , , , , , , , , | Leave a comment

Let the user zoom on a picture and draw in C#

[zoom]

The example Let the user zoom on a picture in C# allows the user to zoom in on a picture and draw on it. Unfortunately, it doesn’t handle the drawing properly when the image is scaled. It doesn’t scale the mouse’s position properly when the image is scaled.

This example corrects that. The idea is to create a Matrix object that represents the inverse of the scaling transformation. Then when the user draws, the program uses the transformation to convert the mouse’s position into the scaled drawing coordinate system so the points can be saved appropriately.

The following code shows how the program declares its transformation matrix.

// Inverse transform to convert mouse coordinates.
private Matrix InverseTransform = new Matrix();

The Matrix class is defined in the System.Drawing.Drawing2D namespace, so the program includes a using System.Drawing.Drawing2D directive to make using the class easier.

When you select a scale, the program calls the following method to prepare to use the new scale. The new code is highlighted in blue.

// Set the scale and redraw.
private void SetScale(float picture_scale)
{
    // Set the scale.
    PictureScale = picture_scale;

    // Resize the PictureBox.
    picCanvas.ClientSize = new Size(
        (int)(WorldWidth * PictureScale),
        (int)(WorldHeight * PictureScale));

    // Prepare the inverse transformation for points.
    InverseTransform = new Matrix();
    InverseTransform.Scale(1.0f / picture_scale, 1.0f / picture_scale);

    // Redraw.
    picCanvas.Refresh();
}

The highlighted code sets InverseTransform to a new Matrix object. It then calls the object’s Scale method to make the matrix represent scaling by the inverse of the current scale factor.

For example, suppose the scale factor is 2. Then the inverse scale factor is 1/2. When the user moves the mouse across the scaled image, the logical location of the mouse in drawing coordinates is twice what it is on the screen because the image is enlarged. When you move the mouse 10 pixels across the screen, you are moving across 20 pixels worth of drawing.

The following code shows the only other pieces of the program that use the inverse transform matrix. Again the changes are highlighted in blue.

// Start drawing.
private void picCanvas_MouseDown(object sender, MouseEventArgs e)
{
    // Create the new polyline.
    NewPolyline = new Polyline();
    Polylines.Add(NewPolyline);

    // Initialize it and add the first point.
    NewPolyline.Color = DrawingColor;
    NewPolyline.Thickness = DrawingThickness;
    NewPolyline.DashStyle = DrawingDashStyle;

    // Transform the point for the current scale.
    Point[] points = { e.Location };
    InverseTransform.TransformPoints(points);
    NewPolyline.Points.Add(points[0]);
}

// Continue drawing.
private void picCanvas_MouseMove(object sender, MouseEventArgs e)
{
    if (NewPolyline == null) return;

    // Transform the point for the current scale.
    Point[] points = { e.Location };
    InverseTransform.TransformPoints(points);
    NewPolyline.Points.Add(points[0]);

    picCanvas.Refresh();
}

The code is similar to the previous version, except this time the program scales the mouse’s position before adding it to the NewPolyline object’s points. To scale the point’s coordinates, the code copies the point into an array and then calls the InverseTransform object’s TransformPoints method to apply the transformation to the array.

The rest of the program is the same as before. Now that the new point is scaled to match the image’s scale factor, the original drawing methods still work.

Download the example to see additional details.


Download Example   Follow me on Twitter   RSS feed   Donate




Posted in drawing, files, graphics, serialization, transformations | Tagged , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , | 1 Comment

List strings with a particular style in a Microsoft Word document in C#

[style]

I’m writing a new book and the development editor wants me to make a list of key terms that I specifically want included in the index. I want to include all of the words marked with the style KeyTerm, so I wrote this program to find them.

The program requires a reference to the Word object library. To add the reference in Visual Studio 2008, open Solution Explorer, right-click the References entry, and select Add Reference. Then go to the COM tab and double-click Microsoft Word 14.0 Object Library.

The program’s code uses the following using directive to make using the object library easy.

using Word = Microsoft.Office.Interop.Word;

The following method searches a Word document for words that have a particular style.

// Find words with the given style in the Word file.
private List<string> FindWordsWithStyle(string file_name,
    string word_style)
{
    // Get the Word application object.
    Word._Application word_app = new Word.ApplicationClass();

    // Make Word visible (optional).
    word_app.Visible = false;

    // Open the file.
    object filename = file_name;
    object confirm_conversions = false;
    object read_only = true;
    object add_to_recent_files = false;
    object format = 0;
    object missing = System.Reflection.Missing.Value;

    Word._Document word_doc =
        word_app.Documents.Open(ref filename, ref confirm_conversions,
            ref read_only, ref add_to_recent_files,
            ref missing, ref missing, ref missing, ref missing,
            ref missing, ref format, ref missing, ref missing,
            ref missing, ref missing, ref missing, ref missing);

    // Search.
    List<string> result = new List<string>();
    object style = word_style;
    word_app.Selection.Find.ClearFormatting();
    word_app.Selection.Find.set_Style(ref style);
    object obj_true = true;
    for (;;)
    {
        word_app.Selection.Find.Execute(ref missing,
            ref missing, ref missing, ref missing, ref missing,
            ref missing, ref missing, ref missing, ref obj_true,
            ref missing, ref missing, ref missing, ref missing,
            ref missing, ref missing);
        if (!word_app.Selection.Find.Found) break;
        result.Add(word_app.Selection.Text);
    }

    // Close the document without prompting.
    object save_changes = false;
    word_doc.Close(ref save_changes, ref missing, ref missing);
    word_app.Quit(ref save_changes, ref missing, ref missing);

    // Return the result.
    return result;
}

The method takes as parameters the name of the file to search and the name of the style to locate. The method starts with the usual tasks required to work with Word documents. It creates a Word application object. It then makes some objects holding values that it will use because Word interop generally only works with objects passed by reference. The method then opens the Word document.

Next, the method performs the search. To do that, it uses the Selection object. It first clears the object’s formatting and uses its set_Style method to set the object’s style to the value in the style parameter. It then enters an infinite loop.

Inside the loop, the code calls the Selection object’s Find.Execute method. The only parameter that is not omitted in that method call is the Format property, which indicates whether the method should take into account any formatting specified for the Selection object. This example srets that property to true to make the search look for text that has the desired style.

After calling Find.Execute, the code checks the Selection object’s Find.Found property to see if it found a piece of text with the desired style. If Find.Found is not true, the code breaks out of its loop.

If Find.Found is true, the code adds the text that it found to its result list and continues its loop.

Each time the code calls Find.Execute, that method searches for the next piece of text that matches the style.

After the code breaks out of its loop, it closes the Word document and returns the strings that it found.

Download the example to see additional details such as how the program lets the user browse for the Word document ad how it displays the result.


Download Example   Follow me on Twitter   RSS feed   Donate




Posted in books, interoperability, Office, Word | Tagged , , , , , , , , , , , | Leave a comment

Segmented Turning Helper, Version 3

[turning]

John Di Stefano has released version 3 of this free tool Segmented Turning Helper. The program helps you design segmented turning projects such as turned bowls and vases. Here’s the basic description of the tool.

Segmented Turning Helper assists you in creating your segmented turning projects by calculating the segment length of each ring in your project.

The software is easy to use. Input the number of segments, thickness and width of the segment for each ring from your plan drawing and then click the calculate button to calculate the segment length for each ring. A clear, easy to read printout is provided giving segment lengths and a timber stock list.

The software is free and should be used for private use only.
Simply download it to your computer, install it and use it.
Win 10, 8, 7

[WPF 3d]

The new version uses a camera class from my book WPF 3d to provide realiztic 3D rendering. It even uses wood grain textures to make the result look more realistic.

I’m glad you found my book useful, John!


Download Example   Follow me on Twitter   RSS feed   Donate




Posted in 3D, 3D graphics, books, drawing, graphics, wpf | Tagged , , , , , , , , , , , , | Leave a comment

Make a Word document with multiple pages in C#

[Word document]

The example Create a Word document in C# shows how to create a Word document and save it into a file. See that example for the basics including how to create the document, add paragraphs to it, and save it into a file.

This example shows how to make a multi-page Word document. The following snippet shows the key pieces of code.

// Page 1.
// Create a header paragraph.
Word.Paragraph para = word_doc.Paragraphs.Add(ref missing);
para.Range.Text = "First Page";
object heading1_name = "Heading 1";
para.Range.set_Style(ref heading1_name);
para.Range.InsertParagraphAfter();

// Add more text.
para.Range.Text = "Here is some text for the first page.";
para.Range.InsertParagraphAfter();

// Add a page break.
object break_type = Word.WdBreakType.wdPageBreak;
para.Range.InsertBreak(ref break_type);

// Page 2.
// Create a header paragraph.
para = word_doc.Paragraphs.Add(ref missing);
para.Range.Text = "Second Page";
para.Range.set_Style(ref heading1_name);
para.Range.InsertParagraphAfter();

// Add more text.
para.Range.Text = "Here is some text for the second page.";
para.Range.InsertParagraphAfter();

After creating the Word document (not shown), the program creates a Paragraph object. It sets the paragraph’s text to “First Page” and sets its style to “Heading 1.” It then calls the InsertParagraphAfter method to insert a paragraph break after the text. That advances the Paragraph object so it points to the spot after its initial position. In other words, it moves the paragraph after the first line of text and the paragraph break.

Next the code sets the object’s text to some more text.

If you wanted to add more text to the first page, you would repeat these steps:

  • Set the Paragraph object’s text.
  • Optionally set the paragraph’s style.
  • Call InsertParagraphAfter to add a paragraph break.

After finishing the first page, the code calls the InsertBreak method to add a page break. It then repeats the earlier steps to create a second page.

See the earlier example and download this example to see additional details about how to create and save the Word document.


Download Example   Follow me on Twitter   RSS feed   Donate




Posted in interoperability, Office, Word | Tagged , , , , , , , , , , , , | Leave a comment

Solve Geometric Problems with C#

[This is a promo piece by Packt, the publisher of my book The Modern C# Challenge. It includes two of the 100 example problems and solutions in the book.]

Solve Geometric Problems with C#

[Solve Geometric Problems with C#]

Learn how to solve C# geometric problems in this article by Rod Stephens, a software developer, consultant, instructor, and author. Rod’s popular C# Helper and VB Helper websites receive millions of hits per year and contain thousands of tips, tricks, and example programs for C# and Visual Basic developers.
Do you wish to test your geometric programming skills?

If your answer is yes, this is the article for you. [This article was taken from Rod’s book The Modern C# Challenge. Some of its chapters] ask you to calculate values such as π or the area below a curve. Others demonstrate useful techniques such as Monte Carlo algorithms. This article will look at two of the prominent geometric programming skills, the Monte Carlo π and Newton’s π. You can also download the example solutions to see additional details and to experiment with the programs at https://github.com/PacktPublishing/The-Modern-CSharp-Challenge/tree/master/Chapter02.

So, let’s get started!

1. Monte Carlo π

A Monte Carlo algorithm uses randomness to approximate the solution to a problem. Often, using more random samples gives you a more accurate approximated solution or gives a greater probability that the solution is correct.

For this problem, use a Monte Carlo algorithm to approximate π. To do this, generate random points in the square (0 ≤ X, Y ≤ 1) and then see how many fall within a circle centered in that square.

Solution:

The following code uses a Monte Carlo algorithm to estimate π:

// Use Monte Carlo simulation to estimate pi.
private double MonteCarloPi(long numPoints)
{
    Random rand = new Random();

    // Make a bitmap to show points.
    int wid = pointsPictureBox.ClientSize.Width;
    int hgt = pointsPictureBox.ClientSize.Height;
    Bitmap bm = new Bitmap(wid, hgt);
    using (Graphics gr = Graphics.FromImage(bm))
    {
        gr.Clear(Color.White);
        gr.DrawEllipse(Pens.Black, 0, 0, wid - 1, hgt - 1);
    }

    // Make the random points.
    int numHits = 0;
    for (int i = 0; i < numPoints; i++)
    {
        // Make a random point 0 <= x < 1.
        double x = rand.NextDouble();
        double y = rand.NextDouble();

        // See how far the point is from (0.5, 0.5).
        double dx = x - 0.5;
        double dy = y - 0.5;
        if (dx * dx + dy * dy < 0.25) numHits++;

        // Plots up to 10,000 points.
        if (i < 10000)
        {
            int ix = (int)(wid * x);
            int iy = (int)(hgt * y);
            if (dx * dx + dy * dy < 0.25)
                bm.SetPixel(ix, iy, Color.Gray);
            else
                bm.SetPixel(ix, iy, Color.Black);
        }
    }

    // Display the plotted points.
    pointsPictureBox.Image = bm;

 
    // Get the hit fraction.
    double fraction = numHits / (double)numPoints;

    // Estimate pi.
    return 4.0 * fraction;
}

The method starts by creating a Random object that it can use to generate random numbers. It then creates a bitmap to fit the program’s PictureBox, associates a Graphics object with it, clears the bitmap, and draws a circle centered in the bitmap.

Next, the code uses a loop to generate the desired number of random points within the square 0 ≤ X, Y < 1. The NextDouble method of the Random class returns a value between 0 and 1, so generating the point’s X and Y coordinates is relatively easy.

The code then determines whether the point lies within the circle that fills the square 0 ≤ X, Y ≤ 1. To do this, the method calculates the distance from the random point to the center of the circle (0.5, 0.5). It then determines whether that distance is less than the circle’s radius.

Actually, the code doesn’t really find the distance between the point and (0.5, 0.5). To do this, it would use the distance formula to find the distance and then use the following equation to determine whether the result is less than the circle’s radius 0.5:

Calculating square roots is relatively slow, however, so the program squares both sides of the equation and uses the following equation instead:

The value 0.5 squared is 0.25, so the program actually tests whether:

The program then plots the point on the bitmap in either gray or black, depending on whether the point lies within the circle. The code also uses the numHits variable to keep track of the number of points that lie within the circle.

After it finishes generating points, the code makes its approximation for π. The square 0 ≤ X, Y ≤ 1 has an area of 1.0 and the circle should have the area π × R2 where R is the circle’s radius. In this example, R is 0.5, so the fraction of points that fall inside the circle should be the following:

If you solve this equation for π, you get the following:

The code gets the fraction of the points that fell within the circle, multiples that by 4.0, and returns the result as its estimate for π.

The following screenshot shows the MonteCarloPi example solution approximating π. After generating 10,000 random points, its approximation for π is off by around 1%. Using more points produces better approximations for π. The result with one million points is correct within about 0.1–0.2%, and the result with 100 million points is correct to within around 0.01%:

2. Newton’s π

Various mathematicians have developed many different ways to approximate π over the years. Sir Isaac Newton devised the following formula to calculate π:

Use Newton’s method to approximate π. Let the user enter the number of terms to calculate. Display the approximation and its error. How does this value compare to the fraction 355/113? Do you need to use checked blocks to protect the code?

Solution:

The following code implements Newton’s method for calculating π:

// Use Newton's formula to calculate pi.
private double NewtonPi(int numTerms)
{
    double total = 0;
    for (int i = 0; i < numTerms; i++)
    {
        total +=
            Factorial(2 * i) /
            Math.Pow(2, 4 * i + 1) /
            (Factorial(i) * Factorial(i)) /
            (2 * i + 1);
    }

    double result = 6 * total;
    Debug.Assert(!double.IsInfinity(result));
    return result;
}

This method simply loops over the desired number of terms, calculates the appropriate term values, and adds them to the result. To allow the program to work with larger values, it uses the following Factorial method:

// Return number!
private double Factorial(int number)
{
    double total = 1;
    for (int i = 2; i <= number; i++) total *= i;
    return total;
}

This is a normal factorial, except it stores its total in a double variable, which can hold larger values than a long variable can.

The value 355/113 is approximately 3.1415929, which is remarkably close to π. Newton’s method converges very quickly on values close to π, only needing nine terms before it is more accurate than 355/113.

This method runs into problems when numTerms is greater than 86. In that case, the value Factorial(2 * i) is too big to fit in a double variable. Because the problem occurs in a double variable instead of an integer, a checked block won’t detect the problem.

As is the case with integers, C# doesn’t notify you if the value doesn’t fit in a double variable. Instead, it sets the variable equal to one of the special values double.Infinity or double.NegativeInfinity. The NewtonPi method uses a Debug.Assert statement to see if this happened.

The lesson to be learned here is that you should use the double.IsInfinity method to check double variables for overflow to infinity or negative infinity if that might be an issue.

Some double calculations, such as total = Math.Sqrt(-1), may result in the special value double.NaN, which stands for Not a Number. You can use the double.IsNaN method to check for that situation.

If you found this article interesting, you can explore The Modern C# Challenge to learn advanced C# concepts and techniques such as building caches, cryptography, and parallel programming by solving interesting programming challenges. The Modern C# Challenge helps you to walk through challenges in C# and explore the .NET Framework in order to develop program logic for real-world applications.

Posted in books, geometry, mathematics | Tagged , , , , , , , , , , | Leave a comment

Pingback: Code Project post “Orbital Mechanics Introduction, Part 2”


[WPF 3d]

The Code Project post Orbital Mechanics Introduction, Part 2 by charles922 uses some code from my WPF 3D posts. His program lets you experiment with the following orbital parameters:

[WPF 3D]

  • Eccentricity – the eccentricity of the orbit’s ellipse.
  • Inclination – the vertical tilt of the ellipse with respect to the orbital plane measured at the ascending node (where the orbit passes upward through the orbital plane).
  • Semi-major Axis – the semi-major axis of the orbit’s ellipse.
  • Longitude of the Ascending Node (Omega, ?) – horizontally orients the ascending node of the ellipse.
  • Argument or Periapsis – defines the orientation of the ellipse in the orbital plane, as an angle measured from the ascending node to the periapsis.

To see Charles’ post, click here.

For LOTS more information on three-dimensional graphics in WPF, see my book WPF 3d,
Three-Dimensional Graphics with WPF and C#
.



Follow me on Twitter   RSS feed   Donate




Posted in 3D, 3D graphics, algorithms, books, drawing, graphics, mathematics, wpf, XAML | Tagged , , , , , , , , , , , , , , | Leave a comment

Quick notes on the recent Windows update


[Windows update]

Recently my computer decided that it needed to perform a bit Windows update. I can usually tell when that’s about to happen because performance is terrible for no obvious reason.

BTW, if you wonder whether an update is impacting performance, open the Start menu and click the Settings tool. Enter “updates” in the search box. Click on the “Check for updates” entry and then click the “Check for updates” button. If an update is pending, that should show its status. For example, if might say that your system is up to date, an update is downloading, an update is pending, or an update is ready to install.

Anyway, the update went pretty smoothly, but it took a really long time–more than four hours. During much of that time, the system was usable but so slow that it wasn’t worth the frustration. Also note that the progress seemed to get stuck a few times. It was still making progress and I could hear the disk working hard, but it showed 85% complete for a long time.

I recommend that you check for updates. If you see that they are available, start the update after you have finished work for the day and let it run overnight. Make sure it’s running correctly and then go watch reruns or something.


Follow me on Twitter   RSS feed   Donate




Posted in system | Tagged , , , , , , , | Leave a comment

Winners of the book drawing

[The Modern C# Challenge]

Congratulations to the following winners of the book drawing for copies of The Modern C# Challenge.

  • Josh Williams
  • Tony Ropson
  • Richard Moss
  • Mark Williamson
  • William Cruz
  • Stephen
  • Igor Kuzmishov
  • Paolo
  • Mike Griffiths
  • Francisco Javier López Manzano

If you didn’t win, don’t despair! I’ll have other drawings, possibly soon!


Follow me on Twitter   RSS feed   Donate




Posted in algorithms, books | Tagged , , , , , , , , | Leave a comment

Why you should study algorithms (plus a free book drawing)

[Essential Algorithms]

There are several reasons why you should study algorithms. I’m going to talk about four of them. (If you want to skip to the bottom, you can read about the drawing I’m having in the next few days for one of these books.)

First, it teaches you how to build specific algorithms. For example, pretty much any introductory algorithms book explains certain basic algorithms, one of which is quicksort. Quicksort is a good, general-purpose sorting algorithm that’s usually quite fast. After you learn how it works, you can use it in your programs.

But wait! Don’t many programming languages include sorting utilities? Yes they do. In fact, many of them use quicksort, at least under some circumstances. The reason they don’t use quicksort all of the time is that other algorithms are sometimes faster. For example, the countingsort can be much faster if the values being sorted are integers that span a relatively small range. For example, countingsort would work quite well if you need to sort 1 million integer values between 1 and 10,000. For another example, bubblesort is very fast for sorting small lists. For example, it is often faster than quicksort or countingsort if you only need to sort 5 items.

That brings me to the second reason why you should study algorithms: so you know which algorithm to use under different circumstances. Studying algorithms lets you know what kinds of algorithms are possible and which might be best suited for a particular problem. The .NET Framework includes sorting tools, but you may be able to sort much more quickly if you have special information about the data that you are sorting. A good background in algorithms will let you know what other kinds of algorithms are out there for building trees, searching databases, finding paths through networks, solving optimization problems, fitting curves to points, and many other useful tasks.

The third reason for studying algorithms, and the one that is probably the most important, it that it gives your brain a workout. Professional football players spend plenty of time in the gym even though they will rarely need to perform bench presses during a game. Similarly, working with a variety of algorithms exercises your brain. It teaches you new techniques for solving problems. It also teaches you problem-solving approaches that you may help you find solutions to completely unrelated problems. It’s practice for solving the problems that you will actually face on the mean streets of programming.

(This is also the main reason why you learn algebra in school. It’s not that your teachers think everyone will use algebra or calculus in their daily lives. They’re trying to make youi smarter.)

The final reason for studying algorithms (at least the final reason that I’m going to talk about now) is that they’re fun! Figuring out how to implement a tricky algorithm is sort of like solving a jigsaw or Sudoku puzzle. It’s a great feeling when all of the pieces fit together to give you something whole. Unlike Sudoko, however, when you’re done implementing an algorithm, you have something useful. It’s also an amazing feeling to dump a bunch of data into a 3D graphics program and have a colorful fractal or photo-realistic picture pop out!

Over the years I have written many books that are largely workouts for your brain. Those include algorithms books, 2- and 3-dimensional graphics books, miscellaneous interesting topics books, and even a book about interview puzzles. (Even my database design book will probably make you think.) Here are my latest titles that fit this category.

[The Modern C# Challenge]

The Modern C# Challenge, Become an expert C# programmer by solving interesting programming problems

This book includes 100 problems (with solutions) that you can use to test and hone your C# programming skills. They cover an eclectic assortment of topics, such as mathematical calculations, geometry, dates and times, the filesystem, simulations, and cryptography. These problems won’t make you an expert in those fields, but they will give you some experience with a wide variety of useful topics.


[WPF 3d]

WPF 3d, Three-Dimensional Graphics with WPF and C#

This easy-to-read guide provides everything you need to know to get started writing striking 3D graphics programs with WPF and C#. The book’s three parts describe 3D basics, building many different shapes, and advanced topics. More than 100 example programs covering such topics as:

  • The lights, cameras, materials, texture coordinates, and other details that you need to create a 3D scene
  • Orthographic, perspective, and other projections that emphasize different aspects of a scene
  • Special material treatments such as specular reflection, wireframes, and solid and translucent materials
  • Examples of many shapes including flat polygons, boxes, Platonic solids, spheres, tori, cones, and more
  • Advanced objects such as parametric surfaces, surfaces of transformation, fractal surfaces, and 2D and 3D text
  • Higher-level scene management to let users select and move objects
  • Advanced techniques such as loading models created in other applications and using skeletons

    [Interview Puzzles Dissected]

    Interview Puzzles Dissected, Solving and Understanding Interview Puzzles

    Job Candidates, Interviewers, and Puzzle Enthusiasts

    Whether you’re applying for a programming job or a position on Wall Street, interview puzzles are the norm at many high-tech companies. This book explains how to solve more than 200 of the hardest and most common interview puzzles in use. Interview Puzzles Dissected:

    • Shows how to solve more than 200 challenging interview puzzles
    • Reveals underlying techniques that let you solve problems that you haven’t seen before
    • Tells how you can show the interviewer that you can think in an organized fashion
    • Explains how to get “partial credit” when all else fails and you just can’t solve a puzzle
    • Includes programming challenges to give you a deeper understanding of puzzles (obviously only if you’re a programmer)

    [Essential Algorithms]


    Essential Algorithms, A Practical Approach to Computer Algorithms

    A friendly and accessible introduction to the most useful algorithms.

    Computer algorithms are the basic recipes for programming. Professional programmers need to know how to use algorithms to solve difficult programming problems. Written in simple, intuitive English, this book describes how and when to use the most practical classic algorithms, and even how to create new algorithms to meet future needs. The book also includes a collection of questions that can help readers prepare for a programming job interview.


    Drawing

    I’m holding a drawing to give away 10 free copies of my book The Modern C# Challenge. To enter, simply send your name and email address to me at RodStephens@CSharpHelper.com. Use the subject line “The Modern C# Challenge book drawing” so I know what your email is about. All I ask in return is that you post a review. The deadline is January 18, 2019, so act now!

    For a little more information, look at this post.


    Follow me on Twitter   RSS feed   Donate




Posted in 3D graphics, algorithms, books, graphics | Tagged , , , , , , , , , | Leave a comment