# Valid Camera Ratio

**URL:** <https://forum.techsoft3d.com/t/valid-camera-ratio/4305>\
**Category:** HOOPS Visualize Desktop\
**Tags:** code, knowledge-base, how-to, camera\
**Created:** [January 1, 2025, 12:23am UTC](https://forum.techsoft3d.com/t/valid-camera-ratio/4305 "2025-01-01T00:23:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mike](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.techsoft3d.com/mike/32/228_2.png) [@mike](https://forum.techsoft3d.com/u/mike)\
**Post date:** [January 1, 2025, 12:23am UTC](https://forum.techsoft3d.com/t/valid-camera-ratio/4305/1 "2025-01-01T00:23:13Z")

</div>

**Camera Setup Guidelines** (in [3DF](https://docs.techsoft3d.com/3df/latest/prog_guide/3dgs/03_2_viewing_modelling_cameras.html#camera-setup-guidelines) and [HPS](https://docs.techsoft3d.com/hps/latest/prog_guide/0303_cameras.html#camera-set-up-guidelines)) recommend “the distance from the camera _position_ to the camera _target_ should be 2.5 times the _field width_.” This is known as the camera ratio.

When the camera ratio is much greater than 2.5, the scene’s visual integrity may degrade (artifacts including edge stitching and edge shine-through). For example, the strange rendering in the scene below comes from a **very large** camera ratio. The inset scene uses a very similar camera with a valid camera ratio.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/techsoft3d/original/2X/8/82f92fc730b4073e3e616ca3507320c3e04af334.jpeg)

The documentation describes a processes for computing valid camera settings.

The following code illustrates how to validate camera settings in the 3DF Part Viewer

```auto
// 3DF - ...\demo\mfc\partviewer_common\CSolidHoopsView.cpp
bool IsValidCamera(HC_KEY sceneKey, float *cameraRatio)
{
    HPoint camera, target;
    float width, h;
    HC_Open_Segment_By_Key(sceneKey);
    HC_Show_Camera_Position(&camera.x, &camera.y, &camera.z);
    HC_Show_Camera_Target(&target.x, &target.y, &target.z);
    HC_Show_Camera_Field(&width, &h);
    HC_Close_Segment();
    HVector viewVector = target - camera;
    *cameraRatio = (float)HC_Compute_Vector_Length(&viewVector) / width;
    return (abs(2.5 - *cameraRatio) < 0.01);
}

void CSolidHoopsView::OnExtraSlot1()
{
    float cameraRatio = 0;
    if (!IsValidCamera(GetSceneKey(), &cameraRatio))
    {
        wchar_t message[MVO_BUFFER_SIZE + 1] = { L"" };
        swprintf(message, MVO_BUFFER_SIZE, L"INVALID CAMERA\n%g.", cameraRatio);
        MessageBox(H_TEXT(message), _T("ERROR!"), MB_OK);
    }
}

```

and the HPS MFC Sandbox

```auto
// HPS - ...\samples\mfc_sandbox\CHPSView.cpp
bool IsValidCamera(HPS::CameraKit camera, float *cameraRatio)
{
	HPS::Point position, target;
	float width, height;
	camera.ShowPosition(position);
	camera.ShowTarget(target);
	camera.ShowField(width, height);
	HPS::Vector viewVector = target - position;
	*cameraRatio = viewVector.Length() / width;
	return (abs(2.5 - *cameraRatio) < 0.01);
}

void CHPSView::OnUserCode1()
{
	HPS::CameraKit theCamera;
	GetCanvas().GetFrontView().GetSegmentKey().ShowCamera(theCamera);
	float cameraRatio = 0;
	if (!IsValidCamera(theCamera, &cameraRatio))
	{
		CString message;
		message.Append(L"INVALID CAMERA\n");
		message.AppendFormat(L"%g", cameraRatio);
		MessageBox(message, _T("ERROR!"), MB_OK);
	}
}

```
