Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- Be respectful, on topic and if you see a problem, Flag it.
If you would like to contact our Community Manager personally, feel free to send a private message or an email.
How to check if an edge is a straight line?
eric_pesty
Member Posts: 2,415 PRO
This is probably obvious but I'm struggling with figuring out if something is "straight"...
I'm computing the min radius of curvature of a sweep path and got it working (I stole/repurposed the code from @NeilCooke 's cable/wire routing) but i would like to do a check first so I don't sample curvature a bunch of times if the segment is just a straight line...
I thought I could use "canBeLine" but it seems to always return false even when I pick a straight sketch segment as my input...
I'm computing the min radius of curvature of a sweep path and got it working (I stole/repurposed the code from @NeilCooke 's cable/wire routing) but i would like to do a check first so I don't sample curvature a bunch of times if the segment is just a straight line...
I thought I could use "canBeLine" but it seems to always return false even when I pick a straight sketch segment as my input...
Tagged:
0
Comments
FRC Design Mentor - Team 1306 BadgerBots
var samples = 1; const wireGeometry = evCurveDefinition(context, { "edge" : edge }); if (wireGeometry is Line) { continue; } else if (wireGeometry is Circle) { if (wireGeometry.radius >= minBendRadius) continue; } else { samples = floor(evLength(context, { "entities" : edge }) / (minBendRadius / 4)); } const curveSamples = @evEdgeCurvatures(context, { "edge" : edge, "parameters" : samples == 1 ? [0.5] : range(0, 1, samples) });excerpt from changed codeI need to study this more but it looks like exactly what I need to do, I'll take a look when I get a chance! I'm assuming the "circle" case will detect a circular arc?
This is what I currently have, the key difference being I need an extra loop as I'm looking for the curvature on a path that can have multiple segments:
EDIT: why is the "code" block so dumb in here?
I also meant to ask, where does the "length / (min bend / 4)" come from on the number of samples? Is that a "scientific" way to determine how many samples are required or just something that "works"? Just curious!
In my case I am just trying to find the minimum bend radius and display in a table (rather than establish a pass/fail so I might need to do this a bit differently...). I replaced your min bend radius with the diameter of my sweep but really what I'm looking for is not dependent on what I'm sweeping!
I should be doing whatever the "curvature comb" is doing to display the min curvature... (and as a side note it would be really nice if we had access to a function that would do that for us as efficiently as possible rather than writing our own!)
export function computeBendRadius(context is Context, OD is ValueWithUnits, path is Query) returns ValueWithUnits { var minRadius = 1e6; var minPoint; const edges = evaluateQuery(context, path); println("number of segments: " ~ size(edges)); for (var e = 0; e < size(edges); e += 1) { var segmentLG = evLength(context, { "entities" : edges[e] }); var segmentsamples = floor(segmentLG / OD * 3); println("segment " ~ e ~ ", Length: " ~ toString(segmentLG) ~ ", samples : " ~ segmentsamples); var segcurvesamples = @evEdgeCurvatures(context, { "edge" : edges[e], "parameters" : range(0, 1, segmentsamples) }); for (var sample in segcurvesamples) { if (minRadius > 1 / sample.curvature) { minRadius = 1 / sample.curvature; minPoint = sample.frame; } } println("min radius so far : " ~ minRadius); if (isUndefinedOrEmptyString(minPoint)) { minPoint = segcurvesamples[0].frame; } } println("overall min radius: " ~ minRadius); minRadius *= meter;Ah ok! Create the "code" section first.I had pasted the code first and selected it and formatted as code and that was a disaster (the whole thing was on one line with extra HTML crap), talk about hard to read:
<div>export function computeBendRadius(context is Context, OD is ValueWithUnits, path is Query) returns ValueWithUnits</div><div>{</div><div> var minRadius = 1e6;</div><div> var minPoint;</div><div><br></div><div> const edges = evaluateQuery(context, path);</div><div><br></div><div> println("number of segments: " ~ size(edges));</div><div><br></div><div> for (var e = 0; e < size(edges); e += 1)</div><div> {</div><div><br></div><div> var segmentLG = evLength(context, { "entities" : edges[e] });</div><div> var segmentsamples = floor(segmentLG / OD * 3);</div><div> println("segment " ~ e ~ ", Length: " ~ toString(segmentLG) ~ ", samples : " ~ segmentsamples);</div><div><br></div><div> var segcurvesamples = @evEdgeCurvatures(context, {</div><div> "edge" : edges[e],</div><div> "parameters" : range(0, 1, segmentsamples)</div><div> });</div><div> for (var sample in segcurvesamples)</div><div> {</div><div> if (minRadius > 1 / sample.curvature)</div><div> {</div><div> minRadius = 1 / sample.curvature;</div><div> minPoint = sample.frame;</div><div> }</div><div><br></div><div> }</div><div> println("min radius so far : " ~ minRadius);</div><div> if (isUndefinedOrEmptyString(minPoint))</div><div> {</div><div> minPoint = segcurvesamples[0].frame;</div><div> }</div><div><br></div><div> }</div><div> println("overall min radius: " ~ minRadius);</div><div> minRadius *= meter;</div>I ran into some difficulties with implementing the code above as I am doing things a bit differently but then I did a "profile" and sampling the curvature 50times on a straight line is quicker than 5 samples on a spline so the performance impact seems pretty negligible.
Interestingly, adding the debug arrow is quite a bit slower than the curvature sampling loops, and the opSweep are also slower so while it's not super efficient it doesn't really have a noticeable performance impact so I am going to leave it like this for now.
export function computeBendRadius(context is Context, OD is ValueWithUnits, path is Query) returns ValueWithUnits { var minRadius = 1e6; var minPoint; const edges = evaluateQuery(context, path); const maxsampledist = .25 * inch; // println("number of segments: " ~ size(edges)); for (var e = 0; e < size(edges); e += 1) { var segmentLG = evLength(context, { "entities" : edges[e] }); var sampleint = min(maxsampledist, OD); var segmentsamples = floor(segmentLG / sampleint * 3); // println("segment " ~ e ~ ", Length: " ~ toString(segmentLG) ~ ", samples : " ~ segmentsamples); var segcurvesamples = @evEdgeCurvatures(context, { "edge" : edges[e], "parameters" : range(0, 1, segmentsamples) }); for (var sample in segcurvesamples) { if (minRadius > 1 / sample.curvature) { minRadius = 1 / sample.curvature; minPoint = sample.frame; } } //println("min radius so far : " ~ minRadius); if (isUndefinedOrEmptyString(minPoint)) { minPoint = segcurvesamples[0].frame; } } //println("overall min radius: " ~ minRadius); minRadius *= meter; //display path and min radius location minPoint = coordSystemFromBuiltin(minPoint); addDebugEntities(context, path, DebugColor.BLUE); if (minRadius < OD / 2) { addDebugArrow(context, minPoint.origin + minPoint.xAxis * minRadius * 20, minPoint.origin, OD * 2, DebugColor.RED); } else { addDebugArrow(context, minPoint.origin + minPoint.xAxis * minRadius, minPoint.origin, OD, DebugColor.GREEN); } return minRadius; }