1 /* =============================================================================
5 * =============================================================================
7 * Copyright (C) Stanford University, 2006. All Rights Reserved.
10 * =============================================================================
12 * For the license of bayes/sort.h and bayes/sort.c, please see the header
15 * ------------------------------------------------------------------------
17 * For the license of kmeans, please see kmeans/LICENSE.kmeans
19 * ------------------------------------------------------------------------
21 * For the license of ssca2, please see ssca2/COPYRIGHT
23 * ------------------------------------------------------------------------
25 * For the license of lib/mt19937ar.c and lib/mt19937ar.h, please see the
26 * header of the files.
28 * ------------------------------------------------------------------------
30 * For the license of lib/rbtree.h and lib/rbtree.c, please see
31 * lib/LEGALNOTICE.rbtree and lib/LICENSE.rbtree
33 * ------------------------------------------------------------------------
35 * Unless otherwise noted, the following license applies to STAMP files:
37 * Copyright (c) 2007, Stanford University
38 * All rights reserved.
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions are
44 * * Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
47 * * Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in
49 * the documentation and/or other materials provided with the
52 * * Neither the name of Stanford University nor the names of its
53 * contributors may be used to endorse or promote products derived
54 * from this software without specific prior written permission.
56 * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``AS IS'' AND ANY
57 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
59 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE
60 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
61 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
62 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
63 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
64 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
65 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
66 * THE POSSIBILITY OF SUCH DAMAGE.
68 * =============================================================================
71 public class coordinate {
72 static int coordinate_compare (coordinate aPtr, coordinate bPtr) {
73 if (aPtr.x < bPtr.x) {
75 } else if (aPtr.x > bPtr.x) {
77 } else if (aPtr.y < bPtr.y) {
79 } else if (aPt.>y > bPtr.y) {
86 /* =============================================================================
88 * =============================================================================
90 static double coordinate_distance (coordinate coordinatePtr, coordinate aPtr) {
91 double delta_x = coordinatePtr.x - aPtr.x;
92 double delta_y = coordinatePtr.y - aPtr.y;
94 return Math.sqrt((delta_x * delta_x) + (delta_y * delta_y));
98 /* =============================================================================
102 * cos a = ---------------------
103 * ||b - a|| * ||c - a||
105 * =============================================================================
107 static double coordinate_angle(coordinate aPtr, coordinate bPtr, coordinate cPtr) {
119 delta_b_x = bPtr.x - aPtr.x;
120 delta_b_y = bPtr.y - aPtr.y;
122 delta_c_x = cPtr.x - aPtr.x;
123 delta_c_y = cPtr.y - aPtr.y;
125 numerator = (delta_b_x * delta_c_x) + (delta_b_y * delta_c_y);
127 distance_b = coordinate_distance(aPtr, bPtr);
128 distance_c = coordinate_distance(aPtr, cPtr);
129 denominator = distance_b * distance_c;
131 cosine = numerator / denominator;
132 radian = Math.acos(cosine);
134 return (180.0 * radian / 3.141592653589793238462643);
138 /* =============================================================================
140 * =============================================================================
142 void coordinate_print() {
143 System.out.println("("+x+", "+y+")");
146 /* =============================================================================
148 * End of coordinate.c
150 * =============================================================================