Advertisement
Guest User

Untitled

a guest
Oct 7th, 2014
471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. class Conv {
  2.     XYZPlane *plane;
  3.     XYZVector *f1, *f2;
  4.     XYZVector *U, *V, *O;
  5. public:
  6.     Conv(XYZPlane *, XYZVector *, XYZVector *);
  7.     Point *from3Dto2D(XYZPoint *) const;
  8.     XYZPoint *from2Dto3D(Point *) const;
  9. };
  10.  
  11.  
  12. Conv::Conv(XYZPlane *pl, XYZVector *ff1, XYZVector *ff2) :
  13.     plane(pl), f1(ff1), f2(ff2)
  14. {
  15.     U = XYZVector::sub(ff1,ff2);
  16.     V = XYZVector::v_mul(U,pl->normal());
  17.     O = XYZVector::middle(ff1,ff2);
  18. }
  19.  
  20. Point *Conv::from3Dto2D(XYZPoint *p) const {
  21.     XYZVector *OP = XYZVector::sub(new XYZVector(p), O);
  22.     double tmpx = XYZVector::s_mul(OP,U) / sqrt(XYZVector::s_mul(U,U));
  23.     double tmpy = XYZVector::s_mul(OP,V) / sqrt(XYZVector::s_mul(V,V));
  24.     return new Point(tmpx,tmpy);
  25. }
  26.  
  27. XYZPoint *Conv::from2Dto3D(Point *p) const {
  28.     XYZVector *UP = U->one()->mul_c(p->x);
  29.     XYZVector *VP = V->one()->mul_c(p->y);
  30.     XYZVector *res = XYZVector::add(UP,VP);
  31.     return res;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement