I have included my original post below and you may want to refer there for a
picture and description of the algorithm I am using.
In essence, I want to find a point that is far enough from a given line
segment that the end points of the whole segment can be connected by two
other line segments forming a triangle whose tip is a given angle in
radians.
For example, I have a line whose length is 1000 meters (SideA) which forms
the base of a triangle. The angle opposite this line is known (Angle1).
Here we will say it is PI / 4. Given that I know the coordinates of the
base line, its length, and this one angle shouldn't I be able to find what
the coordinates of the opposite corner, or tip of the triangle, is? My idea
is to use the AAS theorem by bisecting the triangle perpendicular to SideA.
This should give me a right triangle right? The right triangle should have
a base of SideA / 2 and two angles, PI / 2 and PI / 8. From this, I should
be able to determine SideB and SideC where SideB is the hypoteneus. Using
the length of SideC and the midpoint of SideA I should be able to determine
where the tip of the triangle is at, correct? My problem is that this seems
to never work out right. I seem to get triangle tip that is farther away
than what is expected. If the tip of the triangle were a camera and the
angle of the two lines forming that tip were the cameras field of view angle
then I should only see the base line from one side of the camera view to the
other. I must have something wrong. Any ideas?
Oh yeah, I am calculating the AAS theorem as follows:
SideA is given and Angle1, Angle2, and Angle3 have been determined as
described above.
sideB = sideA * (Sin(angle2) / Sin(angle1))
sideC = (sideB * Cos(angle1)) + (sideA * Cos(angle2))
Thanks for any help you can offer!
Matthew Hanna
---------------- Original Post -----------------------------------
Hello! I am looking for someone to tell me if this algorithm will work. I
feel like it should but is fails to do what I think it should do every time.
The goal here is to zoom a camera out so its view includes the minimum and
maximum coordinates of a bounding box. I just want the bounding box itself
to be visible with very little empty space on either side. All of this is
in 3D.
The following is a diagram of what I am doing (I copied it out of my code in
Visual Studio so I hope it holds together!)
_______________
/ Terrain \
----------------------- <-- SideA
\ ? PI / 2 | / Note:
PI / 2 is Angle2
\ | /
\ | <---/--- Bisector and SideC
\ | /
\ | /
\ | /
\ | /
\ | /
FOV / 2 --> \ | /
\|/ <- FOV (Angle1)
My algorithm is as follows...
Requires:
SideA = Longest side of bouding box (Should be diagonal but this is fine)
FOV = Camera field of view angle
Camera position
Bounding box midpoint
Method:
Determine normal of view direction by subtracting camera position from
bounding box midpoint and normalizing
Bisect field of view creating a triangle with 3 known angles 1) PI / 2
2) FOV / 2 3) PI - PI / 2 - FOV / 2
Apply AAS theorem by using the angles 1 and 2 above plus SideA / 2 to get
SideC
Scale view direction normal by -SideC to get reverse direction with
magnitude
Add midpoint to above vector to get new camera position
This looks right on paper but doesn't work in code for some reason. My
camera ends up farther away than what I think it should so I have to scale
SideC by 1/3 to make it work right. Maybe it is working right but I just
don't feel like it is. Any ideas? Any better way to do this?
Thanks!
Matthew Hanna
-------------------------------------- Sample
ode ---------------------------------------------
Sub DX_FullExtentCamera(min As D3DVECTOR, mid As D3DVECTOR, max As
D3DVECTOR)
Dim vT As D3DVECTOR
'The normalized view direction
Dim angleA As Single, angleB As Single, angleC As Single 'Angles of
right triangle
Dim sideA As Single, sideB As Single, sideC As Single 'Length of
triangle sides
Dim n As Single
'Final distance from midpoint to camera
'We need to know some angles
angleA = g.fov / 2 'Find the bisector angle
angleB = g_pi / 2 ' and 90 degrees at the other end
angleC = g_pi - angleA - angleB
'We first need to know which way we need to be looking
D3DXVec3Subtract vT, mid, g.vPosition
'We need to know the length of the longest edge of the bounding box we
want a full view of
If Abs(vT.z) >= Abs(vT.x) Then
sideA = max.z - min.z
Else
sideA = max.x - min.x
End If
'Our triangle is bisected so we should only need half the length
'This logic seems to be flawed somehow however since it rarely works
right
'Note: I use 1/3 here because 1/2 seems to be to big in the end
sideA = sideA * 0.3333333333
'We need to calculate the other two sides
sideB = sideA * (Sin(angleB) / Sin(angleA))
sideC = (sideB * Cos(angleA)) + (sideA * Cos(angleB))
'Get the shorter side. Should be sideC.
'N is going to be how far back to move the camera
'so the whole area of interest can be seen
'Note: This is just a check I was doing.
If sideB > sideC Then n = sideC Else n = sideB
'Get the new camera position
D3DXVec3Normalize vT, vT
D3DXVec3Scale vT, vT, -n
D3DXVec3Add vT, vT, mid
'Move the camera!
DX_SetupCameraLookAt vT, mid
End Sub
Matthew Hanna wrote:
>Note: I have asked this question in other newsgroups but I have gotten no
>response so I was hoping someone here might have an answer.
>
>I have included my original post below and you may want to refer there for a
>picture and description of the algorithm I am using.
>In essence, I want to find a point that is far enough from a given line
>segment that the end points of the whole segment can be connected by two
>other line segments forming a triangle whose tip is a given angle in
>radians.
>
>For example, I have a line whose length is 1000 meters (SideA) which forms
>the base of a triangle. The angle opposite this line is known (Angle1).
>Here we will say it is PI / 4. Given that I know the coordinates of the
>base line, its length, and this one angle shouldn't I be able to find what
>the coordinates of the opposite corner, or tip of the triangle, is?
>
You are making another assumption which is correct for your application
(apparently -- see below), but may not be for everyone reading this
post. You are assuming that the perpendicular bisector of SideA is also
the angle bisector of Angle1. This is only true for isosceles triangles
(and only for the different side). That means that this calculation is
only correct for straight on shots.
> My idea
>is to use the AAS theorem by bisecting the triangle perpendicular to SideA.
>This should give me a right triangle right? The right triangle should have
>a base of SideA / 2 and two angles, PI / 2 and PI / 8. From this, I should
>be able to determine SideB and SideC where SideB is the hypoteneus. Using
>the length of SideC and the midpoint of SideA I should be able to determine
>where the tip of the triangle is at, correct? My problem is that this seems
>to never work out right. I seem to get triangle tip that is farther away
>than what is expected. If the tip of the triangle were a camera and the
>angle of the two lines forming that tip were the cameras field of view angle
>then I should only see the base line from one side of the camera view to the
>other. I must have something wrong. Any ideas?
>
>Oh yeah, I am calculating the AAS theorem as follows:
>SideA is given and Angle1, Angle2, and Angle3 have been determined as
>described above.
>sideB = sideA * (Sin(angle2) / Sin(angle1))
>sideC = (sideB * Cos(angle1)) + (sideA * Cos(angle2))
>
Huh? I don't know what this formula is supposed to be, but it certainly
isn't one that was ever proved in trig class.
I would just use sideC = sideB/sin(angle2)*sin(angle3), where angle3 =
pi-angle1-angle2. (This is in radians, but use whatever of radians and
degrees is more convenient for your application -- most of the time,
that will be degrees, because that's what your devices are marked in.)
>---------------- Original Post -----------------------------------
>Hello! I am looking for someone to tell me if this algorithm will work. I
>feel like it should but is fails to do what I think it should do every time.
>The goal here is to zoom a camera out so its view includes the minimum and
>maximum coordinates of a bounding box. I just want the bounding box itself
>to be visible with very little empty space on either side. All of this is
>in 3D.
>The following is a diagram of what I am doing (I copied it out of my code in
>Visual Studio so I hope it holds together!)
>
Note that the algorithm can be generalized to allow you to center your
field of view somewhere other than the object being photographed, and to
allow angle2 to be something other than 90 degrees. You still use the
angle bisector of the FOV (which should be an input variable, allowing
you to change lenses), so you have a side and two angles, allowing you
to solve the triangle using only the law of sines and the fact that the
angles of a triangle add up to 180 degrees. This allows you to
photograph objects at an oblique angle, and centered anywhere you want.
Especially fun with a fisheye.
The arc-angle plus twice the fixed angle is 360 degrees.
E.g., if the fixed angle is a right angle (90 degrees), the arc is a
semicircle (180 degrees).
Matthew Hanna
"Jon Miller" <jonandma...@comcast.net> wrote in message
news:3D82137F...@comcast.net...