Edge Center

Edge Center

Postby jolran » Tue Mar 05, 2013 12:08 am

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, orientation :?

So would edge_center = edge.bounds.center.project_to_line(edge.line[1]) be superfluous ?
0
User avatar
jolran 
PluginStore Author
PluginStore Author
 

Re: Edge Center

Postby thomthom » Tue Mar 05, 2013 9:45 am

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.
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: Edge Center

Postby jolran » Tue Mar 05, 2013 10:43 am

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 :D
0
User avatar
jolran 
PluginStore Author
PluginStore Author
 

Re: Edge Center

Postby thomthom » Tue Mar 05, 2013 1:09 pm

Code: Select all

model 
= Sketchup.active_model
entities 
= model.active_entities

= Time.now
edges 
= entities.grep(Sketchup::Edge)
puts "Edges: #{edges.size}"
puts "Edge collection: #{Time.now - t}s"

= Time.now
mid_points1 
= entities.grep(Sketchup::Edge) { |edge|
  edge.bounds.center
}
puts "Midpoint by bounds: #{Time.now - t}s"

= Time.now
mid_points2 
= entities.grep(Sketchup::Edge) { |edge|
  edge.start.position.offset( edge.line[1], edge.length / 2 )
}
puts "Midpoint by offset: #{Time.now - t}s"

= Time.now
mid_points3 
= entities.grep(Sketchup::Edge) { |edge|
  Geom.linear_combination( 0.5, edge.start.position, 0.5, edge.end.position )
}
puts "Midpoint by linear_combination: #{Time.now - t}s"


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.

MidpointPerformance.png
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: Edge Center

Postby thomthom » Tue Mar 05, 2013 1:31 pm

And 3d point results are identical.
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: Edge Center

Postby jolran » Tue Mar 05, 2013 2:52 pm

Edges: 474629
Edge collection: 0.437s
Midpoint by bounds: 0.655s
Midpoint by offset: 2.153s
Midpoint by linear_combination: 1.716s


:shock:

That 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 :thumb:

Every dirt one can polish off is good, huh?
0
User avatar
jolran 
PluginStore Author
PluginStore Author
 

Re: Edge Center

Postby thomthom » Tue Mar 05, 2013 3:07 pm

jolran wrote: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.
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: Edge Center

Postby thomthom » Tue Mar 05, 2013 3:10 pm

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.
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: Edge Center

Postby jolran » Tue Mar 05, 2013 5:36 pm

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.
0
User avatar
jolran 
PluginStore Author
PluginStore Author
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 



 

Return to Developers' Forum

Who is online

Users browsing this forum: Google Bot and 2 guests

Visit our sponsors: