solvespace icon indicating copy to clipboard operation
solvespace copied to clipboard

slvs c++ library dosent constrain with SLVS_C_PT_PLANE_DISTANCE

Open Vishnu-C opened this issue 2 years ago • 4 comments

System information

  • SolveSpace version: 3.1~727b0153
  • Operating system: Windows 10

Expected behavior

SLVS_C_PT_PLANE_DISTANCE should bring the point 3D above the work plane. doc

Actual behavior

The point 3D remains unchanged

Additional information

Code snippet

void ExamplePlanePoint3d() 
{
    Slvs_hGroup g = 1;

    /* Plane Origin, (x y z) = (0 0 0) */
    sys.param[sys.params++] = Slvs_MakeParam(1, g, 0.0);
    sys.param[sys.params++] = Slvs_MakeParam(2, g, 0.0);
    sys.param[sys.params++]    = Slvs_MakeParam(3, g, 0.0);

    sys.entity[sys.entities++] = Slvs_MakePoint3d(101, g, 1, 2, 3);

    /* Plane Normal, N = (0.0, 0.0, 1.0) */
    // Basis Vectors
    double U[3] = {1.0, 0.0, 0.0};
    double V[3] = {0.0, 1.0, 0.0};
    double qw, qx, qy, qz;
    Slvs_MakeQuaternion(U[0], U[1], U[2], V[0], V[1], V[2], &qw, &qx, &qy, &qz);

    sys.param[sys.params++] = Slvs_MakeParam(4, g, qw);
    sys.param[sys.params++] = Slvs_MakeParam(5, g, qx);
    sys.param[sys.params++] = Slvs_MakeParam(6, g, qy);
    sys.param[sys.params++] = Slvs_MakeParam(7, g, qz);

    sys.entity[sys.entities++] = Slvs_MakeNormal3d(201, g, 4, 5, 6, 7);

    sys.entity[sys.entities++] = Slvs_MakeWorkplane(301, g, 101 /*origin*/, 201 /*normal*/);

     /* Test Point (x y z) = (10.0 0.0 0.0) */
    sys.param[sys.params++] = Slvs_MakeParam(8, g, 10.0);
    sys.param[sys.params++] = Slvs_MakeParam(9, g, 0.0);
    sys.param[sys.params++] = Slvs_MakeParam(10, g, 0.0);

    sys.entity[sys.entities++] = Slvs_MakePoint3d(102, g, 8, 9, 10);

    double fDistanceAbovePlane = 10.0;
    sys.constraint[sys.constraints++] =
        Slvs_MakeConstraint(1, g, SLVS_C_PT_PLANE_DISTANCE, SLVS_FREE_IN_3D, fDistanceAbovePlane,
                            102 /*Test point*/, 0, 301 /* workplane*/, 0);

    /* Let's tell the solver to keep the plane origin as close to constant
     * as possible, instead moving the Test point. */
    sys.dragged[0] = 1;
    sys.dragged[1] = 2;
    sys.dragged[2] = 3;

    Slvs_Solve(&sys, g);

    if(sys.result == SLVS_RESULT_OKAY) 
    {
        printf("okay; now at (%.3f %.3f %.3f)\n",
               sys.param[7].val, sys.param[8].val, sys.param[9].val);
        printf("%d DOF\n", sys.dof);
    } else {
        printf("solve failed");
    }
}

Output

okay; now at (10.037 0.000 0.040)

Expected to be at (10.037 0.000 10.0)

Vishnu-C avatar Dec 05 '23 18:12 Vishnu-C

@Vishnu-C can you verify that the plane didn't move? Also, can you start with the initial point not on the plane?

phkahler avatar Dec 29 '23 20:12 phkahler

@phkahler The plane did move, but I solved it anyway, I had to make the test point in a new separate group and solve with the new group. Thanks for the reply!

Vishnu-C avatar Dec 30 '23 15:12 Vishnu-C

@Vishnu-C you could also constrain the plane so it can't move. But your approach of making a new group has the same effect since previous groups are held fixed while the later one is solved.

Can we close this issue?

phkahler avatar Dec 31 '23 14:12 phkahler

@phkahler I couldn't constrain the plane, can you suggest please? I believe my approach is a workaround, I may stumble upon cases where I cannot create a separate group for work plane.

Vishnu-C avatar Jan 01 '24 04:01 Vishnu-C