This is a followup to a previous post about polynomial fitting using boost. This post implements the polynomial fitting using QR decomposition. Included is also a simple Matrix class.

… Read more

## Polynomial Fitting in C++ using Boost

A while back I needed to implement an algorithm utilizing an equivalent function of polyfit/polyval in LabView. The original algorithm was created in LabView for research purposes and since we were in the process of creating a commercial version of the device, the algorithm implementation in C++ needed to mirror the LabView implementation. I found that there is no simple and neat implementation of polyfit() polyval() in C++ so through a bit of digging, research, and implementation I came up with my own functions.

Polynomial fitting function returns coefficients of a polynomial representing a given data. MathWorks has a decent explanation of the function. Below is a graph showing 1000 randomly varying points and the polynomial curve in red generated from the given points.

… Read more

## PictureBox Control Zoom

Recently I needed to implement zooming functionality using the mouse wheel in PictureBox control in C#.

My initial reflex was to reuse existing free code, but I kept on running into controls that were either too bulky or badly implemented. In the end I implemented a relatively simple class which can be used with the standard C# PictureBox.

One of the nicer functionalities of this implementation is that the point being scrolled under the cursor will stay in place during zooming in/out.

The heart of this class is the following function:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
/// <summary> /// Zoom/unzoom the control by a given factor. /// Factor is applied to the image size. /// </summary> /// <param name="zoom">zoom factor between 0.1 and 8.0</param> /// <param name="pos">position under the cursor which is to be /// retained</param> private void Zoom(float zoom, PointF pos) { // make sure an image is set if (_pictureBox.Image != null) { float oldZoom = _zoom; SizeF imageSize = _pictureBox.Image.Size; PointF scrollPosition = _scrollPanel.AutoScrollPosition; PointF cursorOffset = new PointF(pos.X + scrollPosition.X, pos.Y + scrollPosition.Y); _zoom = Math.Max(0.1f, Math.Min(8.0f, zoom)); // disable the redraw to prevent flicker SetRedraw(_scrollPanel, false); // scale the zoom box _pictureBox.Width = (int)Math.Round(imageSize.Width * _zoom); _pictureBox.Height = (int)Math.Round(imageSize.Height * _zoom); // calculate the new scroll position _scrollPanel.AutoScrollPosition = new Point( (int)Math.Round(_zoom * pos.X / oldZoom) - (int)cursorOffset.X, (int)Math.Round(_zoom * pos.Y / oldZoom) - (int)cursorOffset.Y); _scrollPanel.PerformLayout(); // reenable the redraw SetRedraw(_scrollPanel, true); _scrollPanel.Refresh(); } } |

## Manipulating CSV Spreadsheet Data – Java

Often times where I have been required to deal with the data stored in a humanly readable format. I have found that the easiest and the most portable way to deal with this data is via CSV files. This way the data can be reviewed or generated using OpenOffice Calc or Excel.

The code I am posting here does not deal with all eventualities of CSV but is a solid base to include into your own projects and expand as you see fit. As a side note I have posted this code on one of my favourite coding sites full of nerdy goodnessÂ http://rosettacode.org.

… Read more

## Manipulating CSV Spreadsheet Data – C#

Often times where I have been required to deal with the data stored in a humanly readable format. I have found that the easiest and the most portable way to deal with this data is via CSV files. This way the data can be reviewed or generated using OpenOffice Calc or Excel.

The code I am posting here does not deal with all eventualities of CSV but is a solid base to include into your own projects and expand as you see fit. As a side note I have posted this code on one of my favourite coding sites full of nerdy goodnessÂ http://rosettacode.org.

… Read more

## Manipulating CSV Spreadsheet Data – C++

Often times where I have been required to deal with the data stored in a humanly readable format. I have found that the easiest and the most portable way to deal with this data is via CSV files. This way the data can be reviewed or generated using OpenOffice Calc or Excel.

The code I am posting here does not deal with all eventualities of CSV but is a solid base to include into your own projects and expand as you see fit. As a side note I have posted this code on one of my favourite coding sites full of nerdy goodnessÂ http://rosettacode.org.

… Read more