📄 xypt6.c
字号:
/*************************************************************************/
/* */
/* Copyright (c) 1997 - 1999 Accelerated Technology, Inc. */
/* */
/* PROPRIETARY RIGHTS of Accelerated Technology are involved in the */
/* subject matter of this material. All manufacturing, reproduction, */
/* use, and sales rights pertaining to this subject matter are governed */
/* by the license agreement. The recipient of this software implicitly */
/* accepts the terms of the license. */
/* */
/*************************************************************************/
/*************************************************************************/
/* */
/* FILE NAME VERSION */
/* */
/* XYPT6.c 1.9 */
/* */
/* COMPONENT */
/* */
/* All */
/* */
/* DESCRIPTION */
/* */
/* This file contains the PtToAngle function. */
/* */
/* AUTHOR */
/* */
/* Giac Dinh, Accelerated Technology, Inc. */
/* */
/* DATA STRUCTURES */
/* */
/* None */
/* */
/* FUNCTIONS */
/* */
/* None */
/* */
/* DEPENDENCIES */
/* */
/* None */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* GiacD 2/9/99 Added fixed-point math support */
/* BobB 5/11/99 Corrected for angle sign */
/* */
/*************************************************************************/
#include "meta_wnd.h"
#include "metconst.h" /* MetaWINDOW Constant & Stucture Definitions */
#include "metports.h" /* MetaWINDOW Port & Bitmap Definitions */
#include "grafdata.h"
#include "metmacs3.h"
//#include "Nu_math.h"
/* Function PtToAngle RETURNs the angle, in integer tenth of degrees, for the
line between the center of rectangle R and the specified point, PT.*/
#ifdef FIXPOINT
long PtToAngle( rect * R, point * PT)
{
rect tempRect;
/* BobB 5/12/99 - added local point variable */
point tempPt;
short DltX, DltY ;
short Ctr_X , Ctr_Y ;
long hypot;
long angle;
long sin_rad;
long ResX;
long ResY;
long qDltXX;
long qDltYY;
/* BobB 5/12/99 - corrected to use local variables */
if (globalLevel > 0)
{ /* convert from user to global */
U2GR(*R, &tempRect , 1);
U2GP(PT->X , PT->Y, &tempPt.X, &tempPt.Y, 1);
}
else
{
tempRect = * R; /* get rectangle */
tempPt = *PT; /* get point */
}
/* find center point of rect */
Ctr_X = (tempRect.Xmax + tempRect.Xmin) >> 1 ;
Ctr_Y = (tempRect.Ymax + tempRect.Ymin) >> 1 ;
/* compute delta from center to point */
DltX = tempPt.X - Ctr_X;
DltY = tempPt.Y - Ctr_Y;
/* BobB 5/11/99 - corrected the following two lines
ResX = grafPort.portMap->pixResX << 16;
ResY = grafPort.portMap->pixResY << 16; */
ResX = grafPort.portMap->pixResX;
ResY = grafPort.portMap->pixResY;
qDltXX = Fix_div((DltX << 16),(ResX << 16));
qDltXX = Fix_mul(qDltXX,qDltXX);
qDltYY = Fix_div((DltY << 16),(ResY << 16));
/* BobB 5/11/99 - deleted the following line to reduce math
qDltYY = Fix_mul(qDltYY,qDltYY); */
/* take hypothesis of two X and Y coordination */
/* BobB 5/11/99 - changed the following line due to change above
hypot = Fix_sqrt(qDltXX + qDltYY); */
hypot = Fix_sqrt(qDltXX + (Fix_mul(qDltYY,qDltYY)));
/* if angle of Zero there is no graph */
if( hypot == 0 )
{
angle = 0;
return(angle);
}
/* Test to find out angle's position */
/* BobB 5/11/99 - changed the following line due to change above
and changes for the sign of the angle
sin_rad = Fix_div(DltY,hypot); */
if (DltY >= 0)
{ /* negative angle */
sin_rad = Fix_div(qDltYY,hypot);
if (sin_rad >= 0x00010000) sin_rad = 0xFFFF;
angle = - Nu_asin(sin_rad);
}
else
{ /* positive angle */
sin_rad = Fix_div(-qDltYY,hypot);
if (sin_rad >= 0x00010000) sin_rad = 0xFFFF;
angle = Nu_asin(sin_rad);
}
if( DltX < 0 ) angle = 1800 - angle ;
if( angle < 0) angle = 3600 + angle ;
return(angle);
}
#else /* floating-point math */
long PtToAngle ( rect * R, point * PT )
{
rect tempRect;
/* BobB 5/12/99 - added local point variable */
point tempPt;
short DltX, DltY ;
short Ctr_X , Ctr_Y ;
double hypot;
long angle;
double sin_rad;
double ResX ;
double ResY ;
double qDltXX ;
double qDltYY ;
/* BobB 5/12/99 - corrected to use local variables */
if (globalLevel > 0)
{ /* convert from user to global */
U2GR(*R, &tempRect , 1);
U2GP(PT->X , PT->Y, &tempPt.X, &tempPt.Y, 1);
}
else
{
tempRect = * R; /* get rectangle */
tempPt = *PT; /* get point */
}
/* find center point of rect */
Ctr_X = (tempRect.Xmax + tempRect.Xmin) >> 1 ;
Ctr_Y = (tempRect.Ymax + tempRect.Ymin) >> 1 ;
/* compute delta from center to point */
DltX = tempPt.X - Ctr_X;
DltY = tempPt.Y - Ctr_Y;
ResX = grafPort.portMap->pixResX ;
ResY = grafPort.portMap->pixResY ;
qDltXX = (double) (DltX / ResX) ;
qDltXX = qDltXX * qDltXX ;
qDltYY = (double) (DltY / ResY) ;
/* BobB 5/11/99 - deleted the following line to reduce math
qDltYY = qDltYY * qDltYY ; */
/* take hypotenuse of two X and Y coordinates */
/* BobB 5/11/99 - changed the following line due to change above
hypot = sqrt ( qDltXX + qDltYY ) ; */
hypot = sqrt ( qDltXX + (qDltYY*qDltYY) ) ;
/* if angle of Zero there is no graph */
if( hypot == 0 )
{
angle = 0;
return(angle);
}
/* Test to find out angle's position */
/* BobB 5/11/99 - changed the following line due to change above
sin_rad = DltY / hypot; */
sin_rad = qDltYY / hypot;
if (sin_rad >= 1.0) sin_rad = .99999999;
/* BobB 5/11/99 added the following line to test negative rad */
if (sin_rad <= -1.0) sin_rad = -.99999999;
/* BobB 5/11/99 - changed the following line to correct sign
angle = (long) (1800 * asin(sin_rad) / 3.1415926535); */
angle = (long) (-1800 * asin(sin_rad) / 3.1415926535);
if( DltX < 0 ) angle = 1800 - angle ;
if( angle < 0) angle = 3600 + angle ;
return(angle);
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -