Hi, it is possible to make changes to the source code for doing the same thing but with 3D courbes think you
ReplyHi! Can anyone tell me how can I get the curve points to my own array?
Here is my source code :
#include "stdafx.h"
#include
the header file does work perfectly!! i am excited!! thanks !! Good luck!!
Replyhow can i plot a point using x,y,z co-ordinates
friend
ReplyHi , I want to draw closed splines using a given set of points... How can i do that...? Actually , I don't know how to use the GenClosed() and drawClosed()functions. Thanks in advance... Arun Chakaravarthy
Replyhow to use this header file in IDC_Static of FormView
the curve is not in the IDC_BITMAP why??????
This is my code:
//////////////////////////////////////////////
void CTestView3::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CFormView::OnPaint();
// Do not call CFormView::OnPaint() for painting messages
}
void CTestView3::OnLButtonDown(UINT nFlags, CPoint point)
{
//check if the mouse left clicking into one of the control points
int index = IsInsideControlPoint(point);
if(index >= 0)
{
//we are moving a control point around
m_MoveIndex = index;
}
else //we are adding control points
{
CDC* pDC =m_bitmap.GetDC();//right?? DrawCross(point, RGB(255,0,0), 4, pDC->m_hDC);
m_ControlPoints.Add(point);
if(m_ControlPoints.GetSize()>1)
{
//create a spline object
Spline spline(m_ControlPoints.GetData(), m_ControlPoints.GetSize());
//generate a curve
spline.Generate();
//get the curve points number
m_CurvePoints.SetSize(spline.GetCurveCount());
//get the points number
int PointCount = 0;
spline.GetCurve(m_CurvePoints.GetData(), PointCount);
//paint the curve
UpdateFormView(pDC->m_hDC);
}
//ReleaseDC(pDC);
}
CFormView::OnLButtonDown(nFlags, point);
}
void CTestView3::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_MoveIndex >= 0)
{
m_ControlPoints[m_MoveIndex] = point;
if(m_ControlPoints.GetSize()>1)
{
Spline spline(m_ControlPoints.GetData(), m_ControlPoints.GetSize());
spline.Generate();
m_CurvePoints.SetSize(spline.GetCurveCount());
int PointCount = 0;
spline.GetCurve(m_CurvePoints.GetData(), PointCount);
}
CDC* pDC = m_bitmap.GetDC();
UpdateFormView(pDC->m_hDC);
ReleaseDC(pDC);
}
CFormView::OnMouseMove(nFlags, point);
}
void CTestView3::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_MoveIndex = -1;
CFormView::OnLButtonUp(nFlags, point);
}
void CTestView3::UpdateFormView(HDC &hDC)
{
//brush the DC
RECT rect;
GetDlgItem(IDC_BITMAP)->GetClientRect(&rect);//right??
FillRect(hDC, &rect, (HBRUSH)GetStockObject(IDC_BITMAP));//right??
//draw the control points
for(int i=0; i
Originally posted by: Youngsub Ahn
Program does not work properly when I changed spline.generate() to spline.genClosed().
Can you fix this?
Thank you.
I want to smooth a closed curve using this method and I am really a green hand. How can I make it work ? Do appreciate your help!
ReplyHi Raffy, yes, that worked. I changed the code to use GenClosed and drawClosed and bingo! Cheers :)
ReplyHi Arereal, maybe your end point coincides with the starting point. Try to use the functions for closed splines with n-1 knots and let me know. raffy
ReplyHi Raffy, I too was looking at making this a closed spline, I applied your change and it doesn't seem to make a difference, here's the code snippet... // Matrix for(i=1; i<=NP-1;i++) { Mat[0][i] = 1.0f; // Mat[1][1] = 2.0f*k[i-1]*(1.0f + k[i-1]); Mat[1][i] = 2.0f*k[i-1]*(1.0f + k[i-1]); Mat[2][i] = k[i-1]*k[i-1]*k[i]; } ArerealReply
You only need to replace the line: Mat[1][1] = 2.0f*k[i-1]*(1.0f + k[i-1]); with Mat[1][i] = 2.0f*k[i-1]*(1.0f + k[i-1]); RaffyReply
Originally posted by: Esther
Thanks a lot for your work!
I've searched long and hard for a working solution that
involves the drawing of curves.
Your solution matched my needs perfectly!
I managed to find your bug:
The function Generate contains the following line:
k[NP-2] = 1.0f;
At NP == 1 this means accessing k at index -1.
ReplyOriginally posted by: wadim
ever heard of windows GDI function named PolyBezier()?
:-)
wadim
ReplyOriginally posted by: Raman
We are doing something similar in a graphics project, where we require to draw a tangent at any of the user selected points generated for the spline. please help with ideas.
Reply