Is This A Valid Plane Definition

I have 4 Rhino points (Origin, X, Y, and Z) that I’m using to define a plane. The problem is that when they are mirrored across the X or Y, the Z vector of the plane becomes inverted. I can check for the invert by comparing the vector of Origin to Z against the Z vector from PlaneFromPoints(Origin, X, Y) .

  • Is it valid to just swap out the plane’s z vector with the correct value?
  • What’s the correct way to create the correct plane?
  • How are the zero values in a vector negative?

See code below:


        Sub HelpMyPlanesInverted()
    	
    	Dim pts(3), mirrorPts(3), plane, i, xform, vector
    	pts(0) = Array(5, 5, 5) 'origin'
    	pts(1) = Array(6, 5, 5) 'x'
    	pts(2) = Array(5, 6, 5) 'y'
    	pts(3) = Array(5, 5, 6) 'z'
    
    	plane = Rhino.PlaneFromPoints(pts(0), pts(1), pts(2))
    	Print "Correct Plane:", plane
    	'	Correct Plane:'
    	'	5.000, 5.000, 5.000 '
    	'	1.000, 0.000, 0.000 '
    	'	0.000, 1.000, -0.000' 
    	'	- 0.000, 0.000, 1.000' 
    	
    	xform = Rhino.XformMirror(Array(0, 0, 0), Array(1, 0, 0))
    	
    	For i = 0 To 3
    		mirrorPts(i) = Rhino.PointTransform(pts(i), xform)	
    	Next
    	Print "Mirrored Pts:", mirrorPts
    	'	Mirrored Pts:'
    	'	- 5.000, 5.000, 5.000 '
    	'	- 6.000, 5.000, 5.000 '
    	'	- 5.000, 6.000, 5.000 '
    	'	- 5.000, 5.000, 6.000 '
    	
    	plane = Rhino.PlaneFromPoints(mirrorPts(0), mirrorPts(1), mirrorPts(2))
    	Print "Upside down plane:", plane
    	'	Upside down plane:'
    	'	-5.000, 5.000, 5.000' 
    	'	- 1.000, 0.000, 0.000' 
    	'	0.000, 1.000, -0.000 '
    	'	- 0.000, -0.000, -1.000 '
    		
    	vector = Rhino.VectorCreate(pts(3), pts(0))
    	plane(3) = vector
    	Print "Is this a valid plane?", plane
    	'	Is this a valid plane?'
    	'	-5.000, 5.000, 5.000 '
    	'	- 1.000, 0.000, 0.000' 
    	'	0.000, 1.000, -0.000 '
    	'	0.000, 0.000, 1.000 '
    
        End Sub
    
        Sub Print(label, pts)
    	
    	Rhino.Print label
    	Dim pt 
    	For Each pt In pts
    		Rhino.Print Rhino.Pt2Str(pt, , True)
    	Next

        End Sub

In the mean time, I coded this to use for the time being. Not sure why I couldn’t mirror the points.

I am new to transforms and I am constantly scratching my head.


	i = 0
	Do While Rhino.VectorCompare(Rhino.VectorCreate(mirrorPts(3), mirrorPts(0)), plane(3)) <> 0
		
		'with origin (0,0,0) and for points (1,1,1)'
		'i=0 - flip the x across the y (-1,1,1)'
		'i=1 - flip the y across the x (-1,-1,1)'
		'i=2 - flip the x across the y (1,-1,1)'
		'i=3 - that should have to solve it, but just in case reset them to (1,1,1), null the plane and quit the loop'
		
		If i Mod 2 = 0 Then
			xform = Rhino.XformMirror(mirrorPts(0), mirrorPts(1)) '???could not get this mirror to work and no idea why'
			xform = Rhino.XformTranslation(Rhino.VectorScale(Rhino.VectorReverse(plane(1)), 2))
			mirrorPts(1) = Rhino.PointTransform(mirrorPts(1), xform)
		Else
			xform = Rhino.XformTranslation(Rhino.VectorScale(Rhino.VectorReverse(plane(2)), 2))
			mirrorPts(2) = Rhino.PointTransform(mirrorPts(2), xform)
		End If
		
		plane = Rhino.PlaneFromPoints(mirrorPts(0), mirrorPts(1), mirrorPts(2))
		i = i + 1
		
		If i = 3 Then 
			plane = Null
			Exit Do
		End If 
		
	Loop
	Print "Corrected plane:", plane
	'Corrected plane:'
	'-5.000,5.000,5.000 '
	'1.000,0.000,0.000 '
	'0.000,1.000,-0.000' 
	'-0.000,0.000,1.000'

To answer your initial questions:

It is best, in my experience, to define a plane by an origin point and a normal vector. In your case, the normal vector is created by taking the vector outer product of the vectors (y-x) and (z-x), resulting in an inverted normal when one or more points are mirrored. If you define it by origin and normal vector you are in control.

Negative zero is, of itself, a valid floating point value in a computer. But it could also be a rounding error ( e.g. -0.000000000002134324).

I don’t know how to say this the right way in terms of a vector, but I need the absolute value of X and Y along with the origin and correct normal of Z. That is what’s important for the purpose of the plane I’m constructing. In my second post, reversing the X or Y or XY of the points and scaling twice is working perfectly. The magnitude of XYZ is also important, as I can compare that to a unitized vector for other operations.