Edge Center
-
Hi.
Edge.bounds.center gives you the center of edge apparently.
It IS a drawingelement(I should read the API better) so bounds could be called for it, just havent used that method before.
It would be easier than offsetting edge.line[1] by edge.length/2 or something like that..It seams to be working in my code. So question is, are there any pitfalls or inconsistency one should be aware of using this method?
I know sometimes Face.bounds.center can need project_to_plane for ex.
But thinking about it, the center of an edge boundingbox must be center of edge regardless of position, orientationSo would edge_center = edge.bounds.center.project_to_line(edge.line[1)] be superfluous ?
-
Should be yes.
A quick loop over a set of edges where you test the two methods should let you verify.
I'd be interested in profiling this - I used to use Geom.linear_combination for edge mid-points. But the edge bound center might be faster as it'd be less steps. But as always - everything needs to be tested.
-
@unknownuser said:
I'd be interested in profiling this
Yes, me to. I totally overlooked this method. Saves a lot of typing.
Seeing all the tests you've done all over this forum I think you are well suited for the task
-
<span class="syntaxdefault"><br />model </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model<br />entities </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_entities<br /><br />t </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Time</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">now<br />edges </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">grep</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Edge</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">puts </span><span class="syntaxstring">"Edges; #{edges.size}"<br /></span><span class="syntaxdefault">puts </span><span class="syntaxstring">"Edge collection; #{Time.now - t}s"<br /><br /></span><span class="syntaxdefault">t </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Time</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">now<br />mid_points1 </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">grep</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Edge</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">{</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">|</span><span class="syntaxdefault">edge</span><span class="syntaxkeyword">|<br /></span><span class="syntaxdefault"> edge</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">bounds</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">center<br /></span><span class="syntaxkeyword">}<br /></span><span class="syntaxdefault">puts </span><span class="syntaxstring">"Midpoint by bounds; #{Time.now - t}s"<br /><br /></span><span class="syntaxdefault">t </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Time</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">now<br />mid_points2 </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">grep</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Edge</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">{</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">|</span><span class="syntaxdefault">edge</span><span class="syntaxkeyword">|<br /></span><span class="syntaxdefault"> edge</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">start</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">position</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">offset</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> edge</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">line</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">],</span><span class="syntaxdefault"> edge</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">length </span><span class="syntaxkeyword">/</span><span class="syntaxdefault"> 2 </span><span class="syntaxkeyword">)<br />}<br /></span><span class="syntaxdefault">puts </span><span class="syntaxstring">"Midpoint by offset; #{Time.now - t}s"<br /><br /></span><span class="syntaxdefault">t </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Time</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">now<br />mid_points3 </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">grep</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Edge</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">{</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">|</span><span class="syntaxdefault">edge</span><span class="syntaxkeyword">|<br /></span><span class="syntaxdefault"> Geom</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">linear_combination</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> 0.5</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> edge</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">start</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">position</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 0.5</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> edge</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">end</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">position </span><span class="syntaxkeyword">)<br />}<br /></span><span class="syntaxdefault">puts </span><span class="syntaxstring">"Midpoint by linear_combination; #{Time.now - t}s"<br /></span><span class="syntaxdefault"></span>
Edges: 474629 Edge collection: 0.437s Midpoint by bounds: 0.655s Midpoint by offset: 2.153s Midpoint by linear_combination: 1.716s
Using bounds are clearly the fastest. And so much faster than
linear_combination
which I used that I got some refactoring to do. -
And 3d point results are identical.
-
@unknownuser said:
Edges: 474629
Edge collection: 0.437s
Midpoint by bounds: 0.655s
Midpoint by offset: 2.153s
Midpoint by linear_combination: 1.716sThat is quite some speed increase! Relatively speaking...
Lets just hope the method itself is accurate enough when putting it to use.
I have been using this method last couple of hours for testing with cpoints here and there,
and so far appears correct behavior.Thanks for testing
Every dirt one can polish off is good, huh?
-
@jolran said:
Lets just hope the method itself is accurate enough when putting it to use.
Well, I did compare the results of each of the midpoints for all the 474629 edges in my test model (an imported AutoCAD drawing) and they where exactly the same.
-
The speed difference results in that it's doing less - and all the work is done in C. While the method I had used, and your offset method, was doing more - partially in Ruby.
-
@unknownuser said:
The speed difference results in that it's doing less - and all the work is done in C. While the method I had used, and your offset method, was doing more - partially in Ruby.
Yeah, thats probably true.
Anyway, speed increase is always good.
I'll switch to this method and report back if any oddities.Cheers.
Advertisement