Trim at curve crossing

Next
 From:  pressure (PEER)
11423.1 
I'm looking for a way to trim a first curve with a second cutter curve, but only where the first curve actually crosses the cutter and not where it just grazes it.

Like for a line tangent to a circle with the circle as the cutter the line shouldn't get cut at all.

But if the line passes through the center of the circle cutter then I expect the line to get cut into 3 pieces.

- Peer
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
11423.2 In reply to 11423.1 
Hi Peer, there isn't anything built in to the regular Trim that would do that. I'd think you would need a custom made function.

First you'd need to get the intersections between the curves which you can do with the intersect factory:

code:
var curves = moi.geometryDatabase.getSelectedObjects();

if ( curves.length == 2 )
{
    var curve_list = moi.geometryDatabase.createObjectList();
    var factory = moi.command.createFactory( 'intersect' );
    factory.setInput( 0, curves );

     var points_list = factory.calculate().getPoints();
     factory.cancel();

     var text = points_list.length + ' points\n';

     for ( var i = 0; i < points_list.length; ++i )
     {
        var pt_obj = points_list.item(i);
        text += pt_obj.pt.x.toFixed(2) + ', ' + pt_obj.pt.y.toFixed(2) + ', ' + pt_obj.pt.z.toFixed(2) + '\n';
    }

    moi.ui.alert( text );
}


Then for every point get a curve parameter value for the point with
var t = crv.dropPoint( pt );

Then you can evaluate the tangents of both curves using
var tangent = crv.evaluateTangent( t );

If the angle between the tangents is close to 0 or close to 180 degrees then it's one of the grazing intersections so skip it.

Otherwise keep it as a cutting parameter value, sort those cut parameters and then go through them generating pieces using:
var piece = crv.trim( paramA, paramB );

If it's a closed curve and you don't have the start/end of the curve as a cutting parameter then you probably want to call
var reseamed_crv = crv.changeClosedCurveSeam( t );

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  pressure (PEER)
11423.3 In reply to 11423.2 
Thanks for the rapid reply and thorough explanation!

I had no idea that curve.trim() was a thing, so that's pretty cool to learn about and it lead me to some other new curve methods.

I'll try coding up your approach.

- Peer
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
11423.4 In reply to 11423.3 
Hi Peer, I'll also add in a curve.split(); method that will take an array of parameters, and it will handle changing the seam point on a closed curve.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
 From:  pressure (PEER)
11423.5 In reply to 11423.4 
Nice! I'm looking forward to it Michael.

- Peer
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged
 

Reply to All Reply to All