# # Patch name: AttyXYZ2SPH # Patch version: 1 # Author's name: Atuarre Ti Kivikkii # Author's email: atuarre@gz.trekmush.org # Version of PennMUSH: 1.6.10-patch06 # Date patch made: June 19, 1997 # Author is willing to support (yes/no): yes # Patch format: diff -c # # # This is a contributed PennMUSH patch. Its use is subject to the # same restrictions found in PennMUSH's hdrs/copyrite.h file. # # No warranty is given for this patch. It is not necessarily going # to work on your system, with any version of PennMUSH other than # the one above, etc. # # If the author given above was willing to support the patch, you # should write to the author if you have any questions or problems. Do # *NOT* send email messages to Javelin or any PennMUSH mailing list about # this patch! # # Below this line is the author's description of the patch, # followed by the patch itself. If the patch is in context diff # format, you'll probably apply it by typing: patch < patchfile # in your top-level MUSH directory, unless instructed otherwise # below. # # This patch includes the SPH2XYZ and XYZ2SPH functions ported to PennMUSH # by Atuarre. The following patch does not include .hlp files, # so here is a brief synopsis of what these patches do: # # SPH2XYZ(,,) ==> # XYZ2SPH(,,) ==> # # Note that this function requires FLOATIN_POINTS to be #defined. # Note also that and are in degrees and not radians. # PennMUSH trigonometric functions operate in radians, and for most # applications of these two functions, degrees is preferable, so I did them # both directly in degrees. # # Be advised that these functions have their own preferred reference-frame # that may not agree with your own. Use at your own risk. # *** ../penn.virgin/src/funmath.c Tue May 13 07:32:13 1997 --- ./src/funmath.c Thu Jun 19 04:43:46 1997 *************** *** 982,984 x ^= parse_boolean(args[j]); safe_chr(x ? '1' : '0', buff, bp); } --- 982,1069 ----- x ^= parse_boolean(args[j]); safe_chr(x ? '1' : '0', buff, bp); } + + /* ARGSUSED */ + FUNCTION(fun_sph2xyz) + { + NVAL b, e, r; + + if (!is_number(args[0]) || !is_number(args[1]) || !is_number(args[2])) { + safe_str(e_num, buff, bp); + } else { + b = parse_number(args[0]) * PI / 180; + e = parse_number(args[1]) * PI / 180; + r = parse_number(args[2]) ; + safe_str(unparse_number(cos(b) * cos(e) * r), buff, bp); + safe_chr(' ', buff, bp); + safe_str(unparse_number(sin(b) * cos(e) * r), buff, bp); + safe_chr(' ', buff, bp); + safe_str(unparse_number(sin(e) * r), buff, bp); + } + return; + } + + /* ARGSUSED */ + FUNCTION(fun_xyz2sph) + { + NVAL b, e, r, x, y, z, xy; + + if (!is_number(args[0]) || !is_number(args[1]) || !is_number(args[2])) { + safe_str(e_num, buff, bp); + } else { + x = parse_number(args[0]); + y = parse_number(args[1]); + z = parse_number(args[2]); + xy = sqrt(x * x + y * y); + r = sqrt(x * x + y * y + z * z); + #ifndef HAS_IEEE_MATH + /* You can overflow, which is bad. */ + if ((r < 0.0) || (xy < 0.0)) { + safe_str("#-1 OVERFLOW ERROR", buff, bp); + return; + } + #endif /* HAS_IEEE_MATH */ + if (y == 0.0) { + if (x == 0.0) { + b = 0.0; + } else if (x > 0.0) { + b = 0.0; + } else + b = 180.0; + } else if (x == 0.0) { + if (y > 0.0) { + b = 90.0; + } else + b = 270.0; + } else if (x > 0.0) { + if (y > 0.0) { + b = atan(y / x) * 180.0 / PI; + } else + b = atan(y / x) * 180.0 / PI + 360.0; + } else if (x < 0.0) { + b = atan(y / x) * 180.0 / PI + 180.0; + } else + b = 0.0; + + if (xy == 0.0) { + if (z == 0.0) { + e = 0.0; + } else if (z > 0.0) { + e = 90.0; + } else + e = 270.0; + } else if (z > 0.0) { + e = atan(z / xy) * 180.0 / PI; + } else if (z < 0.0) { + e = atan(z / xy) * 180.0 / PI + 360; + } else + e = 0.0; + + safe_str(unparse_number(b), buff, bp); + safe_chr(' ', buff, bp); + safe_str(unparse_number(e), buff, bp); + safe_chr(' ', buff, bp); + safe_str(unparse_number(r), buff, bp); + } + return; + } *** ../penn.virgin/src/function.c Tue May 13 07:42:59 1997 --- ./src/function.c Thu Jun 19 04:46:16 1997 *************** *** 388,393 {"POWER", fun_power, 2, 2, FN_REG}, {"ROUND", fun_round, 2, 2, FN_REG}, {"SIN", fun_sin, 1, 1, FN_REG}, {"SQRT", fun_sqrt, 1, 1, FN_REG}, {"TAN", fun_tan, 1, 1, FN_REG}, #endif /* FLOATING_POINTS */ --- 388,394 ----- {"POWER", fun_power, 2, 2, FN_REG}, {"ROUND", fun_round, 2, 2, FN_REG}, {"SIN", fun_sin, 1, 1, FN_REG}, + {"SPH2XYZ", fun_sph2xyz, 3, 3, FN_REG}, {"SQRT", fun_sqrt, 1, 1, FN_REG}, {"TAN", fun_tan, 1, 1, FN_REG}, {"XYZ2SPH", fun_xyz2sph, 3, 3, FN_REG}, *************** *** 390,395 {"SIN", fun_sin, 1, 1, FN_REG}, {"SQRT", fun_sqrt, 1, 1, FN_REG}, {"TAN", fun_tan, 1, 1, FN_REG}, #endif /* FLOATING_POINTS */ {NULL, NULL, 0, 0} }; --- 391,397 ----- {"SPH2XYZ", fun_sph2xyz, 3, 3, FN_REG}, {"SQRT", fun_sqrt, 1, 1, FN_REG}, {"TAN", fun_tan, 1, 1, FN_REG}, + {"XYZ2SPH", fun_xyz2sph, 3, 3, FN_REG}, #endif /* FLOATING_POINTS */ {NULL, NULL, 0, 0} }; *** ../penn.virgin/hdrs/function.h Tue May 13 07:44:15 1997 --- ./hdrs/function.h Thu Jun 19 04:48:57 1997 *************** *** 221,226 FUNCTION_PROTO(fun_not); /* funmath.c */ FUNCTION_PROTO(fun_t); /* funmath.c */ FUNCTION_PROTO(fun_xor); /* funmath.c */ FUNCTION_PROTO(fun_valid); /* funmisc.c */ FUNCTION_PROTO(fun_pemit); /* funmisc.c */ FUNCTION_PROTO(fun_setq); /* funmisc.c */ --- 221,228 ----- FUNCTION_PROTO(fun_not); /* funmath.c */ FUNCTION_PROTO(fun_t); /* funmath.c */ FUNCTION_PROTO(fun_xor); /* funmath.c */ + FUNCTION_PROTO(fun_sph2xyz); /* funmath.c */ + FUNCTION_PROTO(fun_xyz2sph); /* funmath.c */ FUNCTION_PROTO(fun_valid); /* funmisc.c */ FUNCTION_PROTO(fun_pemit); /* funmisc.c */ FUNCTION_PROTO(fun_setq); /* funmisc.c */