Coordinates of a vector-cross-point?
-
hi,
when i generate a crosspoint from two lines:ector = @centerpointline_left.start.position.vector_to(@centerpointline_left.end.position) vector.length = @centerpointline_left.length vector2 = @centerpointline_right.start.position.vector_to(@centerpointline_right.end.position) vector2.length = @centerpointline_right.length v = vector.cross vector2
where the centerpoint-lines are 100% crossing,
i get the point v (sort of virtual point, i think).but now i would like to place a c_point at this position
this:
point1 = Geom;;Point3d.new v
does not work.
also the
d = vector.dot vector2
does not give me the point.
thanx for helping.
stanedit 1 : now i understand, that v is also a vector. the problem is still, how to place the 3d-point!
thanx for ideas.
-
You could use the Geom module - intersect a line with a line - will give you a point.
http://www.sketchup.com/intl/en/developer/docs/ourdoc/geom.php#intersect_line_line
-
hi tt,
yes, i was just about to put edit 2 in the text:entities2 = Sketchup.active_model.entities @centerpointline_left = entities2.add_line @bottom_c_point1_l,@bottom_m_point2_l @centerpointline_right = entities2.add_line @bottom_c_point1_r,@bottom_m_point2_r point = Geom.intersect_line_line (@centerpointline_left, @centerpointline_right)
the lines are created, the crosspoint is there (can catch a line),
but ruby conole still reports
"
Error: #<TypeError: wrong argument type Sketchup::Edge (expected Array)>
C:/Program Files/Google/Google SketchUp 8/Plugins/01.rb:3783:inintersect_line_line' C:/Program Files/Google/Google SketchUp 8/Plugins/01.rb:3783:in
top_handrails'
C:/Program Files/Google/Google SketchUp
"stan
-
A "line" in the Ruby API means something very different from an Edge. The Geom module instruction gives you examples that a line can be an array of two point or an array of a point and a vector. Lines and planes are infinite.
If you want to see if two edges intersect you first use the edge'slines to see if they intersect, then you must ensure the resulting point in between the edges vertices.
Geom.intersect_line_line(edge1.line, edge2.line)
(Btw, no space between method name and parentheses. Ruby yields warnings about this and they should not be ignored. They are potential source of bugs.)
Unfortunately there is one inconsistency in the Ruby API regarding line vs edge, Entities.add_line - it should have been named Entities.add_edge. Other than that a line and edge is very different concepts.
-
TT beat me to it, but here goes anyway...
You are misunderstanding the results of a 'cross' [which gives you a 'vector3d' not a 'point3d'] AND the difference between an 'edge' and a 'line'.
An 'edge' has a 'line'...
line = edge.line
A line consists of an array of a point and a vector3d - effectively:
[edge.start.position, edge.start.position.vector_to(edge.end.position)]
but easier to get !
Conversely you can get the edge's start_point and its vector from its line...
line = edge.line start_point = line[0] vector = line[1]
To find the intersection of two edges' lines use:
**point =**Geom::intersect_line_line(@centerpointline_left**.line**, @centerpointline_right**.line**)
The '
point
' is either a point3d ornil
when they do not intersect.
The point3d may not be on either of the edges...
I am sure I have previously explained to you how to determine this...
Here are the bones...
You don't have a point - so the edges do not have intersecting lines.
Alternatively you have a point, so we know that the edges' lines intersect.
To see if that point falls on an edge...
Get the vectors between that point and thev0=point.vector_to(edge.start_position
andv1=point.vector_to(edge.end.position)
...if vv0==v1
then the point is somewhere OFF the line.
And alsoif v0.length==0
that point is exactly on the edge.start vertex,
if v1.length==0
that point is exactly on the edge.end vertex.
If there are NO zero lengths for v0 or v1 and v0!=v1, then that point is on the edge, somewhere between its start and end vertices...Also do NOT leave a space between the method and it () arguments!
-
hi tt & tig,
thanx for that, i am going to dive now into the deep space line for the edges and hopefuly come back much smarter than before!thanx for the great help!!! what would all the ruby - manuals be without you all in this forum....
stan
-
A bit of a semi-sequiter this one coming from Haine's Udacity Course on 3d Graphics. Traditionally points are stored with a 4 value list/array with the 4th value being 1 while vectors are stored also in a 4 value list/array with the 4th value being 0. Consequently if you subtract two points you get vector, if you add two vectors you get a vector and if you add a point to vector...you get a point. Adding two points gives you a 2 in the last position in an array which would be nonsensical. I am curious if this is the underlying data structure in sketchup as well?
Youtube Video -
hi and thanx, this is interesting, for me still a bit too high, although i understand it basically, but the time will come.....
btw., i could solve my problem and can now generate points at the cross-point of lines (from edges).
thanx to all, once again.
stan -
@mptak said:
A bit of a semi-sequiter this one coming from Haine's Udacity Course on 3d Graphics. Traditionally points are stored with a 4 value list/array with the 4th value being 1 while vectors are stored also in a 4 value list/array with the 4th value being 0. Consequently if you subtract two points you get vector, if you add two vectors you get a vector and if you add a point to vector...you get a point. Adding two points gives you a 2 in the last position in an array which would be nonsensical. I am curious if this is the underlying data structure in sketchup as well?
Youtube VideoIt isn't documented that I am aware of (the Point3d and Vector class internals are opaque), but given the way that transformations are constructed it seems very likely that SketchUp follows this convention - at least for points. That is, transformations are represented using 4x4 matrices, allowing application to a point via a standard matrix multiply.
Sorry, Stan, that probably went over your head too
Steve
-
oh yes, and how it went......i am just about to begin to understand the basics.but i am proud of having the first version of my ruby nearly finished. the code is still more linear then intelligent, but will be improved step by step.
and one day, who knows, i also can deal with metrices in the 5th dimension.
merry x-mass
stan
Advertisement