@maisoui wrote:
Finally I found a solution. Maybe it could help somebody:
private IList<XYZ> computeBound(BoundingBoxXYZ box, Plane plane)
{
double width = box.Max.X - box.Min.X;
double height = box.Max.Y - box.Min.Y;
IList<XYZ> points = new List<XYZ>();
points.Add(box.Transform.OfPoint(box.Min));
points.Add(points[points.Count - 1].Add(plane.XVec.Multiply(width)));
points.Add(box.Transform.OfPoint(box.Max));
points.Add(points[points.Count - 1].Subtract(plane.XVec.Multiply(width)));
//project points on plane
for(int i = 0; i < points.Count; ++i)
{
points[i] = plane.ProjectOnto(points[i]);
}
return points;
}
To project a point on a plane, read this : http://thebuildingcoder.typepad.com/blog/2014/09/planes-projections-and-picking-points.html
It helped me, but I had to do a few adjustments, depending on the view direction:
Public Const _eps As Double = 0.000000001
Private Function ComputeBound(box As BoundingBoxXYZ, plane As Plane, reverse As Boolean) As IList(Of XYZ)
Dim width As Double = box.Max.X - box.Min.X
Dim height As Double = box.Max.Y - box.Min.Y
Dim points As IList(Of XYZ) = New List(Of XYZ)()
points.Add(box.Transform.OfPoint(box.Min))
Dim vector As XYZ
If Math.Abs(plane.Normal.X) < _eps Then
vector = New XYZ(width, 0, 0)
Else
vector = plane.XVec.Multiply(width)
End If
If reverse Then vector = vector.Multiply(-1)
points.Add(points(points.Count - 1).Add(vector))
points.Add(box.Transform.OfPoint(box.Max))
points.Add(points(points.Count - 1).Subtract(vector))
For i As Integer = 0 To points.Count - 1
points(i) = plane.ProjectOnto(points(i))
Next
Return points
End Function
My criterion for reversing is:
Dim reverse As Boolean
If View.RightDirection.X < 0 Then reverse = True