Click or drag to resize
AB4D logo

BaseCameraLine3DTo2D Method (Point3D, Point3D, Size, Point, Point)

Converts a 3D line that is defined by startPositionWorld and endPositionWorld to a line on the screen that is defined by startPositionScreen and endPositionScreen. The method takes a custom Viewport3D size and does not require that this Camera class is connected to real Viewport3D. This method correctly handles the case when the 3D line crosses the camera near plane (goes behind the camera). In this case the line needs to be cropped at the camera near plane.

Namespace:  Ab3d.Cameras
Assembly:  Ab3d.PowerToys (in Ab3d.PowerToys.dll) Version: 10.1.8147.1045
Syntax
C#
public bool Line3DTo2D(
	Point3D startPositionWorld,
	Point3D endPositionWorld,
	Size viewportSize,
	out Point startPositionScreen,
	out Point endPositionScreen
)

Parameters

startPositionWorld
Type: System.Windows.Media.Media3DPoint3D
start position of the 3D line
endPositionWorld
Type: System.Windows.Media.Media3DPoint3D
end position of the 3D line
viewportSize
Type: System.WindowsSize
Size of the Viewport3D
startPositionScreen
Type: System.WindowsPoint
start position of the 2D line on the screen
endPositionScreen
Type: System.WindowsPoint
end position of the 2D line on the screen

Return Value

Type: Boolean
true if the line was successfully converted to screen line; false otherwise (for example when TargetViewport3D is not set)
Remarks

Converts a 3D line that is defined by startPositionWorld and endPositionWorld to a line on the screen that is defined by startPositionScreen and endPositionScreen.

The method takes a custom Viewport3D size and does not require that this Camera class is connected to real Viewport3D.

This method correctly handles the case when the 3D line crosses the camera near plane (goes behind the camera). In this case the line needs to be cropped at the camera near plane.

The matrix to convert 3D point to 2D point is calculated from the used Ab3d.Camera. The matrix value is cached and is only recalculated when the camera is changed.

If the matrix to convert 3D point to 2D point cannot be calculated (for example if TargetViewport3D is not set), the calculated points will be Point(double.NaN, double.NaN) and the method will return false as a result.

With this method you can convert 3D coordinates to 2D space without creating read Viewport3D and attaching the camera to it. The following example shows how to do that:

Examples
var targetPositionCamera = new Ab3d.Cameras.TargetPositionCamera()
{
    Heading = 30,
    Attitude = -20,
    Distance = 200
};

Point startPositionScreen, endPositionScreen;
bool success = targetPositionCamera.Line3DTo2D(new Point3D(100, 100, 100), new Point3D(200, 100, 100), new Size(200, 100), out startPositionScreen, out endPositionScreen);
See Also