1 //#**************************************************************
2 //#
3 //# filename:             GeomElements.h
4 //#
5 //# author:               Gerstmayr Johannes
6 //#
7 //# generated:						Mai 2005
8 //# description:          Drawing tools
9 //#
10 //# remarks:
11 //#
12 //# Copyright (c) 2003-2013 Johannes Gerstmayr, Linz Center of Mechatronics GmbH, Austrian
13 //# Center of Competence in Mechatronics GmbH, Institute of Technical Mechanics at the
14 //# Johannes Kepler Universitaet Linz, Austria. All rights reserved.
15 //#
16 //# This file is part of HotInt.
17 //# HotInt is free software: you can redistribute it and/or modify it under the terms of
18 //# the HOTINT license. See folder 'licenses' for more details.
19 //#
20 //# bug reports are welcome!!!
21 //# WWW:		www.hotint.org
22 //# email:	bug_reports@hotint.org or support@hotint.org
23 //#**************************************************************
24 
25 #ifndef DRAWTOOLS__H
26 #define DRAWTOOLS__H
27 
28 #include "mbs_interface.h"
29 
30 //GeomElement
31 //GeomQuad3D
32 //GeomZyl3D
33 //GeomPipe3D
34 //GeomRotObject3D
35 //GeomCube3D --> communication changed
36 //GeomSphere3D
37 //GeomGround
38 //GeomCircle2D
39 //GeomPolygon2D
40 //GeomTrig3D
41 //GeomMesh3D
42 
43 typedef enum {TGeomGeneral = 0, TGeomQuad3D = 1, TGeomZyl3D = 2, TGeomPipe3D = 3, TGeomRotObject3D = 4, TGeomCube3D = 5, TGeomSphere3D = 6,
44               TGeomGround = 7, TGeomCircle2D = 8, TGeomPolygon2D = 9, TGeomText2D = 10, TGeomLine2D = 11, TGeomTrig3D = 12, TGeomMesh3D = 13, TGeomOrthoCube3D = 14} TGeomElement;
45 
46 typedef enum { TDSDrawOutline = 1,     // GeomPolygon2D - does not scale zoom [pts]
47 							 TDSFillAreas = 2,       // GeomPolygon2D - disable when using non-convex polygons...
48 							 TDSHighlightPoints = 4, // GeomPolygon2D scales zoom [m]
49 							 TDSColoredLines = 8,    // GeomPolygon2D - does not scale zoom [pts]
50 							 TDSArrowHeadLines = 16, // GeomLine2D - scales zoom [m]
51 } TDrawStyle;
52 
53 //either fixed to ground (element==0) or fixed to element with pointer to element
54 class GeomElement
55 {
56 public:
GeomElement()57 	GeomElement():locpoints(), ptd(), pt(), locpoints2D(), ptd2D(), pt2D(), nodenums()
58 	{
59 		col = Vector3D(0,0,0); elnum = 0; objdata = 0; mbs = 0; draw_dim = Vector3D(0.001,4,0);
60 		drawstyle = TDSDrawOutline | TDSFillAreas; pointsize = 0.1; linethickness = 1.;
61 		transparency = 1; translated = Vector3D(0,0,0);
62 		name = GetElementSpec();
63 	}
GeomElement(const Vector3D & coli)64 	GeomElement(const Vector3D& coli):locpoints(), ptd(), pt(), locpoints2D(), ptd2D(), pt2D(), nodenums()
65 	{
66 		col = coli; elnum = 0; objdata = 0; mbs = 0; draw_dim = Vector3D(0.001,4,0);
67 		drawstyle = TDSDrawOutline | TDSFillAreas; pointsize = 0.1; linethickness = 1.;
68 		transparency = 1; translated = Vector3D(0,0,0);
69 		name = GetElementSpec();
70 	}
GeomElement(MBS * mbsI)71 	GeomElement(MBS* mbsI):locpoints(), ptd(), pt(), locpoints2D(), ptd2D(), pt2D(), nodenums()
72 	{
73 		mbs = mbsI;
74 		ElementDefaultConstructorInitialization();
75 	}
76 	virtual void ElementDefaultConstructorInitialization();
77 
CopyFrom(const GeomElement & e)78 	virtual void CopyFrom(const GeomElement& e)
79 	{
80 		col = e.col;
81 		locpoints = e.locpoints;
82 		ptd = e.ptd;
83 		pt = e.pt;
84 		locpoints2D = e.locpoints2D;
85 		ptd2D = e.ptd2D;
86 		pt2D = e.pt2D;
87 		nodenums = e.nodenums;
88 		elnum = e.elnum;
89 		objdata = e.objdata;
90 		mbs = e.mbs;
91 		draw_dim = e.draw_dim;
92 		transparency = e.transparency;
93 		name = e.name;
94 		translated = e.translated;
95 		drawstyle = e.drawstyle;
96 		pointsize = e.pointsize;
97 		linethickness = e.linethickness;
98 	}
99 
GeomElement(const GeomElement & e)100 	GeomElement(const GeomElement& e): locpoints(), ptd(), pt(), locpoints2D(), ptd2D(), pt2D(), nodenums()
101 	{
102 		CopyFrom(e);
103 	}
104 
105 	GeomElement& operator=(const GeomElement& e)
106 	{
107 		if (this == &e) {return *this;}
108 		CopyFrom(e);
109 		return *this;
110 	}
111 
~GeomElement()112 	virtual ~GeomElement()
113 	{
114 		locpoints.Flush();
115 		ptd.Flush();
116 		pt.Flush();
117 		locpoints2D.Flush();
118 		ptd2D.Flush();
119 		pt2D.Flush();
120 		nodenums.Flush();
121 	}
122 
GetCopy()123 	virtual GeomElement* GetCopy() const
124 	{
125 		GeomElement* ed = new GeomElement(*this);
126 		return ed;
127 	}
128 
GetName()129 	virtual const mystr& GetName() const {return name;}
GetName()130 	virtual mystr& GetName() {return name;}
SetName(const char * nameI)131 	virtual void SetName(const char* nameI) {name = nameI;}
GetElementSpec()132 	virtual const char* GetElementSpec() const {return "GeomElement";}
GetType()133 	virtual TGeomElement GetType() const {return TGeomGeneral;}
134 
DrawStyle()135 	virtual int& DrawStyle() { return drawstyle; }
PointSize()136 	virtual double& PointSize() { return pointsize; }
LineThickness()137 	virtual double& LineThickness() { return linethickness; }
138 
139 	virtual void GetElementData(ElementDataContainer& edc); 		//fill in all element data
140 	virtual int SetElementData(const ElementDataContainer& edc); //set element data acc. to ElementDataContainer, return 0 if failed or values invalid!
141 
Translate(const Vector3D & translate)142 	virtual void Translate(const Vector3D& translate) {assert(0);};
ComputeVolume()143 	virtual double ComputeVolume() const {assert(0); return 0;};
ComputeCenterOfMass()144 	virtual Vector3D ComputeCenterOfMass() const {assert(0); return Vector3D(0.,0.,0.);};
145 	virtual Matrix3D ComputeMassMomentOfInertia(double rho = 1) const {assert(0); return Matrix3D(0.);};
146 
GetBoundingBoxD()147 	virtual Box3D GetBoundingBoxD() const
148 	{
149 		Box3D b;
150 		AddBoundingBoxD(b);
151 		return b;
152 	}
153 
GetBoundingBox()154 	virtual Box3D GetBoundingBox() const
155 	{
156 		Box3D b;
157 		AddBoundingBox(b);
158 		return b;
159 	}
160 
GetBoundingBoxD2D()161 	virtual Box2D GetBoundingBoxD2D() const
162 	{
163 		Box2D b;
164 		AddBoundingBoxD2D(b);
165 		return b;
166 	}
167 
GetBoundingBox2D()168 	virtual Box2D GetBoundingBox2D() const
169 	{
170 		Box2D b;
171 		AddBoundingBox2D(b);
172 		return b;
173 	}
174 
175 
176 	//3D: +++++++++++++++++++++++++++++++++++++
CopyPt()177 	virtual void CopyPt()
178 	{
179 		for (int i=1; i <= locpoints.Length(); i++)
180 		{
181 			pt(i) = locpoints(i);
182 		}
183 	}
184 
CopyPtD()185 	virtual void CopyPtD()
186 	{
187 		for (int i=1; i <= locpoints.Length(); i++)
188 		{
189 			ptd(i) = locpoints(i);
190 		}
191 	}
192 
193 	virtual void SetDrawPoints();
194 	virtual void SetComputePoints();
195 
196 	//2D: +++++++++++++++++++++++++++++++++++++
197 	virtual void CopyPt2D();
198 	virtual void CopyPtD2D();
199 	virtual void SetDrawPoints2D();
200 	virtual void SetComputePoints2D();
201 
DrawYourself()202 	virtual void DrawYourself() {}; //DrawYourself(WCDInterface::RenderContext* pCurrentRC)
203 
204 
205 	//to transform locpoints into deformed or rotated configuration:
GetPoints()206 	virtual const TArray<Vector3D> & GetPoints() {return locpoints;}
207 
GetPointsTransformedD()208 	virtual TArray<Vector3D> & GetPointsTransformedD() {return ptd;}
GetPointsTransformedD()209 	virtual const TArray<Vector3D> & GetPointsTransformedD() const {return ptd;}
210 
GetPointsTransformed()211 	virtual TArray<Vector3D> & GetPointsTransformed() {return pt;}
GetPointsTransformed()212 	virtual const TArray<Vector3D> & GetPointsTransformed() const {return pt;}
213 
GetPoints2D()214 	virtual const TArray<Vector2D> & GetPoints2D() {return locpoints2D;}
215 
GetPointsTransformedD2D()216 	virtual TArray<Vector2D> & GetPointsTransformedD2D() {return ptd2D;}
GetPointsTransformedD2D()217 	virtual const TArray<Vector2D> & GetPointsTransformedD2D() const {return ptd2D;}
218 
GetPointsTransformed2D()219 	virtual TArray<Vector2D> & GetPointsTransformed2D() {return pt2D;}
GetPointsTransformed2D()220 	virtual const TArray<Vector2D> & GetPointsTransformed2D() const {return pt2D;}
221 
222 
PT(int i)223 	virtual const Vector3D& PT(int i) const {return pt(i);}
PTD(int i)224 	virtual const Vector3D& PTD(int i) const {return ptd(i);}
225 
PT2D(int i)226 	virtual const Vector2D& PT2D(int i) const {return pt2D(i);}
PTD2D(int i)227 	virtual const Vector2D& PTD2D(int i) const {return ptd2D(i);}
228 
229 	//e.g. for cutting plane and others
GetRefPosD()230 	virtual Vector3D GetRefPosD(/*int ind, const Vector3D& pglob*/) const
231 	{
232 		return GetBoundingBoxD().Center();
233 	}
234 
235 	//local position
GetLocPoint(int i)236 	virtual Vector3D GetLocPoint(int i) const
237 	{
238 		return locpoints(i);
239 	}
240 
GetLocPoint2D(int i)241 	virtual Vector2D GetLocPoint2D(int i) const
242 	{
243 		return locpoints2D(i);
244 	}
245 
AddLocPoint(const Vector3D & p)246 	virtual int AddLocPoint(const Vector3D& p) {return locpoints.Add(p);}
AddLocPoint2D(const Vector2D & p)247 	virtual int AddLocPoint2D(const Vector2D& p) {return locpoints2D.Add(p);}
248 
249 
250 	//actual (global) position:
251 	virtual Vector3D GetTPoint(int i) const;
252 	virtual Vector3D GetTPointD(int i) const;
253 	virtual Vector2D GetTPoint2D(int i) const;
254 	virtual Vector2D GetTPointD2D(int i) const;
255 	virtual Vector3D ToP3D(const Vector2D& p) const;
256 	virtual Vector2D GetPos2D(const Vector2D& ploc) const;
257 	virtual Vector2D GetVel2D(const Vector2D& ploc) const;
258 
259 	virtual Vector3D GetPos(const Vector3D& ploc) const;
260 	virtual Vector3D GetVel(const Vector3D& ploc) const;
261 
NP()262 	virtual int NP() const {return locpoints.Length() + locpoints2D.Length();} //one of the two arrays must be zero!!!
263 
264 	virtual const Element& GetElement() const;
265 	//$ YV 2012-12-10: commented out
266 	/*virtual const Body2D& GetBody2D() const;
267 	virtual Body2D& GetBody2D();
268 	virtual const Body3D& GetBody3D() const;
269 	virtual Body3D& GetBody3D();*/
270 	virtual MBS* GetMBS() const;
271 
GetElnum()272 	virtual int GetElnum() const {return elnum;}
SetElnum(int en)273 	virtual void SetElnum(int en) {elnum = en;}
GetObjdata()274 	virtual int GetObjdata() const {return objdata;}
SetObjectdata(int od)275 	virtual void SetObjectdata(int od) {objdata = od;}
276 
GetNodeNum(int i)277 	virtual int GetNodeNum(int i) const
278 	{
279 		if (nodenums.Length() == locpoints.Length()) return nodenums(i);
280 		else return 0;
281 	}
282 
SetDrawParam(const Vector3D & v)283 	virtual void SetDrawParam(const Vector3D& v) {draw_dim = v;}
284 
285 	//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
286 	//functions to be set by each GeomElement:
287 
288 	//add bounding boxes to existing box
AddBoundingBoxD(Box3D & box)289 	virtual void AddBoundingBoxD(Box3D& box) const
290 	{
291 		if (locpoints2D.Length() != 0)
292 		{
293 			for (int i=1; i <= locpoints2D.Length(); i++) box.Add(ToP3D(GetTPointD2D(i)));
294 		}
295 		else
296 			for (int i=1; i <= locpoints.Length(); i++) box.Add(GetTPointD(i));
297 	}
298 
AddBoundingBox(Box3D & box)299 	virtual void AddBoundingBox(Box3D& box) const
300 	{
301 		if (locpoints2D.Length() != 0)
302 		{
303 			for (int i=1; i <= locpoints2D.Length(); i++) box.Add(ToP3D(GetTPoint2D(i)));
304 		}
305 		else
306 			for (int i=1; i <= locpoints.Length(); i++) box.Add(GetTPoint(i));
307 	}
308 
AddBoundingBoxD2D(Box2D & box)309 	virtual void AddBoundingBoxD2D(Box2D& box) const
310 	{
311 		for (int i=1; i <= locpoints2D.Length(); i++) box.Add(GetTPointD2D(i));
312 	}
313 
AddBoundingBox2D(Box2D & box)314 	virtual void AddBoundingBox2D(Box2D& box) const
315 	{
316 		for (int i=1; i <= locpoints2D.Length(); i++) box.Add(GetTPoint2D(i));
317 	}
318 
319 	//Get nearest global point pp on element from global point p, ind is the index of found segment, returns the signed gap/penetration
GetNearestPoint(const Vector2D & p,int & ind,Vector2D & pp)320 	virtual double GetNearestPoint(const Vector2D& p, int& ind, Vector2D& pp) {assert(0); return 0;}
321 
322 	//get local position on element from global position and index (for polygon etc.)
GetLocPos(int ind,const Vector2D & pglob)323 	virtual Vector2D GetLocPos(int ind, const Vector2D& pglob) const {assert(0); return Vector2D(0.,0.);};
324 
325 	//get (deformed) normalized normal vector (outwards) at locpos
GetNormal(int ind,const Vector2D & ploc)326 	virtual Vector2D GetNormal(int ind, const Vector2D& ploc) const {assert(0); return Vector2D(0.,0.);};
327 
328 	//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
329 	//3D:
330 	//Get nearest global point pp on element from global point p, ind is the index of found segment, returns the signed gap/penetration
GetNearestPoint(const Vector3D & p,int & ind,Vector3D & pp)331 	virtual double GetNearestPoint(const Vector3D& p, int& ind, Vector3D& pp) {assert(0); return 0;}
332 
333 	//get local position on element from global position and index (for polygon etc.)
GetLocPos(int ind,const Vector3D & pglob)334 	virtual Vector3D GetLocPos(int ind, const Vector3D& pglob) const {assert(0); return Vector3D(0.,0.,0.);};
335 
336 	//get (deformed) normalized normal vector (outwards) at locpos
GetNormal(int ind,const Vector3D & ploc)337 	virtual Vector3D GetNormal(int ind, const Vector3D& ploc) const {assert(0); return Vector3D(0.,0.,0.);};
338 
339 	//get (deformed) normalized unique tangent vector at locpos
GetTangent(int ind,const Vector3D & ploc)340 	virtual Vector3D GetTangent(int ind, const Vector3D& ploc) const {assert(0); return Vector3D(0.,0.,0.);};
341 
GetCol()342 	virtual const Vector3D& GetCol() const {return col;}
SetCol(const Vector3D & colI)343 	virtual void SetCol(const Vector3D& colI) {col = colI;}
344 	virtual void SetGeomElementColor();
GetTransparency()345 	virtual float GetTransparency() const {return transparency;}
SetTransparency(float transparencyI)346 	virtual void SetTransparency(float transparencyI) {transparency = transparencyI;}
347 
348 protected:
349 	mystr name;								 //name for load/save, dialogs
350 	Vector3D col;
351 	float transparency;				 //object transparency; 0=transparent, 1=solid
352 	Vector3D draw_dim;				 //(linewidth, #segments for curved shapes, 0)
353 	MBS* mbs;
354 	int elnum;								 //element number
355 	int objdata;							 //position refers to objectdata in MBS
356 	TArray<int> nodenums;			 //2D and 3D node number; 0 if does not exist
357 	Vector3D translated;			 //Geometry has been translated (e.g. for center of mass)
358 
359 	int drawstyle;						 // drawstyle according to enum
360 	double pointsize;          // drawsize of highlighted points
361 	double linethickness;      // thickness of colored lines
362 
363 	//3D:
364 	TArray<Vector3D> locpoints;//local points
365 	TArray<Vector3D> ptd;		   //transformed points
366 	TArray<Vector3D> pt;       //transformed points for computation
367 	//2D:
368 	TArray<Vector2D> locpoints2D; //local points
369 	TArray<Vector2D> ptd2D;    //transformed points
370 	TArray<Vector2D> pt2D;     //transformed points for computation
371 };
372 
373 
374 
375 
376 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
377 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
378 
379 
380 class GeomText2D:public GeomElement
381 {
382 public:
GeomText2D()383 	GeomText2D():GeomElement()
384 	{
385 		locpoints2D.SetLen(0);
386 		ptd2D.SetLen(0);
387 		pt2D.SetLen(0);
388 	}
GetCopy()389 	virtual GeomElement* GetCopy() const
390 	{
391 		GeomElement* ed = new GeomText2D(*this);
392 		return ed;
393 	}
GeomText2D(const GeomText2D & e)394 	GeomText2D(const GeomText2D& e):GeomElement(e) {CopyFrom(e);}
CopyFrom(const GeomElement & e)395 	virtual void CopyFrom(const GeomElement& e)
396 	{
397 		GeomElement::CopyFrom(e);
398 		const GeomText2D& ce = (const GeomText2D&)e;
399 
400 		row = ce.row;
401 		alignment = ce.alignment;
402 		text = new char[strlen(ce.text)+1];
403 		strcpy(text, ce.text);
404 	}
405 
406 	GeomText2D(MBS* mbsi, int elnumi, const char* textI, int rowI, int alignmentI, const Vector3D& coli);
407 
~GeomText2D()408 	virtual ~GeomText2D()
409 	{
410 		delete[] text;
411 		GeomElement::~GeomElement();
412 	}
GetElementSpec()413 	virtual const char* GetElementSpec() const {return "GeomText2D";}
GetType()414 	virtual TGeomElement GetType() const {return TGeomText2D;}
415 
416 	virtual void DrawYourself();
417 
418 private:
419 	int alignment;
420 	int row;
421 	char* text;
422 };
423 
424 
425 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
426 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
427 
428 
429 class GeomLine2D:public GeomElement
430 {
431 public:
GeomLine2D()432 	GeomLine2D():GeomElement()
433 	{
434 		locpoints2D.SetLen(2);
435 		ptd2D.SetLen(2);
436 		pt2D.SetLen(2);
437 	}
GetCopy()438 	virtual GeomElement* GetCopy() const
439 	{
440 		GeomElement* ed = new GeomLine2D(*this);
441 		return ed;
442 	}
GeomLine2D(const GeomLine2D & e)443 	GeomLine2D(const GeomLine2D& e):GeomElement(e) {CopyFrom(e);}
444 
445 	GeomLine2D(MBS* mbsi, int elnumi, const Vector2D& p1, const Vector2D& p2, const Vector3D& coli);
446 
447 	GeomLine2D(MBS* mbsi, int elnumi, int n1, int n2, const Vector3D& coli);
448 
GetElementSpec()449 	virtual const char* GetElementSpec() const {return "GeomLine2D";}
GetType()450 	virtual TGeomElement GetType() const {return TGeomLine2D;}
451 
452 	//Get nearest global point pp on element from global point p, ind is the index of found segment, returns the signed gap/penetration
453 	virtual double GetNearestPoint(const Vector2D& p, int& ind, Vector2D& pp);
454 
455 	//get local position on element from global position and index (for polygon etc.)
456 	virtual Vector2D GetLocPos(int ind, const Vector2D& pglob) const;
457 
458 	//get (deformed) normalized normal vector (outwards) at locpos
459 	virtual Vector2D GetNormal(int ind, const Vector2D& ploc) const;
460 	virtual void DrawYourself();
461 
462 	//private:
463 };
464 
465 
466 
467 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
468 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
469 
470 
471 class GeomPolygon2D:public GeomElement
472 {
473 public:
GeomPolygon2D()474 	GeomPolygon2D():GeomElement()
475 	{}
476 
GetCopy()477 	virtual GeomElement* GetCopy() const
478 	{
479 		GeomElement* ed = new GeomPolygon2D(*this);
480 		return ed;
481 	}
GeomPolygon2D(const GeomPolygon2D & e)482 	GeomPolygon2D(const GeomPolygon2D& e):GeomElement(e) {CopyFrom(e);}
483 
484 	GeomPolygon2D(MBS* mbsi, int elnumi, const TArray<Vector2D>& p, const Vector3D& coli);
485 	//GeomPolygon2D(MBS* mbsi, int elnumi, int n1, int n2, const Vector3D& coli);
486 
GetElementSpec()487 	virtual const char* GetElementSpec() const {return "GeomPolygon2D";}
GetType()488 	virtual TGeomElement GetType() const {return TGeomPolygon2D;}
489 
490 	//Get nearest global point pp on element from global point p, ind is the index of found segment, returns the signed gap/penetration
GetNearestPoint(const Vector2D & p,int & ind,Vector2D & pp)491 	virtual double GetNearestPoint(const Vector2D& p, int& ind, Vector2D& pp) {assert(0); return 0;};
492 
493 	//get local position on element from global position and index (for polygon etc.)
GetLocPos(int ind,const Vector2D & pglob)494 	virtual Vector2D GetLocPos(int ind, const Vector2D& pglob) const {assert(0); return Vector2D(0,0);};
495 
496 	//get (deformed) normalized normal vector (outwards) at locpos
GetNormal(int ind,const Vector2D & ploc)497 	virtual Vector2D GetNormal(int ind, const Vector2D& ploc) const {assert(0); return Vector2D(0,0);}
498 	virtual void DrawYourself();
499 	virtual int ReadFromFile(mystr& filename);
500 	//private:
501 };
502 
503 
504 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
505 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
506 
507 
508 class GeomCircle2D:public GeomElement
509 {
510 public:
GeomCircle2D()511 	GeomCircle2D():GeomElement()
512 	{
513 		locpoints2D.SetLen(2);
514 		ptd2D.SetLen(2);
515 		pt2D.SetLen(2);
516 	}
GetCopy()517 	virtual GeomElement* GetCopy() const
518 	{
519 		GeomElement* ed = new GeomCircle2D(*this);
520 		return ed;
521 	}
CopyFrom(const GeomElement & e)522 	virtual void CopyFrom(const GeomElement& e)
523 	{
524 		GeomElement::CopyFrom(e);
525 		const GeomCircle2D& ce = (const GeomCircle2D&)e;
526 
527 		r = ce.r;
528 	}
529 
GeomCircle2D(const GeomCircle2D & e)530 	GeomCircle2D(const GeomCircle2D& e):GeomElement(e) {CopyFrom(e);}
531 
532 	//full circle:
533 	GeomCircle2D(MBS* mbsi, int elnumi, const Vector2D& p1, double rad, const Vector3D& coli);
534 
535 	//only segment:
536 	GeomCircle2D(MBS* mbsi, int elnumi, const Vector2D& p1, const Vector2D& pseg1, const Vector2D& pseg2, double rad, const Vector3D& coli);
537 
GetElementSpec()538 	virtual const char* GetElementSpec() const {return "GeomCircle2D";}
GetType()539 	virtual TGeomElement GetType() const {return TGeomCircle2D;}
540 
541 	//add bounding boxes to existing box
AddBoundingBoxD(Box3D & box)542 	virtual void AddBoundingBoxD(Box3D& box) const
543 	{
544 		Vector2D p(GetTPointD2D(1));
545 		box.Add(Box3D(ToP3D(p+Vector2D(-r,-r)),ToP3D(p+Vector2D(r,r))));
546 	}
547 
AddBoundingBox(Box3D & box)548 	virtual void AddBoundingBox(Box3D& box) const
549 	{
550 		Vector2D p(GetTPoint2D(1));
551 		box.Add(Box3D(ToP3D(p+Vector2D(-r,-r)),ToP3D(p+Vector2D(r,r))));
552 	}
553 
AddBoundingBoxD2D(Box2D & box)554 	virtual void AddBoundingBoxD2D(Box2D& box) const
555 	{
556 		Vector2D p(GetTPointD2D(1));
557 		box.Add(Box2D(p+Vector2D(-r,-r),p+Vector2D(r,r)));
558 	}
559 
AddBoundingBox2D(Box2D & box)560 	virtual void AddBoundingBox2D(Box2D& box) const
561 	{
562 		Vector2D p(GetTPoint2D(1));
563 		box.Add(Box2D(p+Vector2D(-r,-r),p+Vector2D(r,r)));
564 	}
565 
566 	//Get nearest global point pp on element from global point p, ind is the index of found segment, returns the signed gap/penetration
567 	virtual double GetNearestPoint(const Vector2D& p, int& ind, Vector2D& pp);
568 
569 	//get local position on element from global position and index (for polygon etc.)
570 	virtual Vector2D GetLocPos(int ind, const Vector2D& pglob) const;
571 
572 	//get (deformed) normalized normal vector (outwards) at locpos
573 	virtual Vector2D GetNormal(int ind, const Vector2D& ploc) const;
574 	virtual void DrawYourself();
575 
576 private:
577 	double r; //radius of circle
578 };
579 
580 
581 
582 
583 
584 
585 
586 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
587 //             3D GeomQuad
588 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
589 
590 class GeomQuad3D:public GeomElement
591 {
592 public:
GeomQuad3D()593 	GeomQuad3D():GeomElement()
594 	{
595 		locpoints.SetLen(4);
596 		ptd.SetLen(4);
597 		pt.SetLen(4);
598 	}
GetCopy()599 	virtual GeomElement* GetCopy() const
600 	{
601 		GeomElement* ed = new GeomQuad3D(*this);
602 		return ed;
603 	}
GeomQuad3D(const GeomQuad3D & e)604 	GeomQuad3D(const GeomQuad3D& e):GeomElement(e) {CopyFrom(e);}
605 
GeomQuad3D(MBS * mbsi,const Vector3D & p1,const Vector3D & p2,const Vector3D & p3,const Vector3D & p4,const Vector3D & coli)606 	GeomQuad3D(MBS* mbsi, const Vector3D& p1, const Vector3D& p2, const Vector3D& p3, const Vector3D& p4, const Vector3D& coli):GeomElement()
607 	{
608 		mbs = mbsi;
609 		col = coli;
610 		elnum = 0;
611 
612 		locpoints.SetLen(4);
613 		ptd.SetLen(4);
614 		pt.SetLen(4);
615 
616 		locpoints(1) = p1;
617 		locpoints(2) = p2;
618 		locpoints(3) = p3;
619 		locpoints(4) = p4;
620 		CopyPt();
621 		CopyPtD();
622 	}
GetElementSpec()623 	virtual const char* GetElementSpec() const {return "GeomQuad3D";}
GetType()624 	virtual TGeomElement GetType() const {return TGeomQuad3D;}
625 
626 	virtual void DrawYourself();
627 
628 
629 	//private:
630 };
631 
632 
633 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
634 //             3D GeomTrig
635 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
636 
637 class GeomTrig3D:public GeomElement
638 {
639 public:
GeomTrig3D()640 	GeomTrig3D():GeomElement()
641 	{
642 		locpoints.SetLen(3);
643 		ptd.SetLen(3);
644 		pt.SetLen(3);
645 	}
GetCopy()646 	virtual GeomElement* GetCopy() const
647 	{
648 		GeomElement* ed = new GeomTrig3D(*this);
649 		return ed;
650 	}
GeomTrig3D(const GeomTrig3D & e)651 	GeomTrig3D(const GeomTrig3D& e):GeomElement(e) {CopyFrom(e);}
652 
GeomTrig3D(MBS * mbsI,int elnumI,const Vector3D & p1,const Vector3D & p2,const Vector3D & p3,const Vector3D & colI)653 	GeomTrig3D(MBS* mbsI, int elnumI, const Vector3D& p1, const Vector3D& p2, const Vector3D& p3, const Vector3D& colI):GeomElement()
654 	{
655 		mbs = mbsI;
656 		col = colI;
657 		elnum = elnumI;
658 
659 		locpoints.SetLen(3);
660 		ptd.SetLen(3);
661 		pt.SetLen(3);
662 
663 		locpoints(1) = p1;
664 		locpoints(2) = p2;
665 		locpoints(3) = p3;
666 		CopyPt();
667 		CopyPtD();
668 	}
669 
GetElementSpec()670 	virtual const char* GetElementSpec() const {return "GeomTrig3D";}
GetType()671 	virtual TGeomElement GetType() const {return TGeomTrig3D;}
672 
673 	//Get nearest global point pp on element from global point p, ind is the index of found segment, returns the signed gap/penetration
674 	virtual double GetNearestPoint(const Vector3D& p, int& ind, Vector3D& pp);
675 
676 	//get local position on element from global position and index (for polygon etc.)
677 	virtual Vector3D GetLocPos(int ind, const Vector3D& pglob) const;
678 
679 	//get (deformed) normalized normal vector (outwards) at locpos
680 	virtual Vector3D GetNormal(int ind, const Vector3D& ploc) const;
681 
682 	//get (deformed) normalized unique tangent vector at locpos
683 	virtual Vector3D GetTangent(int ind, const Vector3D& ploc) const;
684 
685 	virtual void DrawYourself();
686 
687 
688 	//private:
689 };
690 
691 
692 
693 
694 
695 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
696 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
697 
698 class GeomCube3D:public GeomElement
699 {
700 public:
701 	//binary ordering of locpoints: X=0/1: i+=1, Y=0/1: i+=2, Z=0/1: i+=4
702 	//#outer surface right: 2-4-8-6
703 	//#outer surface left:  1-3-7-5
704 	//#bottom: 1-2-4-3
705 	//#top: 5-6-8-7
GeomCube3D()706 	GeomCube3D():GeomElement()
707 	{
708 		locpoints.SetLen(8);
709 		ptd.SetLen(8);
710 		pt.SetLen(8);
711 	}
GetCopy()712 	virtual GeomElement* GetCopy() const
713 	{
714 		GeomElement* ed = new GeomCube3D(*this);
715 		return ed;
716 	}
GeomCube3D(const GeomCube3D & e)717 	GeomCube3D(const GeomCube3D& e):GeomElement(e) {CopyFrom(e);}
718 
GeomCube3D(MBS * mbsi,const Vector3D & pmid,const Vector3D & size,const Vector3D & coli)719 	GeomCube3D(MBS* mbsi, const Vector3D& pmid, const Vector3D& size, const Vector3D& coli):GeomElement(mbsi)
720 	{
721 		elnum = 0;
722 		mbs = mbsi;
723 		col = coli;
724 		Vector3D size2 = 0.5*size;
725 		SetLocPoints(pmid, size2);
726 		CopyPt();
727 		CopyPtD();
728 	}
729 
730 	//rectangular ground-shape, 4 individual heights
GeomCube3D(MBS * mbsi,const Vector3D & p0,double xsize,double ysize,double z1,double z2,double z3,double z4,const Vector3D & coli)731 	GeomCube3D(MBS* mbsi, const Vector3D& p0, double xsize, double ysize, double z1, double z2, double z3, double z4, const Vector3D& coli):GeomElement(mbsi)
732 	{
733 		elnum = 0;
734 		mbs = mbsi;
735 		col = coli;
736 		locpoints(1) = p0+Vector3D(0.   ,0.   ,0.);
737 		locpoints(2) = p0+Vector3D(xsize,0.   ,0.);
738 		locpoints(3) = p0+Vector3D(0.   ,ysize,0.);
739 		locpoints(4) = p0+Vector3D(xsize,ysize,0.);
740 		locpoints(5) = p0+Vector3D(0.   ,0.   ,z1);
741 		locpoints(6) = p0+Vector3D(xsize,0.   ,z2);
742 		locpoints(7) = p0+Vector3D(0.   ,ysize,z3);
743 		locpoints(8) = p0+Vector3D(xsize,ysize,z4);
744 		CopyPt();
745 		CopyPtD();
746 	}
747 
748 	//arbitrary ground-shape, one height
GeomCube3D(MBS * mbsi,const Vector3D & p1,const Vector3D & p2,const Vector3D & p3,const Vector3D & p4,double z,const Vector3D & coli)749 	GeomCube3D(MBS* mbsi, const Vector3D& p1, const Vector3D& p2, const Vector3D& p3, const Vector3D& p4, double z, const Vector3D& coli):GeomElement(mbsi)
750 	{
751 		elnum = 0;
752 		mbs = mbsi;
753 		col = coli;
754 		locpoints(1) = p1;
755 		locpoints(2) = p2;
756 		locpoints(3) = p3;
757 		locpoints(4) = p4;
758 		locpoints(5) = p1+Vector3D(0.,0.,z);
759 		locpoints(6) = p2+Vector3D(0.,0.,z);
760 		locpoints(7) = p3+Vector3D(0.,0.,z);
761 		locpoints(8) = p4+Vector3D(0.,0.,z);
762 		CopyPt();
763 		CopyPtD();
764 	}
765 
GeomCube3D(MBS * mbsi,const Vector3D & p1,const Vector3D & p2,const Vector3D & p3,const Vector3D & p4,const Vector3D & p5,const Vector3D & p6,const Vector3D & p7,const Vector3D & p8,const Vector3D & coli)766 	GeomCube3D(MBS* mbsi, const Vector3D& p1, const Vector3D& p2, const Vector3D& p3, const Vector3D& p4,
767 		const Vector3D& p5, const Vector3D& p6, const Vector3D& p7, const Vector3D& p8, const Vector3D& coli):GeomElement(mbsi)
768 	{
769 		elnum = 0;
770 		mbs = mbsi;
771 		col = coli;
772 		locpoints(1) = p1;
773 		locpoints(2) = p2;
774 		locpoints(3) = p3;
775 		locpoints(4) = p4;
776 		locpoints(5) = p5;
777 		locpoints(6) = p6;
778 		locpoints(7) = p7;
779 		locpoints(8) = p8;
780 		CopyPt();
781 		CopyPtD();
782 	}
783 
GetElementSpec()784 	virtual const char* GetElementSpec() const {return "GeomCube3D";}
GetType()785 	virtual TGeomElement GetType() const {return TGeomCube3D;}
786 
787 	virtual void GetElementData(ElementDataContainer& edc); 		//fill in all element data
788 	virtual int SetElementData(const ElementDataContainer& edc); //set element data acc. to ElementDataContainer, return 0 if failed or values invalid!
789 
790 	virtual void GetTrigs(TArray<int3>& trigs) const;
SetLocPoints(const Vector3D center_point,const Vector3D size)791 	virtual void SetLocPoints(const Vector3D center_point, const Vector3D size)
792 	{
793 		locpoints(1) = center_point+Vector3D(-size.X(),-size.Y(),-size.Z());
794 		locpoints(2) = center_point+Vector3D( size.X(),-size.Y(),-size.Z());
795 		locpoints(3) = center_point+Vector3D(-size.X(), size.Y(),-size.Z());
796 		locpoints(4) = center_point+Vector3D( size.X(), size.Y(),-size.Z());
797 		locpoints(5) = center_point+Vector3D(-size.X(),-size.Y(), size.Z());
798 		locpoints(6) = center_point+Vector3D( size.X(),-size.Y(), size.Z());
799 		locpoints(7) = center_point+Vector3D(-size.X(), size.Y(), size.Z());
800 		locpoints(8) = center_point+Vector3D( size.X(), size.Y(), size.Z());
801 	}
802 	virtual void Translate(const Vector3D& translate);
803 	virtual void Rotate(const Matrix3D& rotate);
804 	virtual double ComputeVolume() const;
805 	virtual Vector3D ComputeCenterOfMass() const;
806 	virtual Matrix3D ComputeMassMomentOfInertia(double rho = 1) const;
807 
808 	virtual void DrawYourself();
809 
810 	//private:
811 };
812 
813 
814 
815 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
816 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
817 // orthogonal cube with stored center point and rotation matrix
818 class GeomOrthoCube3D:public GeomCube3D
819 {
820 public:
821 	//binary ordering of locpoints: X=0/1: i+=1, Y=0/1: i+=2, Z=0/1: i+=4
822 	//#outer surface right: 2-4-8-6
823 	//#outer surface left:  1-3-7-5
824 	//#bottom: 1-2-4-3
825 	//#top: 5-6-8-7
826 	//#center point stored
GeomOrthoCube3D()827 	GeomOrthoCube3D():GeomCube3D()
828 	{
829 		locpoints.SetLen(9);
830 		ptd.SetLen(9);
831 		pt.SetLen(9);
832 		A = Matrix3D(1.);
833 		size = Vector3D(1.);
834 	}
GetCopy()835 	virtual GeomElement* GetCopy() const
836 	{
837 		GeomElement* ed = new GeomOrthoCube3D(*this);
838 
839 		return ed;
840 	}
GeomOrthoCube3D(const GeomOrthoCube3D & e)841 	GeomOrthoCube3D(const GeomOrthoCube3D& e):GeomCube3D(e) {CopyFrom(e);A = e.A;size = e.size;}
842 
GeomOrthoCube3D(MBS * mbsi,const Vector3D & pmid,const Vector3D & sizei,const Matrix3D & Ai,const Vector3D & coli)843 	GeomOrthoCube3D(MBS* mbsi, const Vector3D& pmid, const Vector3D& sizei, const Matrix3D& Ai, const Vector3D& coli):GeomCube3D(mbsi, pmid, sizei, coli)
844 	{
845 		locpoints.SetLen(9);
846 		ptd.SetLen(9);
847 		pt.SetLen(9);
848 		A = Ai;
849 		size = sizei;
850 		SetLocPoints(pmid, size, A);
851 	}
852 
GetElementSpec()853 	virtual const char* GetElementSpec() const {return "GeomOrthoCube3D";}
GetType()854 	virtual TGeomElement GetType() const {return TGeomOrthoCube3D;}
855 
856 	virtual void GetElementData(ElementDataContainer& edc); 		//fill in all element data
857 	virtual int SetElementData(const ElementDataContainer& edc); //set element data acc. to ElementDataContainer, return 0 if failed or values invalid!
858 
859 	virtual void SetLocPoints(const Vector3D center_point, const Vector3D sizei, const Matrix3D A);
Translate(const Vector3D & translate)860 	virtual void Translate(const Vector3D& translate){GeomCube3D::Translate(translate);};
861 	virtual void Rotate(const Matrix3D& rotate);
ComputeVolume()862 	virtual double ComputeVolume() const{return size(1)*size(2)*size(3);};
ComputeCenterOfMass()863 	virtual Vector3D ComputeCenterOfMass() const{return locpoints(9);};
864 	virtual Matrix3D ComputeMassMomentOfInertia(double rho = 1) const{return GeomCube3D::ComputeMassMomentOfInertia(rho);};
865 
DrawYourself()866 	virtual void DrawYourself(){GeomCube3D::DrawYourself();}
867 
868 	private:
869 		Matrix3D A;
870 		Vector3D size;
871 };
872 
873 
874 
875 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
876 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
877 //$ SW 2013-11-13: extended GeomZyl3D such that it can now draw hollow cylinders
878 class GeomZyl3D:public GeomElement
879 {
880 public:
GeomZyl3D()881 	GeomZyl3D():GeomElement()
882 	{
883 		locpoints.SetLen(2);
884 		ptd.SetLen(2);
885 		pt.SetLen(2);
886 		ri = 0.;
887 	}
GetCopy()888 	virtual GeomElement* GetCopy() const
889 	{
890 		GeomElement* ed = new GeomZyl3D(*this);
891 		return ed;
892 	}
GeomZyl3D(const GeomZyl3D & e)893 	GeomZyl3D(const GeomZyl3D& e):GeomElement(e) {CopyFrom(e);}
894 
GeomZyl3D(MBS * mbsi,const Vector3D & pz1,const Vector3D & pz2,double rzi,int tilei,const Vector3D & coli)895 	GeomZyl3D(MBS* mbsi, const Vector3D& pz1, const Vector3D& pz2, double rzi, int tilei, const Vector3D& coli):GeomElement(mbsi)
896 	{
897 		elnum = 0;
898 		mbs = mbsi;
899 		col = coli;
900 		tile = tilei;
901 		rz = rzi;
902 		locpoints(1) = pz1;
903 		locpoints(2) = pz2;
904 		CopyPt();
905 		CopyPtD();
906 		ri = 0.;
907 	}
908 
CopyFrom(const GeomElement & e)909 	virtual void CopyFrom(const GeomElement& e)
910 	{
911 		GeomElement::CopyFrom(e);
912 		const GeomZyl3D& ce = (const GeomZyl3D&)e;
913 
914 		tile =ce.tile;
915 		rz = ce.rz;
916 		ri = ce.ri;
917 	}
918 
GetElementSpec()919 	virtual const char* GetElementSpec() const {return "GeomCylinder3D";}
GetType()920 	virtual TGeomElement GetType() const {return TGeomZyl3D;}
921 
922 	virtual void GetElementData(ElementDataContainer& edc); 		//fill in all element data
923 	virtual int SetElementData(const ElementDataContainer& edc); //set element data acc. to ElementDataContainer, return 0 if failed or values invalid!
924 
925 	virtual void Translate(const Vector3D& translate);
926 	virtual double ComputeVolume() const;
927 	virtual Vector3D ComputeCenterOfMass() const;
928 	virtual Matrix3D ComputeMassMomentOfInertia(double rho = 1) const;
929 
930 	virtual void DrawYourself();
931 
932 private:
933 	int tile;
934 	double rz;
935 	double ri;
936 };
937 
938 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
939 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
940 
941 //A full or partial pipe
942 //draw pipe from phimin to phimax with respect to Vector vrad
943 class GeomPipe3D:public GeomElement
944 {
945 public:
GeomPipe3D()946 	GeomPipe3D():GeomElement()
947 	{
948 		locpoints.SetLen(3);
949 		ptd.SetLen(3);
950 		pt.SetLen(3);
951 	}
GetCopy()952 	virtual GeomElement* GetCopy() const
953 	{
954 		GeomElement* ed = new GeomPipe3D(*this);
955 		return ed;
956 	}
GeomPipe3D(const GeomPipe3D & e)957 	GeomPipe3D(const GeomPipe3D& e):GeomElement(e) {CopyFrom(e);}
958 
959 	GeomPipe3D(MBS* mbsi, const Vector3D& pz0, const Vector3D& vaxis, const Vector3D& vrad, double riI, double roI, int tileI,
GeomElement(mbsi)960 		const Vector3D& coli, double phiminI=0, double phimaxI=2.*MY_PI, int drawendfaceI=1):GeomElement(mbsi)
961 	{
962 		elnum = 0;
963 		mbs = mbsi;
964 		col = coli;
965 		tile = tileI;
966 		if (tile == 0) tile = 1;
967 
968 		ri = riI;
969 		ro = roI;
970 		phimin = phiminI;
971 		phimax = phimaxI;
972 		drawendface = drawendfaceI;
973 
974 		Vector3D va = vaxis;
975 		Vector3D vr = vrad;
976 		vr.Normalize();
977 
978 		locpoints(1) = pz0;
979 		locpoints(2) = pz0 + va;
980 		locpoints(3) = pz0 + vr;
981 		CopyPt();
982 		CopyPtD();
983 	}
984 
CopyFrom(const GeomElement & e)985 	virtual void CopyFrom(const GeomElement& e)
986 	{
987 		GeomElement::CopyFrom(e);
988 		const GeomPipe3D& ce = (const GeomPipe3D&)e;
989 
990 		tile =ce.tile;
991 		ri = ce.ri;
992 		ro = ce.ro;
993 		phimin = ce.phimin;
994 		phimax = ce.phimax;
995 		drawendface = ce.drawendface;
996 	}
997 
GetElementSpec()998 	virtual const char* GetElementSpec() const {return "GeomPipe3D";}
GetType()999 	virtual TGeomElement GetType() const {return TGeomPipe3D;}
1000 
1001 	virtual void DrawYourself();
1002 
1003 private:
1004 	int tile;
1005 	double ri, ro; //inner and outer radius
1006 	double phimin, phimax;
1007 	int drawendface;
1008 };
1009 
1010 
1011 
1012 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1013 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1014 
1015 class GeomSphere3D:public GeomElement
1016 {
1017 public:
GeomSphere3D()1018 	GeomSphere3D():GeomElement()
1019 	{
1020 		locpoints.SetLen(1);
1021 		ptd.SetLen(1);
1022 		pt.SetLen(1);
1023 	}
GetCopy()1024 	virtual GeomElement* GetCopy() const
1025 	{
1026 		GeomElement* ed = new GeomSphere3D(*this);
1027 		return ed;
1028 	}
GeomSphere3D(const GeomSphere3D & e)1029 	GeomSphere3D(const GeomSphere3D& e):GeomElement(e) {CopyFrom(e);}
1030 
GeomSphere3D(MBS * mbsi,int elnumI,const Vector3D & pm,double rzi,int tilei,const Vector3D & coli)1031 	GeomSphere3D(MBS* mbsi, int elnumI, const Vector3D& pm, double rzi, int tilei, const Vector3D& coli):GeomElement(mbsi)
1032 	{
1033 		elnum = elnumI;
1034 		mbs = mbsi;
1035 		col = coli;
1036 		draw_dim.Y() = tilei;
1037 		rz = rzi;
1038 
1039 		locpoints.SetLen(1);
1040 		ptd.SetLen(1);
1041 		pt.SetLen(1);
1042 		locpoints(1) = pm;
1043 
1044 		CopyPt();
1045 		CopyPtD();
1046 	}
1047 
CopyFrom(const GeomElement & e)1048 	virtual void CopyFrom(const GeomElement& e)
1049 	{
1050 		GeomElement::CopyFrom(e);
1051 		const GeomSphere3D& ce = (const GeomSphere3D&)e;
1052 
1053 		rz = ce.rz;
1054 	}
1055 
GetElementSpec()1056 	virtual const char* GetElementSpec() const {return "GeomSphere3D";}
GetType()1057 	virtual TGeomElement GetType() const {return TGeomSphere3D;}
1058 
1059 	virtual void GetElementData(ElementDataContainer& edc); 		//fill in all element data
1060 	virtual int SetElementData(const ElementDataContainer& edc); //set element data acc. to ElementDataContainer, return 0 if failed or values invalid!
1061 
1062 	virtual void Translate(const Vector3D& translate);
1063 	virtual double ComputeVolume() const;
1064 	virtual Vector3D ComputeCenterOfMass() const;
1065 	virtual Matrix3D ComputeMassMomentOfInertia(double rho = 1) const;
1066 
1067 	//add bounding boxes to existing box
AddBoundingBoxD(Box3D & box)1068 	virtual void AddBoundingBoxD(Box3D& box) const
1069 	{
1070 		Vector3D p(GetTPointD(1));
1071 		box.Add(Box3D(p+Vector3D(-rz,-rz,-rz),p+Vector3D(rz,rz,rz)));
1072 	}
1073 
AddBoundingBox(Box3D & box)1074 	virtual void AddBoundingBox(Box3D& box) const
1075 	{
1076 		Vector3D p(GetTPoint(1));
1077 		box.Add(Box3D(p+Vector3D(-rz,-rz,-rz),p+Vector3D(rz,rz,rz)));
1078 	}
1079 
1080 	//Get nearest global point pp on element from global point p, ind is the index of found segment, returns the signed gap/penetration
1081 	virtual double GetNearestPoint(const Vector3D& p, int& ind, Vector3D& pp);
1082 
1083 	//get local position on element from global position and index (for polygon etc.)
1084 	virtual Vector3D GetLocPos(int ind, const Vector3D& pglob) const;
1085 
1086 	//get (deformed) normalized normal vector (outwards) at locpos
1087 	virtual Vector3D GetNormal(int ind, const Vector3D& ploc) const;
1088 
1089 	//get (deformed) normalized unique tangent vector at locpos
1090 	virtual Vector3D GetTangent(int ind, const Vector3D& ploc) const;
1091 
1092 	virtual void DrawYourself();
1093 
GetRadius()1094 	virtual const double& GetRadius() const {return rz;}
1095 
1096 private:
1097 	double rz;
1098 };
1099 
1100 
1101 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1102 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1103 
1104 //rotation object
1105 //a 2D curve builds a rotation object
1106 //the standard rotation axis is z-axis
1107 class GeomRotObject3D:public GeomElement
1108 {
1109 public:
GeomRotObject3D()1110 	GeomRotObject3D():GeomElement()
1111 	{
1112 		locpoints.SetLen(0);
1113 		ptd.SetLen(0);
1114 		pt.SetLen(0);
1115 		segments.SetLen(0);
1116 		colorseg.SetLen(0);
1117 	}
GetCopy()1118 	virtual GeomElement* GetCopy() const
1119 	{
1120 		GeomElement* ed = new GeomRotObject3D(*this);
1121 		return ed;
1122 	}
GeomRotObject3D(const GeomRotObject3D & e)1123 	GeomRotObject3D(const GeomRotObject3D& e):GeomElement(e) {CopyFrom(e);}
1124 
1125 	GeomRotObject3D(MBS* mbsi, const Vector3D& p0, TArray<Vector2D> segs, TArray<Vector3D> cols, const Matrix3D& rotmat, int tilei);
1126 
GetElementSpec()1127 	virtual const char* GetElementSpec() const {return "GeomRotObject3D";}
GetType()1128 	virtual TGeomElement GetType() const {return TGeomRotObject3D;}
1129 
1130 	virtual void CopyFrom(const GeomElement& e);
1131 
1132 	virtual void DrawYourself();
1133 
1134 private:
1135 	int tile;
1136 	double rz;
1137 	TArray<Vector2D> segments;
1138 	TArray<Vector3D> colorseg;
1139 };
1140 
1141 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1142 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1143 
1144 //triangular surface mesh for drawing and contact:
1145 class GeomMesh3D:public GeomElement
1146 {
1147 public:
GeomMesh3D()1148 	GeomMesh3D():GeomElement(), normals(), drawnormals(), trigs(), points_to_trigs(), points_to_edges(), edges()
1149 	{
1150 		Init();
1151 	}
GeomMesh3D(MBS * mbsi,int elnumi,const Vector3D & coli)1152 	GeomMesh3D(MBS* mbsi, int elnumi, const Vector3D& coli):GeomElement(mbsi), normals(), drawnormals(), trigs(), points_to_trigs(), edges()
1153 	{
1154 		Init();
1155 		mbs = mbsi;
1156 		elnum = elnumi;
1157 		col = coli;
1158 	}
GetCopy()1159 	virtual GeomElement* GetCopy() const
1160 	{
1161 		GeomElement* ed = new GeomMesh3D(*this);
1162 		return ed;
1163 	}
GeomMesh3D(const GeomMesh3D & e)1164 	GeomMesh3D(const GeomMesh3D& e):GeomElement(e) {CopyFrom(e);}
1165 	virtual void CopyFrom(const GeomElement& e);
1166 	virtual ~GeomMesh3D();
1167 
GetElementSpec()1168 	virtual const char* GetElementSpec() const {return "GeomMesh3D";}
GetType()1169 	virtual TGeomElement GetType() const {return TGeomMesh3D;}
1170 
1171 	virtual void GetElementData(ElementDataContainer& edc); 		//fill in all element data
1172 	virtual int SetElementData(const ElementDataContainer& edc); //set element data acc. to ElementDataContainer, return 0 if failed or values invalid!
1173 
1174 	virtual void Init();
1175 
1176 	virtual int NTrigs() const;
1177 	virtual void GetTrig0(int i, Vector3D& p1, Vector3D& p2, Vector3D& p3, Vector3D& normal);
1178 	virtual int AddTrig(int n1, int n2, int n3, const Vector3D& normal);
1179 
1180 	//virtual int AddPoint(const Vector3D& p1, double eps = 1e-16); //returns point number if exists, or adds new point
1181 	virtual void ClearMesh();
1182 	virtual Vector3D GeometryNormal(int trig1) const;
1183 	virtual double GetAngle(int trig1, int trig2) const;
1184 	virtual double GetArea(int trig) const;
1185 	virtual int IsEdge(int2 edge) const; //check if two point indices represent an edge, return edge number or zero
1186 
1187 	virtual void ReadSTLMesh(char* file, int binary=0);
1188 //	virtual void ReadFEMesh3D(class FEMesh3D* femesh);
1189 	virtual void ReadFromPointArray(TArray<Vector3D>* v3darr);
1190 	virtual void ReadFromPointSequence(Vector3D* v3dseq, int n);
1191 	virtual void ReadFromDoubleSequence(double* dseq, int n);
1192 
1193 
1194 	//virtual void SetSTLtolerance(double tol) {stl_tolerance = tol;}
SetDrawEdgeAngle(double edge_angle)1195 	virtual void SetDrawEdgeAngle(double edge_angle) {drawedge_angle = edge_angle;}
1196 	virtual void SetSmoothDrawing(int smooth_draw = 1) {smooth_drawing = smooth_draw;}
1197 
1198 	virtual int GetNeighbourTrig(int trig, int side, int& ntrig, int& nside); //get number of triangle neighbouring at 'side'
1199 	virtual void FinishMesh(); //call after all triangles have been added
1200 
1201 	virtual void SetGeomModification(const Vector3D& resize, const Matrix3D& rotate, const Vector3D& translate);
1202 
1203 	virtual void Translate(const Vector3D& translate);
1204 	virtual void Rotation(const Matrix3D &rotate);
1205 	virtual void Stretch(const double factor);
1206 	virtual double ComputeVolume() const;
1207 	virtual Vector3D ComputeCenterOfMass() const;
1208 	virtual Matrix3D ComputeMassMomentOfInertia(double rho = 1) const;
1209 
1210 	virtual int PointIsInside(Vector3D p, double& dist); //return 1 if point is inside geometry; return dist to nearest triangle point;
PointIsInside(Vector3D p)1211 	virtual int PointIsInside(Vector3D p) {double dist = 0; return PointIsInside(p, dist);}; //return 1 if point is inside geometry; return dist to nearest triangle point
1212 
1213 	//cut points which are outside (inside) of mesh geometry; if inside=1, then cut inside points; returns number of cut points
1214 	//points are allowed to have distance min_wall_dist to any triangle
1215 	virtual int CutInsideOutsidePoints(TArray<Vector3D>& points, double min_wall_dist, int inside = 1);
1216 
1217 	virtual void DrawYourself();
1218 
1219 private:
1220 	TArray<Vector3D> normals;						//Normals of triangles
1221 	TArray<Vector3D> drawnormals;				//Normals of triangles, for drawing only: drawnormals = A*normals
1222 	TArray<int3> trigs;									//Triangles to points
1223 	TArray<IVector*> points_to_trigs;   //triangles that belong to a point
1224 	TArray<IVector*> points_to_edges;   //edges that belong to a point
1225 	TArray<int2> edges;									//draw edges
1226 
1227 	int smooth_drawing;									//if 1, each triangle has 3 own normals, otherwise only one
1228 	double drawedge_angle;							// if > MY_PI, do not draw edges!
1229 	//double stl_tolerance;								//tolerance for equal points when reading
1230 };
1231 
1232 
1233 
1234 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1235 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1236 
1237 class GeomGround:public GeomElement
1238 {
1239 public:
GeomGround()1240 	GeomGround():GeomElement()
1241 	{
1242 		col = Vector3D(0,0,0);
1243 		locpoints.SetLen(0);
1244 		ptd.SetLen(0);
1245 		pt.SetLen(0);
1246 		quads.SetLen(0);
1247 		boxes.SetLen(0);
1248 	}
GeomGround(MBS * mbsi)1249 	GeomGround(MBS* mbsi):GeomElement(mbsi)
1250 	{
1251 		elnum = 0;
1252 		mbs = mbsi;
1253 		col = Vector3D(0,0,0);
1254 		locpoints.SetLen(0);
1255 		ptd.SetLen(0);
1256 		pt.SetLen(0);
1257 		quads.SetLen(0);
1258 		boxes.SetLen(0);
1259 	}
~GeomGround()1260 	virtual ~GeomGround()
1261 	{
1262 		quads.Flush();
1263 		cols.Flush();
1264 		boxes.Flush();
1265 	}
GetCopy()1266 	virtual GeomElement* GetCopy() const
1267 	{
1268 		GeomElement* ed = new GeomGround(*this);
1269 		return ed;
1270 	}
1271 
CopyFrom(const GeomElement & e)1272 	virtual void CopyFrom(const GeomElement& e)
1273 	{
1274 		GeomElement::CopyFrom(e);
1275 		const GeomGround& ce = (const GeomGround&)e;
1276 
1277 		quads.Flush();
1278 		for (int i=1; i <= quads.Length(); i++)
1279 			quads.Add(ce.quads(i));
1280 
1281 		cols.Flush();
1282 		for (int i=1; i <= cols.Length(); i++)
1283 			cols.Add(ce.cols(i));
1284 
1285 		boxes.Flush();
1286 		for (int i=1; i <= boxes.Length(); i++)
1287 			boxes.Add(ce.boxes(i));
1288 
1289 		tree = ce.tree;
1290 	}
GeomGround(const GeomGround & e)1291 	GeomGround(const GeomGround& e):GeomElement(e) {CopyFrom(e);}
1292 
1293 	virtual Vector3D FStreet(double x, int mode, double sx, double sy, double sz) const;
1294 
1295 	virtual void SetStreet();
1296 	virtual void SetFlat(const Vector3D& dim, int resx, int resy);
1297 
1298 	virtual void DrawYourself();
1299 
NQuads()1300 	virtual int NQuads() const {return quads.Length();}
GetQuad(int i)1301 	virtual int4 GetQuad(int i) const {return quads(i);}
1302 
Boxes(int i)1303 	virtual const Box3D& Boxes(int i) const {return boxes(i);}
1304 
GetQuadsInBox(const Box3D & b,TArray<int> & items)1305 	virtual void GetQuadsInBox(const Box3D& b, TArray<int>& items)
1306 	{
1307 		tree.GetItemsInBox(b,items);
1308 	}
1309 
1310 private:
1311 	TArray<int4> quads;
1312 	TArray<Vector3D> cols;
1313 	TArray<Box3D> boxes;
1314 	SearchTree tree;
1315 };
1316 
1317 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1318 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1319 
1320 class GeomShip3D:public GeomElement
1321 {
1322 public:
GeomShip3D()1323 	GeomShip3D():GeomElement()
1324 	{
1325 		locpoints.SetLen(2);
1326 		ptd.SetLen(2);
1327 		pt.SetLen(2);
1328 	}
GetCopy()1329 	virtual GeomElement* GetCopy() const
1330 	{
1331 		GeomElement* ed = new GeomShip3D(*this);
1332 		return ed;
1333 	}
GeomShip3D(const GeomShip3D & e)1334 	GeomShip3D(const GeomShip3D& e):GeomElement(e) {CopyFrom(e);}
1335 
GeomShip3D(MBS * mbsi,int elnumi,const Vector3D & sizei,const Vector3D & comi,double tilei,const Vector3D & coli)1336 	GeomShip3D(MBS* mbsi, int elnumi, const Vector3D& sizei, const Vector3D& comi, double tilei, const Vector3D& coli): GeomElement(mbsi)
1337 	{
1338 		elnum = elnumi;
1339 		mbs = mbsi;
1340 		col = coli;
1341 
1342 		size = sizei;
1343 		com = comi;
1344 		tile = (int)tilei;
1345 
1346 		locpoints.SetLen(2);
1347 		ptd.SetLen(2);
1348 		pt.SetLen(2);
1349 
1350 		locpoints(1) = size-com;
1351 		locpoints(2) = -1*(size-com);
1352 		CopyPt();
1353 		CopyPtD();
1354 
1355 	}
1356 
CopyFrom(const GeomElement & e)1357 	virtual void CopyFrom(const GeomElement& e)
1358 	{
1359 		GeomElement::CopyFrom(e);
1360 		const GeomShip3D& ce = (const GeomShip3D&)e;
1361 
1362 		tile =ce.tile;
1363 		size = ce.size;
1364 		com = ce.com;
1365 	}
1366 
1367 	virtual void DrawYourself();
1368 
1369 private:
1370 	Vector3D size; //dimensions of ship
1371 	int tile;
1372 	Vector3D com; //center of mass
1373 
1374 };
1375 
1376 #endif