splines & points
-
On 08/04/2013 at 15:21, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 12
Platform: Mac ;
Language(s) : C++ ;---------
I am trying to write a simple export plugin to create rudimentary g-code for my CNC machine. That means I am trying to pick through how splines can be transformed into usable paths for the tool head. I am using the SplineHelper class but have a hard time finding any detailed info about how to use it.In a simple case I'll have a spline rectangle and to use this to make g-code I'd like to go to the first point, calculate the distance to the second point, etc. until I am back at the first point.
I guess specific questions are:
Is there a way to get the position of each point? (like GetFirst, GetNext....)
Anybody know a good tutorial about splines & points?C4D doesn't seem to be the right tool. At the same time much of the stuff I make starts out in C4D and is then transferred through various applications, via a MacMini running Windows XP, to EMC2 on a Linux box. Just too many steps and I find the Windows tools cumbersome to use.
Peter
-
On 08/04/2013 at 18:38, xxxxxxxx wrote:
Have you checked out SplineObject in the SDK documentation? You'll be most interested in GetSegmentCount() and then GetSplinePoint() and GetSplineTangent(). These allow you to walk along the spline at whatever resolution you desire to get interpolated points on the spline segment by segment. GetSplineTangent() can be used to 'fill in' between your resolution sampling by giving a direction or you can do the next sample and get the direction for motion from this sample to the next.
-
On 09/04/2013 at 00:21, xxxxxxxx wrote:
SplineObject is definitely a good solution, with the benefit of being resolution-independent as mentioned.
SplineHelp can still be useful for getting distance values for specific point indices if required. Distance is calculated by multiplying a point's segment offset by the segment length.
----------------------------------------------------------------------
AutoAlloc<SplineHelp> sh;
if(!sh) return;sh->InitSpline(spline);
if(!sh->Exists()) return;Real segOffs = 0.0;
LONG segPntInd = 0;
LONG segInd = 0;// get distances for 'point array' indices
LONG pntCnt = sh->GetPointCount();
GeDynamicArray<Real> pntDstArr;for(LONG i = 0; i < pntCnt; i++)
{
sh->GetSplinePointSegment(i, &segOffs;, &segPntInd;, &segInd;);
Real segLen = sh->GetSegmentLength(segInd);
Real dist = segOffs * segLen;
pntDstArr.Push(dist);
}// get distances for 'interpolated' indices
LONG segCnt = sh->GetSegmentCount();
LONG vtxCnt = 0;for(LONG i = 0; i < segCnt; i++)
{
LONG cnt = sh->GetVertexCount(i);
vtxCnt += cnt;
}GeDynamicArray<Real> vtxDstArr;
for(LONG i = 0; i < vtxCnt; i++)
{
sh->GetLinePointSegment(i, &segOffs;, &segPntInd;, &segInd;);
Real segLen = sh->GetSegmentLength(segInd);
Real dist = segOffs * segLen;
vtxDstArr.Push(dist);
}
---------------------------------------------------------------------- -
On 12/04/2013 at 20:21, xxxxxxxx wrote:
Thanks Robert & Dave
That sheds light on SplineObject. The descriptions in the SDK are a bit cryptic so this really helps.Thanks.
Peter