Tachyon (current)  Current Main Branch
coordsys.c
Go to the documentation of this file.
1 /*
2  * coordsys.c - Routines to translate from one coordinate system to another.
3  *
4  * (C) Copyright 1994-2022 John E. Stone
5  * SPDX-License-Identifier: BSD-3-Clause
6  *
7  * $Id: coordsys.c,v 1.6 2022/02/18 17:55:28 johns Exp $
8  *
9  */
10 
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <math.h>
15 
16 #define TACHYON_INTERNAL 1
17 #include "tachyon.h"
18 #include "coordsys.h"
19 
20 void xytopolar(flt x, flt y, flt rad, flt * u, flt * v) {
21  flt r1;
22  r1=x*x + y*y;
23  *v=SQRT(r1 / (rad*rad));
24  if (y<0.0)
25  *u=1.0 - ACOS(x/SQRT(r1))/TWOPI;
26  else
27  *u= ACOS(x/SQRT(r1))/TWOPI;
28 }
29 
30 void xyztocyl(vector pnt, flt height, flt * u, flt * v) {
31  flt r1;
32 
33  r1=pnt.x*pnt.x + pnt.y*pnt.y;
34 
35  *v=pnt.z / height;
36  if (pnt.y<0.0)
37  *u=1.0 - ACOS(pnt.x/SQRT(r1))/TWOPI;
38  else
39  *u=ACOS(pnt.x/SQRT(r1))/TWOPI;
40 }
41 
42 void xyztospr(vector pnt, flt * u, flt * v) {
43  flt r1, phi, theta;
44 
45  r1=SQRT(pnt.x*pnt.x + pnt.y*pnt.y + pnt.z*pnt.z);
46 
47  phi=ACOS(-pnt.y/r1);
48  *v=phi/3.1415926;
49 
50  theta=ACOS((pnt.x/r1)/SIN(phi))/TWOPI;
51 
52  if (pnt.z > 0.0)
53  *u = theta;
54  else
55  *u = 1 - theta;
56 }
57 
58 
void xytopolar(flt x, flt y, flt rad, flt *u, flt *v)
Definition: coordsys.c:20
double flt
generic floating point number, using double
Definition: tachyon.h:47
#define SIN(x)
Definition: util.h:30
#define ACOS(x)
Definition: util.h:25
#define SQRT(x)
Definition: util.h:31
Tachyon public API function prototypes and declarations used to drive the ray tracing engine...
void xyztocyl(vector pnt, flt height, flt *u, flt *v)
Definition: coordsys.c:30
void xyztospr(vector pnt, flt *u, flt *v)
Definition: coordsys.c:42