Tesseract  3.02
tesseract-ocr/classify/fpoint.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002  **     Filename:    fpoint.c
00003  **     Purpose:     Abstract data type for a 2D point (floating point coords)
00004  **     Author:      Dan Johnson
00005  **     History:     Thu Apr 12 10:44:15 1990, DSJ, Created.
00006  **
00007  **     (c) Copyright Hewlett-Packard Company, 1988.
00008  ** Licensed under the Apache License, Version 2.0 (the "License");
00009  ** you may not use this file except in compliance with the License.
00010  ** You may obtain a copy of the License at
00011  ** http://www.apache.org/licenses/LICENSE-2.0
00012  ** Unless required by applicable law or agreed to in writing, software
00013  ** distributed under the License is distributed on an "AS IS" BASIS,
00014  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  ** See the License for the specific language governing permissions and
00016  ** limitations under the License.
00017  ******************************************************************************/
00021 #include "const.h"
00022 #include "fpoint.h"
00023 #include <stdio.h>
00024 #include <math.h>
00025 
00029 /*---------------------------------------------------------------------------*/
00030 
00031 FLOAT32 DistanceBetween(FPOINT A, FPOINT B) {
00032   double xd = XDelta(A, B);
00033   double yd = YDelta(A, B);
00034   return sqrt(static_cast<double>(xd * xd + yd * yd));
00035 }
00036 
00037 
00038 
00039 FLOAT32 NormalizedAngleFrom(FPOINT *Point1,
00040                             FPOINT *Point2,
00041                             FLOAT32 FullScale) {
00042 /*
00043  **     Parameters:
00044  **             Point1, Point2  points to compute angle between
00045  **             FullScale       value to associate with 2*pi
00046  **     Globals: none
00047  **     Operation: Return the angle from Point1 to Point2 normalized to
00048  **             lie in the range 0 to FullScale (where FullScale corresponds
00049  **             to 2*pi or 360 degrees).
00050  **     Return: none
00051  **     Exceptions: none
00052  **     History: Wed Mar 28 14:27:25 1990, DSJ, Created.
00053  */
00054   FLOAT32 Angle;
00055   FLOAT32 NumRadsInCircle = 2.0 * PI;
00056 
00057   Angle = AngleFrom (*Point1, *Point2);
00058   if (Angle < 0.0)
00059     Angle += NumRadsInCircle;
00060   Angle *= FullScale / NumRadsInCircle;
00061   if (Angle < 0.0 || Angle >= FullScale)
00062     Angle = 0.0;
00063   return (Angle);
00064 
00065 }                                /* NormalizedAngleFrom */