Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slvs c++ library dosent constrain with SLVS_C_PT_PLANE_DISTANCE #1431

Open
Vishnu-C opened this issue Dec 5, 2023 · 4 comments
Open

slvs c++ library dosent constrain with SLVS_C_PT_PLANE_DISTANCE #1431

Vishnu-C opened this issue Dec 5, 2023 · 4 comments

Comments

@Vishnu-C
Copy link

Vishnu-C commented Dec 5, 2023

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)

@phkahler
Copy link
Member

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

@Vishnu-C
Copy link
Author

@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!

@phkahler
Copy link
Member

@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?

@Vishnu-C
Copy link
Author

Vishnu-C commented Jan 1, 2024

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants