MeshLib Documentation
Loading...
Searching...
No Matches
MRCone3.h
Go to the documentation of this file.
1#pragma once
2#include "MRLine3.h"
3
4namespace MR
5{
6
7// Base class for cone parameterization
8
9template <typename T>
10class Cone3
11{
12public:
14 {}
15
16 // inAxis -- apex position and main axis direction. For any cone point dot( point , direction ) >=0
17 // inAngle -- cone angle, main axis vs side
18 // inHeight -- cone inHeight
19 // main axis direction could be non normalized.
20 Cone3( const Line3<T>& inAxis, T inAngle, T inHeight )
21 :
22 axis( inAxis ),
23 angle( inAngle ),
24 height( inHeight )
25 {}
26
27 // now we use an apex as center of the cone.
29 {
30 return axis.p;
31 }
32 // now we use an apex as center of the cone.
33 const Vector3<T>& center( void ) const
34 {
35 return axis.p;
36 }
37 // main axis direction. It could be non normalized. For any cone point dot( point , direction ) >=0
39 {
40 return axis.d;
41 }
42 // main axis direction. It could be non normalized. For any cone point dot( point , direction ) >=0
43 const Vector3<T>& direction( void ) const
44 {
45 return axis.d;
46 }
47 // return cone apex position
49 {
50 return center();
51 }
52 // return cone apex position
53 const Vector3<T>& apex( void ) const
54 {
55 return center();
56 }
57
58 Vector3<T> projectPoint( const Vector3<T>& point ) const
59 {
60 // Get direction, center, and angle of the cone from the specified viewport
61 const Vector3<T>& n = direction();
62 const Vector3<T>& center = apex();
63 const T coneAngle = angle;
64
65 // Calculate vector X as the difference between the point and the center of the cone
66 auto X = point - center;
67
68 // Calculate the angle between vectors n (cone main axis) and X (center normalyzed source point)
69 T angleX = std::atan2( cross( n, X ).length(), dot( n, X ) );
70
71 // This means the projection will fall on the apex of the cone.
72 if ( coneAngle + PI_F / 2.0 < angleX )
73 return center;
74
75 // Project vector X onto the cone main axis
76 auto K = n * MR::dot( X, n );
77 auto XK = ( X - K );
78
79 // We find the point of intersection of the vector XK with the surface of the cone
80 // and find a guide ventor along the surface of the cone to the projection point
81 auto D = K + XK.normalized() * ( K.length() * std::tan( coneAngle ) );
82 auto normD = D.normalized();
83 // Calculate the projected point on the conical surface
84 return normD * dot( normD, X ) + center;
85 }
86
87
88 Line3<T> axis; // the combination of the apex of the cone and the direction of its main axis in space.
89 // for any cone point dot( point , direction ) >=0
90 T angle = 0; // cone angle, main axis vs side
91 T height = 0; // cone height
92};
93
94
95
96} // namespace MR
length
Definition MRObjectDimensionsEnum.h:14
Definition MRCone3.h:11
const Vector3< T > & direction(void) const
Definition MRCone3.h:43
T angle
Definition MRCone3.h:90
T height
Definition MRCone3.h:91
Line3< T > axis
Definition MRCone3.h:88
Cone3()
Definition MRCone3.h:13
const Vector3< T > & center(void) const
Definition MRCone3.h:33
Vector3< T > & apex(void)
Definition MRCone3.h:48
Cone3(const Line3< T > &inAxis, T inAngle, T inHeight)
Definition MRCone3.h:20
Vector3< T > & center(void)
Definition MRCone3.h:28
Vector3< T > & direction(void)
Definition MRCone3.h:38
const Vector3< T > & apex(void) const
Definition MRCone3.h:53
Vector3< T > projectPoint(const Vector3< T > &point) const
Definition MRCone3.h:58
Definition MRCameraOrientationPlugin.h:8
Definition MRLine.h:12
Definition MRMesh/MRVector3.h:19