15,907,910 members
Home / Discussions / C / C++ / MFC

C / C++ / MFC

 Re: Linux C++ implementation of ioctl leon de boer26-Mar-18 16:53 leon de boer 26-Mar-18 16:53
 Re: Linux C++ implementation of ioctl Vaclav_4-Apr-18 5:08 Vaclav_ 4-Apr-18 5:08
 VS2017: Cannot debug Dll's indrekm23-Mar-18 1:13 indrekm 23-Mar-18 1:13
 Re: VS2017: Cannot debug Dll's Richard MacCutchan23-Mar-18 1:21 Richard MacCutchan 23-Mar-18 1:21
 Re: VS2017: Cannot debug Dll's Jochen Arndt23-Mar-18 1:25 Jochen Arndt 23-Mar-18 1:25
 Re: VS2017: Cannot debug Dll's `Randor` 23-Mar-18 8:09 `Randor` 23-Mar-18 8:09
 Select and Pick lines in OpenGL Gopi Nath22-Mar-18 19:40 Gopi Nath 22-Mar-18 19:40
 Re: Select and Pick lines in OpenGL leon de boer22-Mar-18 20:30 leon de boer 22-Mar-18 20:30
 Find the line in your list that is closest the point or at least less than some tolerance value A number of Contributed implementations of the formula here plus an explaination of the mathematics Point, Line, Plane[^] Implementation would look something like this ```#define GLfloat float // No sure if you want floats or double you can change here /* Calculate euclidian distance between vertex points (x1,y1) and (x2,y2) */ GLfloat GLDistance2D (GLfloat x1, GLfloat y1, // Vertex 1 (x1,y1) GLfloat x2, GLfloat y2) // Vertex 2 (x2,y2) { GLfloat dx, dy; dx = x2 - x1; // Diff x dy = y2 - y1; // Diff y if ( dx < -FLT_EPSILON || dx > FLT_EPSILON || dy < -FLT_EPSILON || dy > FLT_EPSILON ) // Check dx, dy or both are non zero { return sqrtf(dx * dx + dy * dy); // Calculate the distance } return (GLfloat) 0.0; // Both dx and dy are zero } /* Given (px, py) and two points forming line segment(x1, y1), (x2, y2). Calculate the closest point(cpx, cpy) between the point and the line and return the distance.The linesegment flag is true the closest point must be on the line segment or false it does an extended infinite line test. */ GLfloat GLDistanceToLine2D (GLfloat px, GLfloat py, // Test point (px,py) GLfloat x1, GLfloat y1, // Line vertex 1 (x1,y1) GLfloat x2, GLfloat y2, // Line vertex 2 (x2,y2) bool linesegment, // Flag true if line segment, false extended line GLfloat* cpx, GLfloat* cpy) // Closest point point result pointers { GLfloat u; // see Paul Bourke's original article(s) GLfloat dx = x2 - x1; // Diff x GLfloat dy = y2 - y1; // Diff y GLfloat SqLineMag = dx * dx + dy * dy; // Square of line magnitude if (SqLineMag > -FLT_EPSILON && SqLineMag < FLT_EPSILON) { // We have a single point there is no measurable distance between vertexes if (linesegment) return GLDistance2D(px, py, x1, y1); // Line segement test return distance between 2 pts else return (GLfloat)-1.0; // Extended line invalid return -1 as it's impossible } u = ((px - x1)* dx + (py - y1)* dy) / SqLineMag; // Calculate value u if ((linesegment) && ((u < FLT_EPSILON) || (u > (GLfloat)1.0))) // Line segment test and closest point is outside the segment { GLfloat ix, iy; ix = GLDistance2D(px, py, x1, y1); // Distance line point (x1,y1) to point (px,py) iy = GLDistance2D(px, py, x2, y2); // Distance line point (x2,y2) to point (px,py) if (ix < iy) { // If first distance less than second if (cpx) (*cpx) = x1; // If x intersect result needed return x1 if (cpy) (*cpy) = y1; // If y intersect result needed return y1 return(ix); // Return distance as calculated distance ix } else { if (cpx) (*cpx) = x2; // If x intersect result needed return x2 if (cpy) (*cpy) = y2; // If y intersect result needed return y2 return(iy); // Return distance as calculated distance iy } } else { // Closest point is between line points or extended line test GLfloat ix, iy; ix = x1 + (u * dx); // Calculate intersection point x if (cpx) (*cpx) = ix; // If x intersect result needed return it iy = y1 + (u * dy); // Calculate intersection point y if (cpy) (*cpy) = iy; // If y intersect result needed return it return GLDistance2D(px, py, ix, iy); // Return the distance } }``` Run a test .. it should return ix,iy = (200,100) dist = 100 ... plot it you will see why. ```GLfloat ix, iy; GLfloat dist = GLDistanceToLine2D(100, 100, 200, 0, 200, 200, true, &ix, &iy);``` In vino veritasmodified 23-Mar-18 2:36am.
 Re: Select and Pick lines in OpenGL Gopi Nath22-Mar-18 21:08 Gopi Nath 22-Mar-18 21:08
 Re: Select and Pick lines in OpenGL Gopi Nath24-Jul-18 21:17 Gopi Nath 24-Jul-18 21:17
 Notifiation Messages for CSpinButtonCtrl in MFC Sampath57922-Mar-18 3:46 Sampath579 22-Mar-18 3:46
 Re: Notifiation Messages for CSpinButtonCtrl in MFC Jochen Arndt22-Mar-18 4:32 Jochen Arndt 22-Mar-18 4:32
 Re: Notifiation Messages for CSpinButtonCtrl in MFC Sampath57922-Mar-18 7:31 Sampath579 22-Mar-18 7:31
 Re: Notifiation Messages for CSpinButtonCtrl in MFC Victor Nijegorodov22-Mar-18 8:37 Victor Nijegorodov 22-Mar-18 8:37
 Re: Notifiation Messages for CSpinButtonCtrl in MFC Sampath57922-Mar-18 17:10 Sampath579 22-Mar-18 17:10
 Re: Notifiation Messages for CSpinButtonCtrl in MFC Victor Nijegorodov22-Mar-18 21:45 Victor Nijegorodov 22-Mar-18 21:45
 Re: Notifiation Messages for CSpinButtonCtrl in MFC Jochen Arndt22-Mar-18 9:46 Jochen Arndt 22-Mar-18 9:46
 Re: Notifiation Messages for CSpinButtonCtrl in MFC Sampath57922-Mar-18 17:17 Sampath579 22-Mar-18 17:17
 Re: Notifiation Messages for CSpinButtonCtrl in MFC Victor Nijegorodov22-Mar-18 21:52 Victor Nijegorodov 22-Mar-18 21:52
 Re: Notifiation Messages for CSpinButtonCtrl in MFC Sampath57923-Mar-18 0:22 Sampath579 23-Mar-18 0:22
 Re: Notifiation Messages for CSpinButtonCtrl in MFC Jochen Arndt22-Mar-18 22:00 Jochen Arndt 22-Mar-18 22:00
 Re: Notifiation Messages for CSpinButtonCtrl in MFC Sampath57923-Mar-18 0:22 Sampath579 23-Mar-18 0:22
 Re: Notifiation Messages for CSpinButtonCtrl in MFC Victor Nijegorodov22-Mar-18 4:38 Victor Nijegorodov 22-Mar-18 4:38
 QR CODE IN ARABIC Member 1054250021-Mar-18 6:13 Member 10542500 21-Mar-18 6:13
 Re: QR CODE IN ARABIC Richard MacCutchan21-Mar-18 6:44 Richard MacCutchan 21-Mar-18 6:44
 Last Visit: 31-Dec-99 18:00     Last Update: 29-May-24 4:47 Refresh ᐊ Prev1...293294295296297298299300301302 Next ᐅ