Ifc2x3 Equivalent for IfcExtrudedAreaSolidTapered - c#

I want to be able to implement a truncated cone in IFC. I know that there is a rather quick way to implement this in IFC 2x4 with the IfcExtrudedAreaSolidTapered class.
Can anybody tell me how to do that with Ifc 2x3?
Here's what I have:
IfcExtrudedAreaSolid CreateExtrudedAreaSolid(IfcStore model, IfcProfileDef
profile,IfcAxis2Placement3D placement, double extrude)
{
var extrusion = model.Instances.New<IfcExtrudedAreaSolid>();
extrusion.Depth = extrude;
extrusion.ExtrudedDirection = model.Instances.New<IfcDirection>(d =>
d.SetXYZ(0, 0, 1));
extrusion.Position = placement;
extrusion.SweptArea = profile;
return extrusion;
}
And here's where I create the profile:
private IfcCircleHollowProfileDef MakeCircleHollowProfileDef(IfcStore model,
IfcAxis2Placement3D placement, double r, double wallThickness)
{
var circleProfile = model.Instances.New<IfcCircleHollowProfileDef>();
circleProfile.Position = ConvertToAxis2D(placement, model);
circleProfile.Radius = r;
circleProfile.WallThickness = wallThickness;
return circleProfile;
}
Does anybody have an idea how to do that the right way?

I would go for a cone and cut it (via BooleanResult) with a half space. You want the boolean operation to be DIFFERENCE, the cone as first operand and the half space the second operand.
I don't have the code to implement that in xBim (I use IfcPlusPlus), sorry. From your given code, one information you need to calculate would be the full height of the cone to cut it back to the desired height.

Related

How to get coordinates of each word of PDF?

For each word I am creating an object of LocationTextExtractionStrategy class to get its coordinates but the problem is each time I pass a word it is returning coordinates of all the chunks of that word present in pdf. How can i get coordinates of the word present at specific position or in a specific line?
I found a code somewhere
namespace PDFAnnotater
{
public class RectAndText
{
public iTextSharp.text.Rectangle Rect;
public string Text;
public RectAndText(iTextSharp.text.Rectangle rect, string text)
{
this.Rect = rect;
this.Text = text;
}
}
public class MyLocationTextExtractionStrategy : LocationTextExtractionStrategy
{
public List<RectAndText> myPoints = new List<RectAndText>();
public string TextToSearchFor { get; set; }
public System.Globalization.CompareOptions CompareOptions { get; set; }
public MyLocationTextExtractionStrategy(string textToSearchFor, System.Globalization.CompareOptions compareOptions = System.Globalization.CompareOptions.None)
{
this.TextToSearchFor = textToSearchFor;
this.CompareOptions = compareOptions;
}
public override void RenderText(TextRenderInfo renderInfo)
{
base.RenderText(renderInfo);
var startPosition = System.Globalization.CultureInfo.CurrentCulture.CompareInfo.IndexOf(renderInfo.GetText(), this.TextToSearchFor, this.CompareOptions);
//If not found bail
if (startPosition < 0)
{
return;
}
var chars = renderInfo.GetCharacterRenderInfos().Skip(startPosition).Take(this.TextToSearchFor.Length).ToList();
//Grab the first and last character
var firstChar = chars.First();
var lastChar = chars.Last();
//Get the bounding box for the chunk of text
var bottomLeft = firstChar.GetDescentLine().GetStartPoint();
var topRight = lastChar.GetAscentLine().GetEndPoint();
//Create a rectangle from it
var rect = new iTextSharp.text.Rectangle(
bottomLeft[Vector.I1],
bottomLeft[Vector.I2],
topRight[Vector.I1],
topRight[Vector.I2]
);
this.myPoints.Add(new RectAndText(rect, this.TextToSearchFor));
}
}
}
I am passing words from an array to check for its coordinates. The problem is that RenderText() method is automatically called again and again for each chunk and returns the list of coordinates of the word present at different places in the pdf. For example if i need coordinate of '0' it is returning 23 coordinates. What should I do or modify in the code to get the exact coordinate of the word?
Your question is a bit confusing.
How can I get coordinates of the word present at specific position
In that statement you're basically saying "How can I get the coordinates of something that I already know the coordinates of?" Which is redundant.
I'm going to interpret your question as "How can I get the coordinates of a word, if I know the approximate location?"
I'm not familiar with C#, but I assume there are methods similar to the ones in Java for working with Rectangle objects.
Rectangle#intersects(Rectangle other)
Determines whether or not this Rectangle and the specified Rectangle intersect.
and
Rectangle#contains(Rectangle other)
Tests if the interior of the Shape entirely contains the specified Rectangle2D.
Then the code becomes trivially easy.
You use LocationTextExtractionStrategy to fetch all the iText based rectangles
you convert them to native rectangle objects (or write your own class)
for every rectangle you test whether the given search region contains that rectangle, keeping only those that are within the search region
If you want to implement your second use-case (getting the location of a word if you know the line) then there are two options:
you know the rough coordinates of the line
you want this to work given a line number
For option 1:
build a search region. Use the bounds of the page to get an idea of the width (since the line could stretch over the entire width), and add some margin y)-coordinates (to account for font differences, subscript and superscript, etc)
Now that you have a search region, this reverts to my earlier answer.
For option 2:
you already have the y coordinate of every word
round those (to the nearest multiple of fontsize)
build a Map where you keep track of how many times a certain y-coordinate is used
remove any statistical outliers
put all these values in a List
sort the list
This should give you a rough idea of where you can expect a given line(number) to be.
Of course, similar to my earlier explanation, you will need to take into account some padding and some degree of flexibility to get the right answer.

Getting selected non-regular shape from image in C#

I have a following problem and I will try to explain it.
I have a huge, political world map. I want to get a shape of selected country (in example Ghana, Nepal or Poland). How can I do that?
It depends what other information you are able to provide in advance. From your question and comments it sounds like you plan to predefine your shapes so the problem isn't too difficult. If you define each region by a set of points it's just a matter of checking if the selection (presumably a mouse click or similar) is within a polygon. There are a number of ways to do this. I think I've used one of the answers to the following question:
C# Point in polygon
Something like:
public static bool IsInPolygon(Point[] poly, Point clickedPoint)
{
if (poly.Length < 3)
{
return false;
}
Point p1, p2;
bool inside = false;
Point oldPoint = new Point(poly[poly.Length - 1].X, poly[poly.Length - 1].Y);
for (int i = 0; i < poly.Length; i++)
{
Point newPoint = new Point(poly[i].X, poly[i].Y);
if (newPoint.X > oldPoint.X)
{
p1 = oldPoint;
p2 = newPoint;
}
else
{
p1 = newPoint;
p2 = oldPoint;
}
if ((newPoint.X < clickedPoint.X) == (clickedPoint.X <= oldPoint.X)
&& (clickedPoint.Y - (long)p1.Y) * (p2.X - p1.X) < (p2.Y - (long)p1.Y) *(clickedPoint.X - p1.X))
{
inside = !inside;
}
oldPoint = newPoint;
}
return inside;
}
I haven't tested the above code so I'd make sure to test it properly if you use it.
If you can't predefine the shapes then you'll probably have to use some sort of analysis method to pick out the shapes. If you use a clean map with solid lines it won't be too difficult. Any kind of flood fill algorithm should be able to pick out individual countries (obviously you'd have to deal with special cases like when a country is made of two distinct regions). From there getting a set of points from each shape can be done using a simple marching squares algorithm. If desired, you can then reduce the number of points depending on the level of accuracy you need.

XNA Hexagonal Map Tilepicking

Okay guys,
I am having a LOT trouble with this. I simply cannot figure out a way to implement tile picking in a hexagonal map in XNA. I have looked this up prior to asking this question, and all the answers involve complicated algorithms and diagrams my puny mind simply cannot comprehend. So my question for you guys is: How would i be able to hover over tiles, and select them if i wanted to?
If you need any reference as to how my program looks so far, just check out this link, its literally the same except i have a smaller map on mine.
http://www.xnaresources.com/default.asp?page=Tutorial:TileEngineSeries:3
Thanks!
This is code i had stored but never used and its for hex grid where one edge is looking up, so by some minor tweaks it could work in your example. It's not my code, not sure who wrote it.
Hexagon[][] hexagons = new Hexagon[100][100];
double hexagonHeight = 30;
double hexagonWidth = 40;
double halfWidth = hexagonWidth / 2;
// Find rough coordinates of Hexagon at mousepoint
private Hexagon getSelectedHexagon(MouseEvent mouse)
{
// These will represent which box the mouse is in, not which hexagon!
int row = (int) (mouse.y / hexagonHeight);
int column;
boolean rowIsOdd = row % 2 != 0;
// Is the row an even number?
if (rowIsOdd) // No: Calculate normally
column = (int) (mouse.x / hexagonWidth);
else // Yes: Offset mouse.x to match the offset of the row
column = (int) ((mouse.x + halfWidth) / hexagonWidth);
// column is more complex because it has to
// take into account that every other row
// is offset by half the width of a hexagon
return hexagons[row][column];
}
edit: i just found author
Hexagonal Grids, how do you find which hexagon a point is in?

How to move the camera behind a model with the same angle?

I meet are having difficulty in moving my camera behind an object in a 3D world. I would create two view mode.
1: for fps (first person).
2nd: external view behind the character (second person).
I searched the net some example but it does not work in my project.
Here is my code used to change view if F2 is pressed
//Camera
double X1 = this.camera.PositionX;
double X2 = this.player.Position.X;
double Z1 = this.camera.PositionZ;
double Z2 = this.player.Position.Z;
//Verify that the user must not let the press F2
if (!this.camera.IsF2TurnedInBoucle)
{
// If the view mode is the second person
if (this.camera.ViewCamera_type == CameraSimples.ChangeView.SecondPerson)
{
this.camera.ViewCamera_type = CameraSimples.ChangeView.firstPerson;
//Calcul position - ?? Here my problem
double direction = Math.Atan2(X2 - X1, Z2 - Z1) * 180.0 / 3.14159265;
//Calcul angle - ?? Here my problem
this.camera.position = ..
this.camera.rotation = ..
this.camera.MouseRadian_LeftrightRot = (float)direction;
}
//IF mode view is first person
else
{
//....
Here is a very basic 3rd person camera (what you meant by 2nd person) in Xna. It assumes you have the player's world matrix stored and can access it:
Vector3 _3rdPersonCamPosition = playerWorldMatrix.Translation + (playerWorldMatrix.Backward * trailingDistance) + (playerWorldMatrix.Up * heightOffset);// add a right or left offset if desired too
Vector3 _3rdPersonCamTarget = playerWorldMatrix.Translation;//you can offset this similarly too if desired
view = Matrix.CreateLookAt(_3rdPersonCamPosition, _3rdPersonCamTarget , Vector3.Up);
If your FPS cam is working properly and assuming it is essentially the same location and orientation as the player, you can substitute it's view matrix in place of the playerWorldMatrix above like this:
Matrix FPSCamWorld = Matrix.Invert(yourWorkingFPSviewMatrixHere);
Now wherever I wrote playerWorldMatrix you can use FPSCamWorld instead.
If I were you, I would take your now-working FPS camera (I'm assuming that moves properly, has a positional matrix, etc?), and add another Translation Transform to it to "move it" back behind the player.
Put another way:
If your "translation/view matrix" for the FPS view is something like:
(sorry, haven't played with XNA in a while, so don't remember proper class names)
var camTranslateMatrix = [matrix representing player position];
var camDirectionMatrix = [matrix representing player direction, etc];
var camViewMatrix = camTranslateMatrix * camDirectionMatrix;
Then you could change it like so:
var camTranslateMatrix = [matrix representing player position];
var camDirectionMatrix = [matrix representing player direction, etc];
// If not in 3rd person, this will be identity == no effect
var camThirdPersonMatrix =
IsInThirdPersonMode ?
new TranslateMatrix(back a bit and up a bit) :
IdentityMatrix();
var camViewMatrix =
camTranslateMatrix *
camDirectionMatrix *
camThirdPersonMatrix;
Make sense? That way, it'd be trivial to toggle between the two views without tons of nasty math each time you do so.

"Matrix decomposition" of a matrix with holonic sub structure

Before I start, I must say that for those with a background of linear algebra, this is NOT matrix decomposition as you know it. Please read the following paragraphs to get a clearer understanding of the problem I am trying to solve.
Here are the salient properties/definitions of the matrix and its submatrices:
I have an SxP matrix which forms a grid like structure of S.P "boxes". This is the main matrix.
This is what the (empty) main matrix looks like. Each square in the matrix is simply referred to as a box. The matrix can be viewed as a a kind of "gameboard" e.g. a chess board. The vertical axis is measured using an interval scale (i.e. real numbers), and the horizontal axis is measured using monotonically increasing non-negative integers.
There is an additional concept of submatrices (as explained earlier). A submatrix is simply a collection of boxes in a particular configuration, and with specific numbers and piece types (see black and white pieces below), assigned to the boxes. I have a finite set of these sub matrices - which I refer to as my lexicon or vocabulary for carrying out valid matrix composition/decompositions.
The "formal" definition of a sub matrix is that it is a configuration of M boxes contained within the main matrix, that satisfy the criteria:
1 <=M<= 4
the "gap" G (i.e. distance) between any two adjacent boxes satisfies: 1<= G<= 2*(vertical units).
A vertical unit is the gap between the vertical axis lines in the main matrix. In the image below, the vertical unit is 100.
The image immediately above illustrates a simple sub matrix addition. The units with orange boarders/boxes are sub matrices - the recognized units that form part of my lexicon. You will notice that I have introduced further annotation in my sub matrices. This is because (using the chess analogy), I have two types of pieces I can use on the board. B means a black piece, and W (not shown in the image), represents a white piece. A recognized unit (or lexeme/sub matrix) There is a simple equivalence relation that allows conversion between a white piece and a black piece. This relationship can be used to further decompose a submatrix to use either exclusively black pieces, white pieces or a combination of both.
For the sake of simplicity, I have omitted specifying the equivalence relationship. However, if someone feels that the problem as posed is not "too difficult" without additional details, I shall gladly broaden the scope. For now, I am trying to keep things as simple as possible, to avoid confusing people with "information overload".
Each box in a sub matrix contains a signed integer, indicating a number of units of an item. Each "configuration" of boxes (along with its signed integers and piece type i.e. black or white pieces) is said to be a "recognized unit".
Submatrices can be placed in the main matrix in a way such that they overlap. Wherever the "boxes" overlap, the number of units in the resulting submatrix box is the sum of the number of units in the constituent boxes (as illustrated in the second image above).
The problem becomes slightly difficult because, the "recognized units" defined above themselves are sometimes combined with other "recognized units" to form another "recognized unit" - i.e. the sub matrices (i.e.recognized units) are "holons". For example, in the second image above, the recognized unit being added to the matrix can itself be further decomposed into "smaller" submatrices.
This sort of holarchy is similar to how (in Physical chemistry), elements form compounds, which then go on to form ever more complicated compounds (amino acids, proteins etc).
Back to our problem, given a main matrix M, I want to be able to do the following:
i. identify the submatrices (or recognized units) that are contained within the main matrix. This is the first "matrix decomposition". (Note: a submatrix has to satisfy the criteria given above)
ii. For each identified submatrix, I want to be able to recognize whether it can be decomposed further into 2 or more recognized submatrices. The idea is to iteratively decompose submatrices found in step i above, until either a specified hierarchy level is reached, or until we have a finite set of submatrices that can not be decomposed further.
I am trying to come up with an algorithm to help me do (i) and (ii) above. I will implement the logic in either C++, Python or C# (in increasing level of preference), depending on which ever is the easiest to do and/or in which I happen to get snippets to get me started in implementing the algorithm.
I am not sure if i have a understand correctly the problem.
So first ypu want to find all submatrixes that conform with your 2 criterea.
Thats like a graph decomposition problem or a set coverage problem i think, where you can have a recursive function and iterate the matrix to find all available submatrixes.
enum PieceTypes
{
White,
Black
}
class Box
{
public PieceTypes PieceType { get; set; }
public uint Units { get; set; }
public int s, p;
public Box(PieceTypes piecetype, uint units)
{
PieceType = piecetype;
Units = units;
}
}
class Matrix
{
public Box[,] Boxes;
public int Scale, S, P, MaxNum, MaxDist;
public List<List<Box>> Configurations;
public Matrix(int s, int p, int scale, int maxnum, int maxdist)
{
S = s;
P = p;
Scale = scale;
Boxes = new Box[S, P];
MaxNum = maxnum;
MaxDist = maxdist;
Configurations = new List<List<Box>>();
}
public void Find(List<Box> Config, int s, int p)
{
// Check the max number thats valid for your configuration
// Check that the current p and s are inside matrix
if (Config.Count() < MaxNum && s >= 0 && s < S && p >= 0 && p < P)
{
foreach (Box b in Config)
{
if (Valid(b, Boxes[s, p]))
{
Boxes[s, p].s = s;
Boxes[s, p].p = p;
Config.Add(Boxes[s, p]);
break;
}
}
Find(Config, s + 1, p);
Find(Config, s - 1, p);
Find(Config, s, p + 1);
Find(Config, s, p - 1);
}
if (Config.Count() > 0) Configurations.Add(Config);
Config.Clear();
}
public bool Valid(Box b1, Box b2)
{
// Create your dist funtion here
// or add your extra validation rules like the PieceType
if (Math.Sqrt((b1.s - b2.s) ^ 2 + (b1.p - b2.p) ^ 2) <= MaxDist && b1.PieceType == b2.PieceType) return true;
else return false;
}
}
I haven't used the best data structures and i have simplified the solution. I hope its some way helpful.

Categories

Resources