File: plane.cc

package info (click to toggle)
epix 1.2.19-2
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 3,284 kB
  • sloc: cpp: 16,837; sh: 5,043; makefile: 155; lisp: 6
file content (143 lines) | stat: -rw-r--r-- 3,024 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/* 
 * plane.cc -- ePiX::Plane class and mathematical operators
 *
 * This file is part of ePiX, a C++ library for creating high-quality 
 * figures in LaTeX 
 *
 * Version 1.2.2
 * Last Change: December 06, 2007
 */

/* 
 * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
 * Andrew D. Hwang <rot 13 nujnat at zngupf dot ubylpebff dot rqh>
 * Department of Mathematics and Computer Science
 * College of the Holy Cross
 * Worcester, MA, 01610-2395, USA
 */

/*
 * ePiX is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * ePiX is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
 * License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with ePiX; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include "constants.h"
#include "errors.h"

#include "curves.h" // for draw()

#include "plane.h"

namespace ePiX {

  const double INF(2*EPIX_INFTY);

  Plane::Plane(const P& pt, const P& perp)
    : m_pt(pt), m_perp(perp), m_malformed(false)
  { 
    double temp(norm(perp));

    if (temp < EPIX_EPSILON)
      {
	epix_warning("Degenerate plane normal, using (0,0,1)");
	m_perp=E_3;
      }

    else
      m_perp *= 1.0/temp;
  }

  Plane::Plane(const P& p1, const P& p2, const P& p3)
    : m_pt(p1), m_malformed(false)
  {
    P perp((p2-p1)*(p3-p1));
    double norm_perp(norm(perp));

    if (norm_perp < EPIX_EPSILON)
      {
	epix_warning("Collinear points in Plane constructor");
	m_malformed = true;
      }

    else
      m_perp = (1/norm_perp)*perp;
  }


  P Plane::pt() const
  {
    return m_pt;
  }

  P Plane::perp() const
  {
    return m_perp;
  }

  bool Plane::malformed() const
  {
    return m_malformed;
  }

  // translate
  Plane& Plane::shift(const P& arg)
  {
    if (!m_malformed)
      m_pt += arg;
    return *this;
  }

  Plane& Plane::move_to(const P& arg)
  {
    if (!m_malformed)
      m_pt = arg;
    return *this;
  }

  void Plane::draw() const
  {
    if (m_malformed)
      return;

    // else
    const P ctr((m_pt|m_perp)*m_perp); // closest point to origin

    // construct an orthonormal basis
    P e1(m_perp*E_1);

    if (norm(e1) < 0.7) // ~sqrt(0.5)
      e1 = m_perp*E_2;

    e1 *= 1.0/norm(e1);
    P e2(m_perp*e1);

    // very large rectangle
    quad(ctr + INF*( e1 + e2), ctr + INF*(-e1 + e2),
	 ctr + INF*(-e1 - e2), ctr + INF*( e1 - e2));
  }


  //// global functions ////
  void plane(const P& point, const P& normal)
  {
    Plane pl(point, normal);
    pl.draw();
  }

  void plane(const P& p1, const P& p2, const P& p3)
  {
    Plane pl(p1, p2, p3);
    pl.draw();
  }
} // end of namespace