Align plane to nearest two points on a mesh

Very cool problem regardless.

I couldn’t help but to come back and test one of a couple of ideas I’ve entertained.

I’m not super happy because it’s not bullet proof.

You might have to get help from true gurus in this forum!

In the meantime one of those entertaining ideas was:

A bounding box for the mesh is created using the XZ plane for its orientation
Evaluate the box (‘W’ parameter = 0) to get the start plane:

Then we create point regions to get some low-zone candidate points:

Then the two lowest points are determined*:

*It’s important to mention that this is a custom sorting of the points within each candidate zone, where we make the (A) Z value of the points have a greater ‘influence’ than their (B) distance to the local base plane, but we still get a sum of A and B to sort the points.

With that we try to force a finding of the closest-lowest point (:rofl:) at each of the candidate regions, to fit a line between them:

image

We then project this line to the local plane and use Rotate Direction again:


This time the first-and-lowest point of contact isn’t the same as before; it’s now the first closest-lowest point as I mentioned above, so it tries to make sure the plane doesn’t cut through the anatomy piece.

First point:


Second point:

Here’s the file if you want to take a look:
Mesh with 2-points of contact-2.gh (565.5 KB)

Still not proud of it!

Another idea I had in mind was using a local axis for the mesh (for instance, the fitted line through all vertices) to rotate a plane about it and grab a bunch of mesh cross sections to then determine the biggest cross section and start messing with extreme points so we find the two contact points that way.

Best

I kept thinking about this and thought of something with kangaroo.

I think am doing it wrong lol - it can be improved. Maybe by using the 3D convex hull of the mesh points to speed up the rigid body stuff.

However, as is I start the kangaroo engine, it takes a couple of minutes and then I stop it.

The result seems acceptable:


In essence I do make the mesh fall onto the base plane, attempting to anchor it from the lowest point then make it fall flushed with the base plane using the solid and plane collision component. Once it falls and settles, we get an intersection (base plane and collided mesh), consisting of two planar curves. The centers of these intersections can now be pulled to the mesh via Mesh Closest Point . From these points we can find the closest vertices and fit a line to use when rotating the direction of the base plane without compromising the position of the mesh.

It seemed to work, probably a work-in-progress happy accident.
Mesh with 2-points of contact-23-kangaroo.gh (574.8 KB)


Mesh with 2-points of contact.gh (548.3 KB)

Thank-you for this! You definitely should be proud. It is very close. It took me quite some time to follow the algorithm, but I think I understand most of except for the rational of the Z weighting vs. distance. Anyway it is a viable solution.

FWIW, the orientation of the femur was random for the exercise. I did not realize how “flat” the lowest regional was for the distal lateral femoral condyle (furtherest contact point from the origin) was. But it serves as a good test for algorithms which use approximation methods.

This seems to be very accurate. I had played around with Kangaroo earlier in the week but abandoned it.

What is interesting is that both methods work, but the more accurate one (Kangaroo) requires much more processing overhead. I’m on a generic PC and the lag due to the Kangaroo physics is noticeable. So the less accurate method may actually be better is some applications.

Anyway, thank-you for your help on this! I’m amazed at the talent here and the creative approaches to problem solving.

This is another great solution! As I understand your approach, you project an outline (reducing 3D to 2D), remove redundant points, create a hull, separate the hull into segments, filter the desired segment, use line segment to reconstruct plane. Simple, yet clever! Thank-you Thomas!

I wish there was a way to select more than one solution for a thread as all three latter solutions work for my purposes. Rene wins out as his solution was first, but I will also be using Thomas solution. Thank-you again!

See what I meant!

awesome, @ThomasE

I think you can remove my reply as solution and reattribute to Thomas! :slightly_smiling_face:

Done, glad you are not offended. Your efforts were not in vain though. I learned a lot from your filtering methods and will be adapting your Kangaroo solution to a future problem. So this speed bump is solved, but I am expecting another one soon…but I will take several stabs at it first when I get there.

No problem!

BTW

I opened Thomas’ file. I love it.

It makes me curious about other pieces you’re trying this with. Could you show us in the near future?

In the first method I shared I was also going with mesh shadows and convex hulls, but detoured from that because I didn’t know if reorienting was allowed; and it was! Like you said, as long as it wasn’t arbitrary. What Thomas did isn’t :slight_smile: I broke my own rule of not over-constraining myself the whole time.

Though most likely unnecessary for this particular scenario, I kept looking into kangaroo, I think it’s definitely possible to improve and speed up rigid body collision, perhaps optimizing what’s shown here, here, or even here. while still constraining displacement along certain axes.

*At this point I guess you’d just use the 3D hull of the mesh to speed things up, drop it to the ground without it tumbling, then use some mesh-mapping from start 3D hull to target {dropped} 3D hull and reconstruct the original mesh…blah blah…

Back to what Thomas showed us and what I was doing in the beginning, I would have ended up with something like this:


It’s pretty much the same but here I went with the “local {fitted-through-vertices} mesh plane”.

Apologies for the delay regarding re-orientation possibility, thanks @colorado1876 for the teachings, and thanks Thomas for the memory elixir!

Mesh with 2-points of contact-reorient.gh (550.5 KB)

Sure, but in case it wasn’t obvious, this GH newbie’s near future is still a ways out. Right now, I just trying to figure out possible workflows.

I’m really excited about the possibilities of Kangaroo. That is what I hope to learn more of as time permits. I had abandoned it for this problem as the videos and GH files I found all simulated the physics of bouncing around, simulating gravity. I was concerned about losing mesh alignment. So I probably should have investigated earlier. Anyway, I see other potential uses for Kangaroo.

Not sure how I taught anything, but I know I learned a lot and the journey continues. Now we about the capabilities of hull, which likely surpasses the intentions of its developer.

“The teacher appears when the student is ready”

Something like that? Haha

It’s all about curiosity! One time I managed to influence the decision-making of an orthopedic surgeon after putting together a model using CT files. Not that I know what I am doing, but I love how we can forget about our actual ‘fields of work’ some times, step into geometry/data world to play and solve problems, then come back to the mundane realm.

So yes, thanks - I love using words like “effective radius” from now on! :wink:

Makes a lot of sense for the fabrication terminology we use in our shop!

Cheers