Click here to Skip to main content
15,889,863 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Directory existance Pin
Ravi Bhavnani19-May-05 5:41
professionalRavi Bhavnani19-May-05 5:41 
GeneralRe: Directory existance Pin
ThatsAlok19-May-05 18:25
ThatsAlok19-May-05 18:25 
GeneralProblem with controlling window media player Pin
JaniceA19-May-05 5:06
JaniceA19-May-05 5:06 
GeneralRun program on startup Pin
Zack Manning19-May-05 4:52
sussZack Manning19-May-05 4:52 
GeneralRe: Run program on startup Pin
Blake Miller19-May-05 5:18
Blake Miller19-May-05 5:18 
GeneralRe: Run program on startup Pin
ddmcr19-May-05 7:11
ddmcr19-May-05 7:11 
GeneralPolyBezier Pin
Anthony988719-May-05 4:37
Anthony988719-May-05 4:37 
GeneralRe: PolyBezier Pin
Joel Holdsworth19-May-05 6:51
Joel Holdsworth19-May-05 6:51 
Ok... I think you are going down the right path with PolyBezier. But you have to think a bit about how beziers work. There's an article here[^] on the subject (ignore the code at the bottom - windows implements that for you!). So each point on the polygon has two bezier handles associated with it... one for the next line segment, and on for the previous. Now what I think Excel does is choose the positions of those bezier handles for you automatically. The two points are in a smooth arrangement - so the the polygon point, and the two bezier handles form a straight line. The distance between the handle and polygon point is chosen in proportion to the length of the line segmet it applies to. With me so far?

Additionally the line formed by the polygon point and the two bezier handles is angled in way to be sort of tangential to the polygons. It seems to take an average between the angle of the first and last segments (whether weigthed by length I'm not sure).

so I think you need to do something like this:

void DrawSmoothedPolygon(HDC dc, POINT *pointlist, int pointcount)
{
   const float curvyness = 0.1f;

   float prevseglength, nextseglength;
   long dx, dy;
   long leapfrogdx, leapfrogdy;

   ASSERT(pointlist != NULL);
   ASSERT(pointcount >= 3);

   POINT *curvepoints = new POINT[pointcount * 3 + 1];

   curvepoints[0] = pointlist[i];
   curvepoints[1] = pointlist[i];
   curvepoints[pointcount * 3 + 1] = pointlist[pointcount];
   curvepoints[pointcount * 3] = pointlist[pointcount];

   dx = (curvepoints[1].x - curvepoints[0].x);
   dy = (curvepoints[1].y - curvepoints[0].y);

   nextseglength = sqrt(dx*dx + dy*dy);
   
   for(int i = 1; i < pointcount - 1; i++)
   {
      leapfrogdx = (curvepoints[i-1].x - curvepoints[i+1].x);
      leapfrogdy = (curvepoints[i-1].y - curvepoints[i+1].y);

      preveglength = nextseglength;
      dx = (curvepoints[i+1].x - curvepoints[i].x);
      dy = (curvepoints[i+1].y - curvepoints[i].y);
      nextseglength = sqrt(pointlist[i].x * pointlist[i].x + pointlist[i].y * pointlist[i].y);

      curvepoints[i * 3] = pointlist[i];

      curvepoints[i * 3 + 1].x = pointlist[i].x + leapfrogdx / (nextseglength / curvyness);
      curvepoints[i * 3 + 1].y = pointlist[i].y + leapfrogdy / (nextseglength / curvyness);
      curvepoints[i * 3 - 1].x = pointlist[i].x - leapfrogdx / (prevseglength / curvyness);
      curvepoints[i * 3 - 1].y = pointlist[i].y - leapfrogdy / (prevseglength / curvyness);
   }

   PolyBezier(dc, curvepoints, pointcount * 3 + 1);
   delete[] curvepoints;
}
Now I'm not sure how well this will work. But it may give you some ideas to start with. Also it doesn't deal with closed curves... I'll leave you to figure those out Wink | ;)

Joel Holdsworth

Wanna give me a job this summer?
Check out my online CV and project history[^] - now available in MSWord format![^]
GeneralHelp needed to fix warning C4251 Pin
Kri519-May-05 3:55
Kri519-May-05 3:55 
GeneralRe: Help needed to fix warning C4251 Pin
Alexander M.,19-May-05 4:22
Alexander M.,19-May-05 4:22 
GeneralRe: Help needed to fix warning C4251 Pin
Kri519-May-05 6:04
Kri519-May-05 6:04 
GeneralRe: Help needed to fix warning C4251 Pin
jmkhael19-May-05 6:32
jmkhael19-May-05 6:32 
GeneralRe: Help needed to fix warning C4251 Pin
Anonymous19-May-05 7:03
Anonymous19-May-05 7:03 
GeneralRe: Help needed to fix warning C4251 Pin
jmkhael19-May-05 7:18
jmkhael19-May-05 7:18 
GeneralRe: Help needed to fix warning C4251 Pin
Kri519-May-05 11:30
Kri519-May-05 11:30 
GeneralConnecting to another computer's shares as a different user Pin
Luis Mejia19-May-05 3:39
Luis Mejia19-May-05 3:39 
GeneralRe: Connecting to another computer's shares as a different user Pin
Blake Miller19-May-05 5:10
Blake Miller19-May-05 5:10 
GeneralRe: Connecting to another computer's shares as a different user Pin
David Crow19-May-05 5:51
David Crow19-May-05 5:51 
GeneralRe: Connecting to another computer's shares as a different user Pin
Luis Mejia19-May-05 14:58
Luis Mejia19-May-05 14:58 
Generalsorting charater array alphabetically Pin
Anonymous19-May-05 3:15
Anonymous19-May-05 3:15 
GeneralRe: sorting charater array alphabetically Pin
Joaquín M López Muñoz19-May-05 3:17
Joaquín M López Muñoz19-May-05 3:17 
GeneralRe: sorting charater array alphabetically Pin
BlackDice19-May-05 5:39
BlackDice19-May-05 5:39 
Questionmulti-monitors? Pin
Anonymous19-May-05 3:05
Anonymous19-May-05 3:05 
AnswerRe: multi-monitors? Pin
Blake Miller19-May-05 5:13
Blake Miller19-May-05 5:13 
GeneralThread - Process synchronization Pin
javi_jmc19-May-05 2:47
javi_jmc19-May-05 2:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.