Can't make Plane.IntersectWithPlane work

Can't make Plane.IntersectWithPlane work

DonStauffer99
Advocate Advocate
208 Views
3 Replies
Message 1 of 4

Can't make Plane.IntersectWithPlane work

DonStauffer99
Advocate
Advocate

I can't figure this out, mainly because of the nonspecific error message "the parameter is incorrect". That happens on the last line in this code, but I did find out that the line returned by IntersectWithPlane apparently has a direction of (0, 0, 0). That shouldn't necessarily cause an error when used in CreatePlane, but it doesn't look right. But in any case, no matter what I try I can't get that CreatePlane line to work. I'd appreciate any suggestions.

	Dim TG As Inv.TransientGeometry = ThisApplication.TransientGeometry
	
	Dim TargPoint As Point
	TargPoint = TG.CreatePoint(1, 1, 1)
	
	Dim StartPoint As Point
	StartPoint = TG.CreatePoint(2, 2, 1)
	
	Dim EndPoint As Point
	EndPoint = TG.CreatePoint(-1, -1, 1)

        '   Create the X-Axis vector

        Dim XYScanPlane As Inv.Plane
        XYScanPlane = TG.CreatePlaneByThreePoints(TargPoint, StartPoint, EndPoint)

        Dim X As Double
        Dim Y As Double
        Dim Z As Double
        X = StartPoint.X - TargPoint.X
        Y = StartPoint.Y - TargPoint.Y
        Z = StartPoint.Z - TargPoint.Z
        Dim XAxisVect As Inv.Vector = TG.CreateVector(X, Y, Z)
		
        Dim YZScanPlane As Inv.Plane
        YZScanPlane = TG.CreatePlane(TargPoint, XAxisVect)

        Dim YAxisLine As Inv.Line
        YAxisLine = XYScanPlane.IntersectWithPlane(YZScanPlane) ' This is likely the problem
		
		Dim RootPoint As Point = YAxisLine.RootPoint
		
		Logger.Debug("Root Point: " & RootPoint.X & ", " & RootPoint.Y & ", " & RootPoint.Z & ")")
		
		Dim YAxisUnit As Inv.UnitVector = TG.CreateUnitVector
		YAxisUnit= YAxisLine.Direction()
		Logger.Debug("Unit: " & YAxisUnit.X & ", " & YAxisUnit.Y & ", " & YAxisUnit.Z)
		
        Dim YAxisVect As Inv.Vector = TG.CreateVector(0, 0, 0)
		YAxisVect = YAxisUnit.AsVector()
		
		Logger.Debug("Vect: " & YAxisVect.X & ", " & YAxisVect.Y & ", " & YAxisVect.Z)

        Dim XZScanPlane As Inv.Plane
        XZScanPlane = TG.CreatePlane(TargPoint, YAxisVect)
0 Likes
209 Views
3 Replies
Replies (3)
Message 2 of 4

DonStauffer99
Advocate
Advocate

More info:

I changed the test point (-1, -1, 1) to (-1, -1, 0), thus making XYScanPlane no longer parallel to the origin XY Plane, and the error went away. But it seems to me that shouldn't have caused an error. I'm really not sure if this function is just unreliable and fails with certain inputs when it shouldn't, or if there's something I'm missing and I'm actually sending invalid data.

0 Likes
Message 3 of 4

DonStauffer99
Advocate
Advocate

I'm discovering that the TransientGeometry.CreatePlaneByThreePoints method produces an invalid plane if all 3 of the points has at least one coordinate that's the same. In other words, if the plane will be parallel to one of the 3 standard "origin" planes.

Specifically, it constructs a plane whose Normal is (0, 0, 0). As far as I can tell, that's just wrong, unless maybe the plane is EQUAL to one of the 3 standard planes (which I haven't tested). As long as no more than one coordinate is the same across all 3 points, the points are not collinear, so they define a plane, mathematically speaking.

 

I'm thinking the fix is, after constructing the plane using CreatePlaneByThreePoints, I test the points, and if I find all 3 have the same Z coordinate, for example, I set the normal for the plane to (0, 0, 1). Something like this, although I'm not sure about equality testing floating points:

	Dim P As Plane
	P = TG.CreatePlaneByThreePoints(P1, P2, P3)
	
	If P1.X = P2.X And P2.X = P3.X Then
		P.Normal = TG.CreateUnitVector(1, 0, 0)
	ElseIf P1.Y = P2.Y And P2.Y = P3.Y Then
		P.Normal = TG.CreateUnitVector(0, 1, 0)
	ElseIf P1.Z = P2.Z And P2.Z = P3.Z Then
		P.Normal = TG.CreateUnitVector(0, 0, 1)
	End If

 

0 Likes
Message 4 of 4

DonStauffer99
Advocate
Advocate

In this case, I think equality checking Doubles may be OK since that seems to be the root of the bug. That is, if they don't test as equal, the plane created should probably be valid since it wouldn't be precisely parallel to an origin plane. It would just be almost parallel and should have a valid direction, I hope.

0 Likes