*On 05/06/2010 at 17:29, xxxxxxxx wrote:*

User Information:

Cinema 4D Version: 11.5

Platform: Windows ; Mac ; Mac OSX ;

Language(s) : C.O.F.F.E.E ;

---------

I know how to get the coordinates (global or local) of a point along a spline.

But how can I get the plane that is perpendicular to that point in the spline?

Maybe its easier to understand with a picture:

I have a spline (the blue curve). Now imagine that I have the point located at 0.45 along the spline (using UniformToNatural...). How can I calculate the plane that is perpendicular to that specific point? (the red plane, in the picture, perpendicular to the tangent of the spline in that point).

I ask this because I need to calculate points on the surface of that plane (the green dots). Actually, I need to calculate a vector that is coplanar to that plane and that has its origin in the point of the spline that I'm calculating the perpendicular plane from.

Anyone? Please?

Thank you very much in advance.

Rui Batista

]]>*On 07/06/2010 at 18:40, xxxxxxxx wrote:*

Yes, its working fine now. Well, I still have to add a few more options but the main part is already working.

Thank you all for the help :-)

Rui Batista

]]>*On 07/06/2010 at 13:51, xxxxxxxx wrote:*

Thanks Michael, that shaved a few lines off in my set up.

Making a little Spiral Gadget here :)

Rui, did you get it working now?

Cheers

Lennart

*On 07/06/2010 at 08:10, xxxxxxxx wrote:*

Hey guys. You must not add hpb rotations just like so ;p

Its better generate a local rotation matrix and multiply it to the right of the tangent plane matrix.

Here is a piece of code which works pretty well in Ruis scene:

```
var m_spiral = new(Matrix);
m_spiral->SetRotHPB(vector(0,0,t*2*PI*10));
var hpb=VectorToHPB(tang);
var new_mat = new(Matrix);
new_mat->SetRotHPB(hpb);
new_mat->SetV0(pos);
new_mat=new_mat->GetMulM(m_spiral);
new_mat=spline1->GetMg()->GetMulM(new_mat);
var vec = vector(0.0,radii,0.0);
var new_vec = new_mat->GetMulP(vec);
```

]]>*On 06/06/2010 at 19:41, xxxxxxxx wrote:*

It helped me a lot but its still not working the way I want it to :-(

I want to adjust the points of a spline so that it spirals around another spline.

If its not asking you too much, could you take a look at what I have come up so far?

Pay no attention to the User Data parameters of the COFFEE tag. For now, only the Spline, Number of Points and Radius are working.

Thank you very much in advance.

Rui Batista

]]>*On 06/06/2010 at 19:00, xxxxxxxx wrote:*

See if this rude set up might help.

```
// Put COFFEE Tag on an object to circle the spline
// Add a point spline in link field.
GetFirstTag(obj,type)
{
var tag = obj->GetFirstTag();
while (tag){
if (tag->GetType() == type) return tag;
tag = tag->GetNext();
}
return NULL;
}
main(doc,op)
{
var ctag = GetFirstTag(op,Tcoffeeexpression);
var udpos = ctag#ID_USERDATA:1;
var spline = ctag#ID_USERDATA:2;
spline->InitLength(0);
var spos = spline->GetSplinePoint(spline->UniformToNatural(udpos),0);
var tpos = spline->GetSplineTangent(spline->UniformToNatural(udpos),0);
var srot = VectorToHPB(tpos);
var revs = 20; // revs along spline
var mym = new(Matrix);
mym->SetRotHPB(srot+vector(0,0,udpos*2*PI*revs));
mym->SetV0(spos);
mym = spline->GetMg()->GetMulM(mym);
op->SetMg(mym);
}
```

Cheers

Lennart

*On 06/06/2010 at 18:35, xxxxxxxx wrote:*

So, this is a snippet of my code:

```
x=spline1->UniformToNatural(float(f)/(n_points-1));
pos=spline1->GetSplinePoint(x,0);
tang=spline1->GetSplineTangent(x,0);
r1=50*sin(31.415*f); // just for testing
r2=50*cos(31.415*f); // just for testing
hpb=VectorToHPB(vnorm(pos-tang));
new_mat = new(Matrix);
new_mat->SetV0(pos);
new_mat->SetRotHPB(hpb);
vec = vector(r1,r2, 0.0);
new_vec = new_mat->GetMulP(vec);
```

Should this be it? Its not working as I expected :(

Rui Batista

]]>*On 06/06/2010 at 16:35, xxxxxxxx wrote:*

Mmmmm, ok, I will give it a try. Thank you Lennart.

Rui Batista

]]>*On 06/06/2010 at 16:18, xxxxxxxx wrote:*

You need to build a matrix. The position is given by the spline point position.

The rotation you build from the spline point position and the tangent position.

The GetSplineTangent(x,0) returns a position in space tangential to the

spline point position at distance x. (It doesn't give a angle).

Using VectorToHPB(splinepoint - tangentpoint) will give you the

basic rotation (skipping up vector to start with)

So you basically build a AlignToSpline function moving a tangential

matrix (instead of an object).

This matrix is what you have as a base for the circle calculation.

Cheers

Lennart

*On 06/06/2010 at 15:47, xxxxxxxx wrote:*

That sounds logic and I can see it in my mind.

The problem is how to make sure the "circle" gets mapped perpendicularly to the points along the spline.

The matrix of the spline gives me just that, the matrix of the position/rotation/scale of the spline object, not the matrix of the points along the spline.

Rui Batista

]]>*On 06/06/2010 at 11:12, xxxxxxxx wrote:*

My theoretical go at it would be to describe a regular circle (local sin x , cos y) around the

z direction ( of a matrix at spline position).

Iterating the position of that matrix along the spline while

calculating the circle would then describe a helix along the spline.

(The movement along the spline corresponding to the "t" in that Helix formula)

Cheers

Lennart

*On 06/06/2010 at 10:53, xxxxxxxx wrote:*

I had already been there, emberintherain. And, unfortunately, it doesn't help me much. I know how to create an helix along a line. Not along an arbitrary spline :-(

]]>*On 06/06/2010 at 10:49, xxxxxxxx wrote:*

Would this help?

http://en.wikipedia.org/wiki/Helix

This at least provides some formulas.

]]>*On 06/06/2010 at 09:49, xxxxxxxx wrote:*

So, I believe that, for what I'm trying to create, I just need to know the code to do this:

I have been trying to get that information from the net but can't seem to find anything :-(

So, I have a spline. I have access to the coordinates of any point along that spline. I also have access to the tangent vector of any point along that spline. What is the method to calculate the helix points around that spline?!? Anyone knows or could point me in the right direction?

Rui Batista

]]>*On 06/06/2010 at 00:46, xxxxxxxx wrote:*

I know I need, at least, three points or one point and a vector, to define a plane.

I do have one point and a vector (the tangent vector).

However, I arrived to the conclusion that all I need to know is how to calculate a spiral along a spline.

I have been searching for the source code of such expression but I could not find anything :-(

I tried searching for "helix along spline", "helix along spline source code", "helix around spline", "spiral along spline", etc.

All I find are methods to do that using applications. What I need is the source code.

Rui Batista

]]>*On 05/06/2010 at 20:22, xxxxxxxx wrote:*

I am pretty sure you need more than one point to find a plane. :)

]]>*On 05/06/2010 at 17:59, xxxxxxxx wrote:*

Better yet, if someone could point me in the right direction as to how to calculate the points of an helix along a spline, I believe I could do what I need.

Rui Batista

]]>