Fit_plane_to_points problem
-
Hi guys, I'm trying to adjust hundreds of points to a plane, my problem is that I do not understand the output format fit_plane_to_points, I expected a Point3d and Vector3D, but it seems I get different, I do not know how to interpret the result, appreciate the help in advance
point1 = Geom::Point3d.new 0,0,0 point2 = Geom::Point3d.new 1,2,3 point3 = Geom::Point3d.new 5,5,5 plane = Geom.fit_plane_to_points point1, point2, point3 plane.size
-
The plane is returned as an
[A,B,C,D]
Array of 4 numbers which are the coefficients of the plane equationA
x +B
y +C
z +D
= 0. -
Fit plane to Points returns a plane on which you can use SU-API methods.
It also returns what Dan said.A plane is infinite, and so is a Line [point3d, vector]
I suspect what you acctually want to do is Project your Points on to that plane with the point.project_to_plane method?
-
thank you very much Dan, is exactly what I needed
thank jolran, that's not my next step, but I thank you, I had not seen the command project_to_plane
-
I thought of a way to put the plane in the format [point, vector], at some point it might be useful to someone
p1 = Geom;;Point3d.new 1,1,1 p2 = Geom;;Point3d.new 2,1,1 p3 = Geom;;Point3d.new 1,2,1 p4 = Geom;;Point3d.new 1,2,0 pl = Geom.fit_plane_to_points p1, p2, p3, p4 tolerance = 0.0001 if pl[2].abs > tolerance point = Geom;;Point3d.new(0,0,-pl[3]/ pl[2]) elsif pl[1].abs > tolerance point = Geom;;Point3d.new(0,-pl[3]/ pl[1],0) else point = Geom;;Point3d.new(-pl[3]/ pl[0],0,0) end vector = Geom;;Vector3d.new(pl[0],pl[1],pl[2]) plane = [point,vector]
-
@unknownuser said:
thank jolran, that's not my next step, but I thank you, I had not seen the command project_to_plane
Ahh, I see. You ARE just interested in getting Point and vector, for some reason.
Then if I'm not misstaken I think p4 is redudant in you calculation ?
You only have to feed 3 Points for fit_plane_to_points.
-
<span class="syntaxdefault"> </span><span class="syntaxcomment"># Returns +plane+ in the format +[ point3d, vector3d ]+.<br /> #<br /> # @param [Array<Geom;;Point3d, Geom;;Vector3d>, Array<Number, Number, Number, Number>] plane<br /> #<br /> # @return [Array<Geom;;Point3d, Geom;;Vector3d>]<br /> # @since 2.0.0<br /> </span><span class="syntaxdefault">def self</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">normalize_plane</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">plane</span><span class="syntaxkeyword">)<br /> return </span><span class="syntaxdefault">plane </span><span class="syntaxkeyword">if </span><span class="syntaxdefault">plane</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">length </span><span class="syntaxkeyword">== </span><span class="syntaxdefault">2<br /> a</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">b</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">c</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">d </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">plane<br /> v </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">Geom</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Vector3d</span><span class="syntaxkeyword">.new(</span><span class="syntaxdefault">a</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">b</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">c</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">p </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">ORIGIN</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">offset</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">v</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">reverse</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">d</span><span class="syntaxkeyword">)<br /> return [</span><span class="syntaxdefault">p</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">v</span><span class="syntaxkeyword">]<br /> </span><span class="syntaxdefault">end<br /></span>
-
@dacastror said:
I expected a Point3d and Vector3D, but it seems I get different,
The definition of a plane in SketchUp is described in the introduction to
Geom3d
: sketchucation.com/forums/posting.php?mode=quote&f=180&p=485589@unknownuser said:
A line can be represented as either an Array of a point and a vector, or as an Array of two points.
<span class="syntaxdefault"> line </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">[</span><span class="syntaxdefault">Geom</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Point3d</span><span class="syntaxkeyword">.new(</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">),<br /></span><span class="syntaxdefault"> Geom</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Vector3d</span><span class="syntaxkeyword">.new(</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">)]<br /></span><span class="syntaxdefault"> line </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">[</span><span class="syntaxdefault">Geom</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Point3d</span><span class="syntaxkeyword">.new(</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">),<br /></span><span class="syntaxdefault"> Geom</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Point3d</span><span class="syntaxkeyword">.new(</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">100</span><span class="syntaxkeyword">)]</span><span class="syntaxdefault"> </span>
A plane can be represented as either an Array of a point and a vector, or as an Array of 4 numbers that give the coefficients of a plane equation.
<span class="syntaxdefault"> plane </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">[</span><span class="syntaxdefault">Geom</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Point3d</span><span class="syntaxkeyword">.new(</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">),<br /></span><span class="syntaxdefault"> Geom</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Vector3d</span><span class="syntaxkeyword">.new(</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">)]<br /></span><span class="syntaxdefault"> plane </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">[</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">]</span><span class="syntaxdefault"> </span>
-
I did not understand point.offset, with this example I understand a little more, thank you very much Thom, very interesting this
Advertisement