BRL-CAD
scale_eto.c
Go to the documentation of this file.
1 /* S C A L E _ E T O . C
2  * BRL-CAD
3  *
4  * Copyright (c) 2008-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 /** @file libged/scale_eto.c
21  *
22  * The scale_eto command.
23  *
24  */
25 
26 #include "common.h"
27 
28 #include <string.h>
29 
30 #include "bu/cmd.h"
31 #include "rtgeom.h"
32 #include "raytrace.h"
33 
34 #include "./ged_private.h"
35 
36 
37 int
38 _ged_scale_eto(struct ged *gedp, struct rt_eto_internal *eto, const char *attribute, fastf_t sf, int rflag)
39 {
40  RT_ETO_CK_MAGIC(eto);
41 
42  switch (attribute[0]) {
43  case 'r':
44  case 'R': {
45  fastf_t ch, cv, dh, newrad;
46  vect_t Nu;
47 
48  if (rflag)
49  newrad = eto->eto_r * sf;
50  else
51  newrad = sf;
52 
53  if (newrad < SMALL)
54  newrad = 4*SMALL;
55 
56  VMOVE(Nu, eto->eto_N);
57  VUNITIZE(Nu);
58 
59  /* get horiz and vert components of C and Rd */
60  cv = VDOT(eto->eto_C, Nu);
61  ch = sqrt(VDOT(eto->eto_C, eto->eto_C) - cv * cv);
62 
63  /* angle between C and Nu */
64  dh = eto->eto_rd * cv / MAGNITUDE(eto->eto_C);
65 
66  /* make sure revolved ellipse doesn't overlap itself */
67  if (ch <= newrad && dh <= newrad)
68  eto->eto_r = newrad;
69  }
70  break;
71  case 'd':
72  case 'D': {
73  fastf_t dh, newrad, work;
74  vect_t Nu;
75 
76  if (rflag)
77  newrad = eto->eto_rd * sf;
78  else
79  newrad = sf;
80 
81  if (newrad < SMALL)
82  newrad = 4*SMALL;
83  work = MAGNITUDE(eto->eto_C);
84  if (newrad <= work) {
85  VMOVE(Nu, eto->eto_N);
86  VUNITIZE(Nu);
87  dh = newrad * VDOT(eto->eto_C, Nu) / work;
88  /* make sure revolved ellipse doesn't overlap itself */
89  if (dh <= eto->eto_r)
90  eto->eto_rd = newrad;
91  }
92  }
93  break;
94  case 'c':
95  case 'C': {
96  fastf_t ch, cv;
97  vect_t Nu, Work;
98 
99  if (!rflag)
100  sf /= MAGNITUDE(eto->eto_C);
101 
102  if (sf * MAGNITUDE(eto->eto_C) >= eto->eto_rd) {
103  VMOVE(Nu, eto->eto_N);
104  VUNITIZE(Nu);
105  VSCALE(Work, eto->eto_C, sf);
106 
107  /* get horiz and vert comps of C and Rd */
108  cv = VDOT(Work, Nu);
109  ch = sqrt(VDOT(Work, Work) - cv * cv);
110  if (ch <= eto->eto_r)
111  VMOVE(eto->eto_C, Work);
112  }
113  }
114  break;
115  default:
116  bu_vls_printf(gedp->ged_result_str, "bad eto attribute - %s", attribute);
117  return GED_ERROR;
118  }
119 
120  return GED_OK;
121 }
122 
123 
124 /*
125  * Local Variables:
126  * tab-width: 8
127  * mode: C
128  * indent-tabs-mode: t
129  * c-file-style: "stroustrup"
130  * End:
131  * ex: shiftwidth=4 tabstop=8
132  */
#define GED_OK
Definition: ged.h:55
#define SMALL
Definition: defines.h:351
Definition: ged.h:338
Header file for the BRL-CAD common definitions.
#define GED_ERROR
Definition: ged.h:61
int _ged_scale_eto(struct ged *gedp, struct rt_eto_internal *eto, const char *attribute, fastf_t sf, int rflag)
Definition: scale_eto.c:38
struct bu_vls * ged_result_str
Definition: ged.h:357
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:694
double fastf_t
Definition: defines.h:300