Error Drawing Lines
-
Dear all,
I'm facing an issue I can't understand.
These two codes should produce the same result.Here is the code that does not draw the correct lines :
(no line is drawn from pt2 to pt1 and this line is replaced by one joining pt3, pt1)pt1 = Geom::Point3d.new(0.98787,0.926013,0)
pt2 = Geom::Point3d.new(0.988135,0.925025,0)
pt3 = Geom::Point3d.new(0.977696,0.924673,0)
Sketchup.active_model.entities.add_line(pt3,pt2)
Sketchup.active_model.entities.add_line(pt2,pt1)And what I got when running it in the console
If I reverse the order lines are drawing, I got the correct result.
pt1 = Geom::Point3d.new(0.98787,0.926013,0)
pt2 = Geom::Point3d.new(0.988135,0.925025,0)
pt3 = Geom::Point3d.new(0.977696,0.924673,0)
Sketchup.active_model.entities.add_line(pt1,pt2)
Sketchup.active_model.entities.add_line(pt2,pt3)
I was thinking of something linked to the precision of SU but cant explain if its the limit why the one code produces the correct result and the other not.
Any idea appreciated.
Yours
Pascal -
@ppoublan said:
Dear all,
I'm facing an issue I can't understand.
These two codes should produce the same result.Here is the code that does not draw the correct lines :
(no line is drawn from pt2 to pt1 and this line is replaced by one joining pt3, pt1)pt1 = Geom::Point3d.new(0.98787,0.926013,0)
pt2 = Geom::Point3d.new(0.988135,0.925025,0)
pt3 = Geom::Point3d.new(0.977696,0.924673,0)
Sketchup.active_model.entities.add_line(pt3,pt2)
Sketchup.active_model.entities.add_line(pt2,pt1)And what I got when running it in the console
[attachment=1:24mkndsa]<!-- ia1 -->error.JPG<!-- ia1 -->[/attachment:24mkndsa]If I reverse the order lines are drawing, I got the correct result.
pt1 = Geom::Point3d.new(0.98787,0.926013,0)
pt2 = Geom::Point3d.new(0.988135,0.925025,0)
pt3 = Geom::Point3d.new(0.977696,0.924673,0)
Sketchup.active_model.entities.add_line(pt1,pt2)
Sketchup.active_model.entities.add_line(pt2,pt3)
[attachment=0:24mkndsa]<!-- ia0 -->correct.jpg<!-- ia0 -->[/attachment:24mkndsa]I was thinking of something linked to the precision of SU but cant explain if its the limit why the one code produces the correct result and the other not.
Any idea appreciated.
Yours
Pascalpt1 and pt2 are less than 0.001" apart so Sketchup treats them as the same point.
-
Hi sdmitch,
Sorry but do not think this is the reason cause :- pt1/pt2 distance is 0.0010229217956422459 inches, so equal or above 0.001 inches
- if it was the reason, the second code would not produce different result
- and last, in both codes, the 3 different points are correctly setup by SU, just the joining lines are incorrect
...
Still looking for a solution. I could add to my code to test minimum distance longer than 0.001 inches, but in this case this would not solve the issue.
Pascal
-
Same results while using entities.add_curve ?
-
@ppoublan said:
Sorry but do not think this is the reason cause :
- pt1/pt2 distance is 0.0010229217956422459 inches, so equal or above 0.001 inches
It is not the distance between points, it is the position of the vertices in the model.
Note that the model hasSketchup::Vertex
objects, notGeom::Point3d
objects.Geom::Point3d
objects are only virtual helper objects.` xd = 0.988135 - 0.98787
0.0002649999999999597yd = 0.926013 - 0.925025
0.0009879999999999889pt1.x == pt2.x
truept1.y == pt2.y
true` -
Thanks Dan,
But then how could you explain the second example works fine ? -
I think what you are seeing is a "capture effect" that happens as SketchUp post-processes the geometry to see whether a new Edge intersects or lies atop part of an existing Edge. When the new Edge passes "close enough" to a Vertex of an existing Edge, SketchUp decides they were meant to intersect at that Vertex and modifies them to make it so. In your case this amounted to redefining the Edge from pt3 to pt2 to end at pt1 instead (!). I haven't figured out the logic behind which nearby Vertex SketchUp chooses (i.e. why shift from pt2 to pt1?), but suspect it is sensitive to the order in which the Vertices are stored in some data structure, and the order depends on the order and direction in which you drew the Edges. That would explain why one of your cases works and the other gets captured.
I've seen similar effects in other situations such as when a new Edge passes near but not absolutely through the end of a previous one, but gets "bent" over to that end and split into two segments (this causes nasty subtle errors in some people's floorplans when they draw a bit carelessly!). There was also a post a while back in which a new Edge tried to go to a Vertex of a circle and got "sucked" over to the next one because the Edge passed too close to it.
The bottom line is that it is always dangerous to create geometry at sizes near SketchUp's 0.001 tolerance. It isn't worth arguing about whether the Vertices are .00002 over, since the actual tolerance logic isn't explained anywhere. Just don't try to create geometry at that sort of size. Scale up, create it, then scale down.
-
Better understand. Thanks slb for these explanation.
I Cant use scaling in this case as the points are the result of crossing lines, so at any scale the resulting point of two lines crossing can be very close to any other point in the model.
This gave me an idea for a very bad workaround. Do not like it, but it works. this way SU does not seem to try sharing same vertex...
pt1 = Geom::Point3d.new(0.98787,0.926013,0)
pt2 = Geom::Point3d.new(0.988135,0.925025,0)
pt3 = Geom::Point3d.new(0.977696,0.924673,0)
grp1 = Sketchup.active_model.entities.add_group
grp1.entities.add_line(pt3,pt2)
grp2 = Sketchup.active_model.entities.add_group
grp2.entities.add_line(pt2,pt1)
grp1.explode
grp2.explodeThks again
Pascal
Advertisement