# CJ 2D Joint planar rotation

The previous 2D joint restricted position but rotation was free. The version on this page restricts the object so it may only rotate in the 2D plane (around the plane normal).

## Construction

The construction code is the same:

```Joint2D::Joint2D(NewtonBody* kpBody0, dVector kPlaneNormal)
{
mpBody0=kpBody0;
mPlaneNormal=kPlaneNormal;

dMatrix matrix0;
NewtonBodyGetMatrix(mpBody0, &matrix0);
mPlaneOrigin=matrix0.m_posit;

mpJoint=NewtonConstraintCreateUserJoint(mspWorld, 6, SubmitConstraints, mpBody0, 0);
NewtonJointSetUserData (mpJoint, (void*) this);
}
```

## SubmitConstraints

The constraint code begins the same but we add another linear constraint. This fixes a point the line through the object's origin along the plane normal, to a 2D plane that was parallel to the first. This second 2D plane is positioned away from the first such that the point is always in its desired position. The result of all of this is that rotations around the axes perpendicular to the plane normal are prevented because they would take the point out of its plane.

Example C++ code:

```void Joint2D::LocalSubmitConstraints(const NewtonJoint* kpJoint)
{
dMatrix matrix0;
NewtonBodyGetMatrix(mpBody0, &matrix0);

// this line clamps the origin to the plane

// we can prevent rotation that takes any points out of the plane by clamping a point on the
// object that is on the line through the origin of the object with the same vector as the
// plane normal.  The clamp is to another plane that is parallel to the first, offset by the
// plane normal vector.  Rotations around either of the axes orthogonal to the plane normal
// will be prevented because they take the object point off that parallel plane.

dVector object_point;
dVector world_point;

object_point=matrix0.TransformVector(mPlaneNormal);
world_point=mPlaneOrigin+mPlaneNormal;