opennurbs_torus.h
1 /* $NoKeywords: $ */
2 /*
3 //
4 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
5 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
6 // McNeel & Associates.
7 //
8 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
9 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
10 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
11 //
12 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
13 //
14 ////////////////////////////////////////////////////////////////
15 */
16 
17 #if !defined(ON_TORUS_INC_)
18 #define ON_TORUS_INC_
19 
20 class ON_RevSurface;
21 class ON_TextLog;
22 
23 /*
24 Description:
25  The torus is defined by a major circle and minor radius. The
26  torus is parameterized by (major_angle,minor_angle). The angles
27  are specified in radians. The domain of both parameters is (0,2pi).
28 */
29 class ON_CLASS ON_Torus
30 {
31 
32 public:
33  // for expert users
34 
35  ON_Plane plane; // major circle plane
36  double major_radius; // > minor_radius
37  double minor_radius; // > 0
38 
39 public:
40 
41  ON_Torus();
42  ON_Torus( const ON_Plane& major__plane, double major__radius, double minor__radius );
43  ON_Torus( const ON_Circle& major__circle, double minor__radius );
44  ~ON_Torus();
45 
46  bool IsValid( ON_TextLog* text_log = nullptr ) const;
47 
48  bool Create( const ON_Plane& major__plane, double major__radius, double minor__radius );
49  bool Create( const ON_Circle& major__circle, double minor__radius);
50 
51  /*
52  Description:
53  Get the circle that is the isocurve on the torus
54  at a specified minor angle.
55  Parameteters:
56  minor_angle_radians - [in]
57  Returns:
58  A circle with normal major_circle.plane.zaxis that starts
59  at PointAt( 0.0, minor_angle_radians ).
60  See Also:
61  ON_Torus::MajorCircleRadians
62  ON_Torus::MajorCircleDegrees
63  ON_Torus::MinorCircleRadians
64  ON_Torus::MinorCircleDegrees
65  */
66  ON_Circle MajorCircleRadians(double minor_angle_radians ) const;
67 
68  /*
69  Description:
70  Get the circle that is the isocurve on the torus
71  at a specified minor angle.
72  Parameteters:
73  minor_angle_degrees - [in]
74  Returns:
75  A circle with normal major_circle.plane.zaxis that starts
76  at PointAt( 0.0, minor_angle_degrees*ON_PI/180.0 ).
77  See Also:
78  ON_Torus::MajorCircleRadians
79  ON_Torus::MajorCircleDegrees
80  ON_Torus::MinorCircleRadians
81  ON_Torus::MinorCircleDegrees
82  */
83  ON_Circle MajorCircleDegrees(double minor_angle_degrees) const;
84 
85  /*
86  Description:
87  Get the minor circle that is the isocurve on the torus
88  at a specified major angle.
89  Parameteters:
90  major_angle_radians - [in]
91  Returns:
92  A circle with radius = minor_radis,
93  center = major_circle.PointAt(major_angle_radians), and
94  starting point PointAt( major_angle_radians, 0.0 ).
95  See Also:
96  ON_Torus::MajorCircleRadians
97  ON_Torus::MajorCircleDegrees
98  ON_Torus::MinorCircleRadians
99  ON_Torus::MinorCircleDegrees
100  */
101  ON_Circle MinorCircleRadians(double major_angle_radians) const;
102 
103  /*
104  Description:
105  Get the minor circle that is the isocurve on the torus
106  at a specified major angle.
107  Parameteters:
108  major_angle_degrees - [in]
109  Returns:
110  A circle with radius = minor_radis,
111  center = major_circle.PointAt(major_angle_degrees*ON_PI/180.0), and
112  starting point PointAt( major_angle_degrees*ON_PI/180.0, 0.0 ).
113  See Also:
114  ON_Torus::MajorCircleRadians
115  ON_Torus::MajorCircleDegrees
116  ON_Torus::MinorCircleRadians
117  ON_Torus::MinorCircleDegrees
118  */
119  ON_Circle MinorCircleDegrees(double major_angle_degrees) const;
120 
121  ON_3dPoint Center() const;
122  ON_3dVector Axis() const;
123  double MajorRadius() const;
124  double MinorRadius() const;
125 
126  ON_3dPoint PointAt(
127  double major_angle_radians,
128  double minor_angle_radians
129  ) const;
130 
131  ON_3dVector NormalAt(
132  double major_angle_radians,
133  double minor_angle_radians
134  ) const;
135 
136  // returns parameters of point on torus that is closest to test_point.
137  bool ClosestPointTo(
138  ON_3dPoint test_point,
139  double* major_angle_radians,
140  double* minor_angle_radians
141  ) const;
142 
143  // returns point on torus that is closest to test_point
144  ON_3dPoint ClosestPointTo(
145  ON_3dPoint test_point
146  ) const;
147 
148  // rotate torus about its origin
149  bool Rotate(
150  double sin_angle, // sin(angle)
151  double cos_angle, // cos(angle)
152  const ON_3dVector& axis_of_rotation // axis of rotation
153  );
154 
155  bool Rotate(
156  double angle_radians, // angle in radians
157  const ON_3dVector& axis_of_rotation // axis of rotation
158  );
159 
160  // rotate torus about a point and axis
161  bool Rotate(
162  double sin_angle, // sin(angle)
163  double cos_angle, // cos(angle)
164  const ON_3dVector& axis_of_rotation, // axis of rotation
165  const ON_3dPoint& center_of_rotation // center of rotation
166  );
167 
168  bool Rotate(
169  double angle_radians, // angle in radians
170  const ON_3dVector& axis_of_rotation, // axis of rotation
171  const ON_3dPoint& center_of_rotation // center of rotation
172  );
173 
174  bool Translate(
175  const ON_3dVector&
176  );
177 
178  bool Transform( const ON_Xform& );
179 
180  // parameterization of NURBS surface does not match torus's transcendental paramaterization
181  int GetNurbForm( ON_NurbsSurface& ) const; // returns 0=failure, 2=success
182 
183  /*
184  Description:
185  Creates a surface of revolution definition of the torus.
186  Parameters:
187  srf - [in] if not nullptr, then this srf is used.
188  Result:
189  A surface of revolution or nullptr if the torus is not valid.
190  */
191  ON_RevSurface* RevSurfaceForm( ON_RevSurface* srf = nullptr ) const;
192 };
193 
194 #endif
Definition: opennurbs_nurbssurface.h:62
ON_Circle is a circle in 3d. The cirle is represented by a radius and an orthonormal frame of the pla...
Definition: opennurbs_circle.h:32
Definition: opennurbs_xform.h:28
The torus is defined by a major circle and minor radius. The torus is parameterized by (major_angle...
Definition: opennurbs_torus.h:28
Definition: opennurbs_textlog.h:20
Definition: opennurbs_point.h:460
Definition: opennurbs_plane.h:20
surface of revolution
Definition: opennurbs_revsurface.h:21
Definition: opennurbs_point.h:1152