text:
Archived

This topic is now archived and is closed to further replies.

Making a scripting engine/console

This topic is 5463 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I''m making a 3D game engine, and I''ve got some nice features now. My problem is I want to let other people of my programming team use the engine as well, for map/model testing etc. Since they cannot program/compile and stuff I want to make a console so they can load in maps, models, etc. Commands will be pretty basic first (as in ''loadplayermodel /models/model.mod'', ''loadmap /maps/map.map'', etc.) but later I want to use the scripting system for the game itself, so it should also be able to do more complicated things. I have absolutely no experience for console/scripting programming, and I don''t know where to start. A good thing would be if I knew how to display and read in what the user types (the console thingy. I want the player to be able to type something and the console should display that and check the input) Also I am not sure how to do the scripting system so that it''ll still be fast if I add lots of commands. Now, are there any good articles/tutorials on this, or do you have advice for me? Anything is welcome BTW I''m using OpenGL/C++ | Panorama 3D Engine | Contact me | | MSDN | Google | SourceForge |

Share on other sites
Im going to use lua for mine, an example of how a command might look with lua...

SpawnPlayerModel(location,"somemodel.3ds");

or something like that

This function would be part of a real engine function but with a lua interface for it...

//an example...int l_SetPlayerLocation(lua_State* l){  PlayerEntity.Set_Location(lua_tonumber(l,1),lua_tonumber(l,2),lua_tonumber(l,3));	return 1;}bool InitAll(){         lua_register(lua,"SetPlayerLocation",l_SetPlayerLocation);}

Theres a great article here on game dev about lua,
I would suggest reading it. you could also check out the script
/ mods etc forum.

The console part would be a matter of handling input and displaying text on some sorta window, or quad...

This is how I plan on doing mine, so im not sure if its gonna work perfect, but in thoery is should.
good luck.

Share on other sites
I completed my console a couple of days ago, using Lua. It''s networked, so you can connect to it from a different computer to execute commands while the program is running fullscreen (I have a terminal on my desk exclusively for doing this). Really useful stuff.

How appropriate. You fight like a cow.

Share on other sites
ps.

Lua is VERY fast in my opinion and is easy to work with.
A bit of a pain to get installed on your system though.

Basicly, you need to make a basic text editor for the console.
I havent actually done this yet though.

Hmm, theres a good tut at
http://www.ultimategameprogramming.com/
(for a small fee though)

look under GL and I think DX tutorials as well for it.

Share on other sites
ok, seem good. But I''d rather make my own, instead of using another scripting engine. This is my first engine, and my goal is to do everything myself to learn as much as I can from it. So I''ll only use some pre-made scripting system if I really can''t figure out myself.

| Panorama 3D Engine | Contact me |
| MSDN | Google | SourceForge |

Share on other sites
There is a great book called ''Game scripting mastery'' which
shows you how to build a C like scripting language from the
ground up, with compiler, assembler, and a VM. There is two
chapters on command based scripting to, but that is really
simple stuff. It also teaches you how to use existing languages
like LUA, Python, and TcL. By the end of the book you will have
a scriping language which you can customize in every way
possible to fit you engine (think mod development).

• 32
• 12
• 10
• 9
• 9
• Forum Statistics

• Total Topics
631349
• Total Posts
2999467
×


text:
# Affine Transformation C++

 The multiplication of 2 affine transformations and is defined as the affine transformation which, when applied on any vecor , results in the same vector that one would obtain by first transforming it with and then with. The value of the input at those coordinates is determined by spline interpolation of the requested order. , the midpoint of a line segment remains the midpoint after transformation). I am trying to implement affine transformation on two images. Affine Transformation¶ In affine transformation, all parallel lines in the original image will still be parallel in the output image. Affine Transformation. The Transformation Matrix. Now that you understand the basics of drawing shapes like triangles and rectangles, let's take another step and try to move (translate), rotate, and scale the triangle and display the results on the screen. The affine transformation has an important property that two successive affine transformations combine also into an affine transformation. A 2D point transformation requires 9 multiplies and 6 adds But since affine transformations have always the form: The number of operations can be reduced to 4 multiplies and 4 adds ab c x ax by cz defydx eyfz g hi zg xhy iz ++ =++ ++ 00 1 1 1 ab c x ax by c. Eden, "B-Spline Signal Processing: Part I--Theory," IEEE Transactions on Signal Processing, vol. It also contains face drawing function that make it easy to plot the 3d figure with respect to a specific question. Also, sets of parallel lines remain parallel after an affine transformation. A C++ library for Affine transformation. Download Anaconda. It can be obtained from the previous description by applying affine transformations to keep the polygon bounded as it degenerates. particular transformations that are not supported by ITransform2D and also for performing numerous transformations in one go. My question is, what did people find useful in this article, and I mean it sincerely. Pluto transforms C programs from source to source for coarse-grained parallelism and data locality simultaneously. The matrix operation is applied to each location (x, y) that is then transformed to (x', y') of the new array. An affine transformation can differentially scale the data, skew it, rotate it, and translate it. I am implementing some affine transformations and I am aware that there are several algorithms for efficient matrix multiplication, like Strassen. But are there some algorithms that are especially efficient for matrices that small?. That is, the shape is defined up to an affine transformation in space. So, this class library implements affine transformations on images such as translation, rotation, scaling, schear. gdTransformAffineCopy: Applies an affine transformation to a region and copy the result in a destination to the given position. Lowe, International Journal of Computer Vision, 60, 2 (2004), pp. This example illustrates how to use the maketform and imtransform functions to perform a 2-D spatial transformation of an image. Affine Partitioning Based Algorithms. , DoG, Harris-Affine, Harris-Laplace) and corresponding feature descriptors (SIFT, raw patches). In this question, f and g are both affine transformations. The name affine differential geometry follows from Klein's Erlangen program. Property 1 An affine transformation of the plane is defined uniquely by three pairs of points. An affine transformation is any transformation that preserves collinearity (i. , all points lying on a line initially still lie on a line after transformation) and ratios of distances (e. The chapter reviews some properties of affine mappings through theorems and discusses the representation of any affine transformation as a product of affine transformations of the simplest types. affine invariant subspaces of c(c) 233 2. Affine Transformation. An affine transform is a special case of a perspective transform. Thus, rectified text region is required for most text recognition algorithm. For each of the configuration, calculate the Sum of Absolute Differences (or other scoring method), but only for a…. org, freedictionary. Just an update, I changed the CvInvoke. Affine (distance) ratio from 3 parallel lines. Moreover, the generalized de Casteljau approach is computationally more efficient than trivariate de Casteljau, because it is an affine transformation plus a univariate interpolation in space vs. 1 #include "rotate 44 // our affine transformation. There are two important particular cases of such transformations: A nonproportional scaling transformation centered at the origin has the form (x,y,z) (ax,by,cz), where a,b,c 0 are the. The image of a line under any affine transformation is a line. Transformation. It successfully performs affine transformations or more general non-affine transformations such as tiling on the polyhedron, and then converts the transformed polyhedron into equivalent, but optimized (depending on targeted optimization goal), loop nests through polyhedra scanning. C++ : Will an (affine transformationno) better pow() function improve accuracy? By random_thinker , August 20, 2005 in General and Gameplay Programming This topic is 5131 days old which is more than the 365 day threshold we allow for new replies. These n+1-dimensional transformation matrices are called, depending on their application, affine transformation matrices, projective transformation matrices, or more generally non-linear transformation matrices. Notice that in order to check this, we needed only the matrix C, and not the entire affine transformation. The goal of the localisation network is to spit out the parameters of the affine transformation that’ll be applied to the input feature map. cvEstimateAffineTransformation function to wrap the opencv C function defined in the opencv_video module. origin is moved, axes do not rotate diagram u = x - a v = y - b. The usual way to represent an Affine Transform is by using a 2 \times 3 matrix. As an example we will convert world coordinates to pixel (screen or image) coordinates. An unsupervised algorithm for learning lie group transformations. Affine transformation is a linear mapping method that preserves points, straight lines, and planes. Affine transformations as matrices. Here is it , My First article for codeproject, I hope you enjoy it. With input feature map U, with width W, height H and C channels, outputs are θ, the parameters of transformation Tθ. Mathematically, it is represented as e(x) = (ax + b) mod m. Good parametrisations of affine transformations are essential to interpolation, deformation, and analysis of shape, motion, and animation. It does not necessarily preserve angles or lengths, but does have the. The normalisation stage, where the homogeneous vectors are scaled so that their third component is one, and is set to one, is carried out to make the equations linear. which is should not get otherwise if the transformation is right. Affine transformation is a linear mapping method that preserves points, straight lines, and planes. The inverse of a transformation L, denoted L−1, maps images of L back to the original points. Affine transformations are composed of Affine transformations are composed of elementary ones. An unsupervised algorithm for learning lie group transformations. in an output image) by applying a linear combination of translation, rotation, scaling and/or shearing (i. And the second one is, if I take the transformation of any scaled up version of a vector -- so let me just multiply vector a times some scalar or some real number c. The ModelView matrix combined the model and view transformations into one. Affine transformation software Author: Philippe Thévenaz This C routine is based on the following two papers: M. Pitchaiah, Philemon Daniel, Praveen Abstract—Cryptography is the study of mathematical techniques related to aspects of information security such as confidentiality, data integrity, entity authentication and data origin authentication. Transformation matrixes for affine transformations are as follows: 9 DOF transformation matrix which includes scale parameters Sx, Sy and Sz looks as follows \begin{bmatrix}. Javascript isomorphic 2D affine transformations written in ES6 syntax. Control points are used to define the mapping. Write a 3-by-3 matrix representing this transformation. Translation. Making these things is very easy with grid package. With beginners, trying to implement an affine transformation in a programming language (C/C++) is really a challenge. See Also EGS_AffineTransform. whereas affine transformations have the form € xnew=ax+by+e ynew=cx+dy+f € ⇔ (xnew,ynew)=(x,y)∗ ac bd +(e,f). Introduction to Transformations n Introduce 3D affine transformation: n Position (translation) n Size (scaling) n Orientation (rotation) n Shapes (shear) n Previously developed 2D (x,y) n Now, extend to 3D or (x,y,z) case n Extend transform matrices to 3D n Enable transformation of points by multiplication. Anaconda Cloud. ch Abstract A well-known modular software for analysis and performance has been redesigned in Java for distributed components and. A spatial transformation is a mapping function that establishes a spatial correspondence between all points in an image and its. The new affine. Define an affine transformation on the CMF’s: For the case of monochromatic SRD, let )w1 (λ), w2 (λ , w3 (λ) be three auxiliary functions of the wavelength and define the affine tri-stimulus values )(Xa ,Ya ,Za through Eqn. Mark these points and their images on the same diagram, making it clear which points map to which. YANO, A class of. For this instruction, an affine transformation is defined by A * x + b where "A" is an 8 by 8 bit matrix, and "x" and "b" are 8-bit vectors. Notice that in order to check this, we needed only the matrix C, and not the entire affine transformation. This leads to the following differences in operations properties:. Implementation of Affine Cipher The Affine cipher is a type of monoalphabetic substitution cipher, wherein each letter in an alphabet is mapped to its numeric equivalent, encrypted using a simple mathematical function, and converted back to a letter. How to use this projective transformation with CSS. If matrix tf is is a 3x2 matrix, an affine transformation will be performed. Creation You can create an affine2d object using the following methods:. ‘Our interest is in the space of affine equivalence classes of equal-area polygons. This does shearing , scaling , translating and scaling. In geometry, an affine transformation, affine map or an affinity (from the Latin, affinis, "connected with") is a function between affine spaces which preserves points, straight lines and planes. The technical definition of an affine transformation is one that preserves parallel lines, which basically means that you can write them as matrix transformations, or that a rectangle will become a parallelogram under an affine transformation (see fig 10. Note: 11 12 1 1 11 1 12 2 1 21 22 2 2 21 1 22 2 2. Affine transformations are composed of Affine transformations are composed of elementary ones. $\endgroup$ – godaygo Jul 11 at 10:26. the transformation φ we used is Affine Transformation (AT), defined by: φ(s ) = Asi + b (6) where = = 2 1 22 12 21 11, b b a a a a A b are six parameters of AT. Affine Transformations. 2D Cartesian coordinate transformations are generally used to assign map coordinates (x,y) to an uncorrected image or scanned map. An affine transformation does not necessarily preserve angles between. Obviously the images represent only partially the same thing (some background is removed and other is added) but after a roto-translation (an affine transformation caused by the camera movement). , & Goel, A. I am an entrepreneur who loves Computer Vision and Machine Learning. AFFINE—Affine transformation requires a minimum of three transformation links. Georgieva, CSI/CUNY 5 Using Transformations cont’d • A designer may want to view an object from different vantage points. Gangopadhyay XLRI C. By affine calibration is meant that besides of projective calibration, some affine information should somehow introduced. There are some common transformations such as:. Ask Question Asked 6 months ago. It does not necessarily preserve angles or lengths, but does have the. Affine Transformation zAffine Transforms needed in OQM since imaging is done on basis of the phase difference between pixels. Suppose an affine transformation T maps P to P', Q to Q', R to R' Suppose some other collineation S maps P to P', Q to Q', R to R' Then T-1 S fixes P, Q, and R and must be the identity. To the point: Unfortunately CF doesn't support this kind of operation on Images in comaprison with. Transformations can be done in two different ways. 2D projective transformations (homographies) Christiano Gava christiano. After beeing multiplied by the ProjectionMatrix, homogeneous coordinates are divided by their own W component. you can see that, in essence, an Affine Transformation represents a relation between two images. Affine Transformations. Imaging Namespace / AffineMatrix Class. Model matrix. (c) Use the expressions that you found for f(x) and g(x) in parts (a) and (b) to calculate f(g(x)), and hence find the affine transformation f g in the same form as you found g in part (a). An affine symmetric space is a connected affinely connected manifold M such that to each point peM there is an involutive (i. Studholme U. c) Find the affine transformation g o f (in the same form as you found g and f in parts a) and b)) d) Hence, or otherwise, find the images of the points (0,0), (4,0), (4,1) and (0,1) under g o f. It also contains face drawing function that make it easy to plot the 3d figure with respect to a specific question. hpp // // Copyright 2005-2007 Adobe Systems Incorporated // // Distributed under the Boost Software License, Version 1. Moving, Rotating, and Scaling. Although not user-friendly, not real. , all points lying on a line initially still lie on a line after transformation) and ratios of distances (e. The algorithm compares an input image to its database of preprocessed images and determines if the input matches any image in the database. When the contents of children change, their parents are automatically invalidated. This is a left side matrix multiplication. Applications: whitening transformation: Suppose X is a column vector zero-centered data. Theorem Affine transformations map affine subspaces to affine subspaces. Affine transformation In geometry, an affine transformation is a transformation which preserves straight lines (all points lying on a line initially still lie on a line after transformation) and ratios of distances between points lying on a straight line. Mathematically, it is represented as e(x) = (ax + b) mod m. We will learn how to apply those transformations to entire render targets, brushes and geometries. Apply an affine transformation. It would not be appropriate for example, for air photos taken in mountainous terrain. Affine Transformation. png picture (with transparent background) placed on a form (using a TImage object). To the point: Unfortunately CF doesn't support this kind of operation on Images in comaprison with. The usual way to represent an Affine Transformation is by using a \(2 \times 3. Affine Transformations •Line preserving •Characteristic of many physically important transformations - Rigid body transformations: translation, rotation - Non-rigid: Scaling, shear •Importance in graphics is that we need only transform vertices (points) of line segments and polygons, then system draws between the transformed points. Transformations of Variables Basic Theory The Problem As usual, we start with a random experiment with probability measure ℙ on an underlying sample space. affine: [adjective] of, relating to, or being a transformation (such as a translation, a rotation, or a uniform stretching) that carries straight lines into straight lines and parallel lines into parallel lines but may alter distance between points and angles between lines. A 2D transformation matrix is an array of numbers with three rows and three columns for performing algebraic operations on a set of homogeneous coordinate points (regular points, rational points, or vectors) that define a 2D graphic. This program is able to load one PCD or PLY file; apply a matrix transformation on it and display the original and transformed point cloud. This means that, each pixel is localized by two coordinates, in the rectangular domain of the image. Geospatial software of all varieties use an affine transform (sometimes refered to as "geotransform") to go from raster rows/columns to the x/y of the coordinate reference system. So this article will show you guys some simple examples that apply affine transformations. To the point: Unfortunately CF doesn't support this kind of operation on Images in comaprison with. Download Anaconda. Affine Transformations Every linear transformation is equivalent to a change in frames Every affine transformation preserves lines However, an affine transformation has only 12 degrees of freedombecause 4 of the elements in the matrix are fixed and are a subset of all possible 4 x 4 linear transformations. • They can be inferred by giving the correspondence of three 2-D points between the input and output images. • Affine transformations map triangles onto triangles. Translation of axes. King ([email protected] For the medium faculty senate there exist collineations that are not affine transformations. 3D Transformations Yong Cao Virginia TechVirginia Tech 5. If we do a translation, T, by by^we convert the problem to reection about a line passing through the origin; the translation matrix is T= 2 4 1 0 0 0 1 b 0 0 1 3 5:. Manually annotated macro‐structures on both pathology and MRI were used to assist registration using a relaxed local affine transformation approximation. Show that an affine transformation is rigid its homogeneous part is an orthogonal matrix. Parameters. The affine transformation Imagine you have a ball lying at (1,0) in your coordinate system. Include translations, rotations, scales, and/or skewing parameters. Fast logarithm and exponential for 3D transformations ( rotational and shearing transformations ) Euclidean parametrisation map for 3D affine transformation (see [1]) Fast polar decomposition ( without SVD. Excised prostate specimens underwent quarter mount step-section pathologic processing, digitization, annotation, and assembly into a PWM. A transformation changes the positions of points in the plane. Transformation matrixes for affine transformations are as follows: 9 DOF transformation matrix which includes scale parameters Sx, Sy and Sz looks as follows \begin{bmatrix}. An affine transformation can differentially scale the data, skew it, rotate it, and translate it. Where I is the identity matrix and N is the unit vector for the surface normal of the plane. The image of a line under any affine transformation is a line. A perspective transformation is not affine, and as such, can't be represented entirely by a matrix. Transformations of Variables Basic Theory The Problem As usual, we start with a random experiment with probability measure ℙ on an underlying sample space. On infinitesimal affine and isometric transformations preserving respective vector fields. C A; simply represents an arbitrary a ne transformation, having 12 degrees of freedom. Flash uses matrices to define affine transformations. This can be computed from the "nice" format transformation information. Mathematically, it is represented as e(x) = (ax + b) mod m. Affine transformation) with that of the transformations (*) was first proved (for ${\rm char}\; k = 0$) by H. PDF | This paper deals with surface normal estimation from calibrated stereo images. This means points on a line will remain in a line after an affine transformation is applied to the coordinate space in which that line exists. Affine Transformation zAffine Transforms needed in OQM since imaging is done on basis of the phase difference between pixels. The usual way to represent an Affine Transform is by using a matrix. glTranslate only allows you to change b. Given the affine map C == aP +b(mod N), where a E (ZINZ)*, b E (ZINZ). Usage with GIS data packages. This produces a transformation whose effect is that of A followed by B. Learn for free about math, art, computer programming, economics, physics, chemistry, biology, medicine, finance, history, and more. These transformations and coordinate systems will be discussed below in more detail. Theorem Affine transformations map affine subspaces to affine subspaces. A single multi-dimensional affine function can represent a long and complex sequence of simpler transformations. (c) Extra discussion on the plane-to-plane projectivity. the result will be the equivalent of doing first the transformation m1 and then m2. not involving gamma correction or whatnot), this is actually pretty simple. Decryption is a slightly different formula, d(x) = a-1 (x - b) mod m. Affine transformations. With beginners, trying to implement an affine transformation in a programming language (C/C++) is really a challenge. Creation You can create an affine2d object using the following methods:. If v is such a vector, then we say that X(v) is the affine transformation of the vector. Include translations, rotations, scales, and/or skewing parameters. Copying and pasting the three blocks of PostScript into a text file with a. A 4x4 matrix can represent all affine transformations (including translation, rotation around origin, reflection, glides, scale from origin contraction and expansion, shear, dilation, spiral similarities). CCS CONCEPTS. [5] (d) Use your answer to part (c) to determine any points (x, y) that are left unchanged by the transformation f g, or to show that there are. So take the image below as my input example: After successfully detecting the area that corresponds to the p…. Manually annotated macro-structures on both pathology and MRI were used to assist registration using a relaxed local affine transformation approximation. It successfully performs affine transformations or more general non-affine transformations such as tiling on the polyhedron, and then converts the transformed polyhedron into equivalent, but optimized (depending on targeted optimization goal), loop nests through polyhedra scanning. The ModelView matrix combined the model and view transformations into one. We will apply a rotation and a translation to a loaded point cloud and display then result. In all this, it is only necessary to keep track 00185 * of the shear angles and translations of points during the shears. Solving for T requires a minimum of 3 pairing points (that aren't degenerate!). With input feature map U, with width W, height H and C channels, outputs are θ, the parameters of transformation Tθ. This repository uses dlib's real-time pose estimation with OpenCV's affine transformation to try to make the eyes and bottom lip appear in the same location on each image. Automatic face recognition usually normalizes the face images as the preprocessing step and then proceeds with the recognition. It is capable of the following operations: Declare Vectors, matrices, quaternions. THis program does some simple graphics transformation in 2D. The affine transformation function is. Sometimes a similarity transformation doesn't do the trick. 9/10/2016 4 Affine properties: composition Affine transforms are closed under composition. affine invariant subspaces of c(c) 233 2. Affine Transformation Shear, Skew, & Rotate Add an Affine transform (sometimes called a Free Transform) to any graphic, then use the interactive on-screen handles to apply a distortion or scaling transform. In the case of affine transformation the scaling can be non-uniform, that is different in each direction. Geometric image transformation, such as translation, scaling, or rotation A transformation that involves a linear transformation followed by a translation Function expressed in the form of the equation of a line or plane see above (Also call 1st order) Relevante Übersetzungen affine transformations plural form of affine transformation. Affine transformations and their inverse When you're programming games or other 3d applications using OpenGL or DirectX, it is often required to use affine transformation matrices to describe transformations in space (4x4 matrices and the like). particular transformations that are not supported by ITransform2D and also for performing numerous transformations in one go. For an affine transformation there are 6 transformation parameters, so you need at least 3 control points (each control point implies 4 coordinates: Xsource, Ysource, Xtarget, Ytarget), but more control points are recommended to have redundancy and thus be able to apply Least. Usage with GIS data packages. Gangopadhyay XLRI C. In the AIR package, the 2D affine model is parameterized in terms of six parameters defined below. In a translation, you shift an image in coordinate space by adding a specified value to the x- and y. The performance of fractal image coding mainly depends on the affine transformations. What happens if I multiply TxP? Let's do that right over here. One such measure is the Arrow-. Find an afne transformation to reect two-dimensional points about this line. The methods are essential in handling digitized locational data and are applicable widely in other graphical applications such as calibrating data sets for plotting, and in. That is, the shape is defined up to an affine transformation in space. convert Matrix4f to Affine transformation in Eigen To rename all the files in a folder; Errors the errors that I get while compiling GTSA adding / Linking GTSAM with ROS; linking external c++ library to ROS January 2014 (4) 2013 (61) December 2013 (10) November 2013 (8) October 2013 (7). Refer to the transformations. Jung ; the case of arbitrary ground field was proved by W. This page documents progress on automating the computation of the transformation matrix by least-squares (Bruce Rindahl) via SQL. Any number of points are said to be collinear when they lie on one line. Next, we will cover some interesting applications and concepts like Face Detection, Image Recognition, Object Detection and Facial Landmark Detection. Define an affine transformation on the CMF’s: For the case of monochromatic SRD, let )w1 (λ), w2 (λ , w3 (λ) be three auxiliary functions of the wavelength and define the affine tri-stimulus values )(Xa ,Ya ,Za through Eqn. Two-Dimensional Affine Transformations Affine transformations of the plane in two dimensions include pure translations, scaling in a given direction, rotation, and shear. For images gray level transformations these take the form g(m,n) = af(m,n) + b (2. Generate a unique affine transformation for each ops. Usage with GIS data packages. Note that the horizontal and vertical grids are perpendicular to each other. The class of bi-affine functions is not closed under composition, but the composition of a bi-affine and an affine function is bi-affine. Depending on the input imagery and output coordinate systems, a nonsymmetric transformation may be REQUIRED to properly fit the points. //get the affine transformation. In addition, to strengthen the S-Box against algebraic attacks, the affine transformation was added. affine transformations keep parallel lines parallel are four different types (primitives): handout - Affine transformation primitives 1. Transformations of Variables Basic Theory The Problem As usual, we start with a random experiment with probability measure ℙ on an underlying sample space. However, since expected utility functions are not uniquely defined (are defined only up to affine transformations), a measure that stays constant with respect to these transformations is needed. In fact, to avoid sampling artifacts, the mapping is done in the reverse order, from destination to the source. Many transformations have been proposed in the past including unimodular transformations (interchange, skew and reversal), fusion, fission, reindexing, scaling, and statement reordering. "A transformation that maps lines to lines (but does not necessarily preserve parallelism) is a projective transformation. For example, because paper maps expand and contract more along the paper grain than across the grain in response to changes in humidity, the scale of a paper map is likely to be slightly greater along one axis than the other. In this paper, we proposed a text detection method which can provide accurate text region. An affine2d object stores information about a 2-D affine geometric transformation and enables forward and inverse transformations. $\endgroup$ – godaygo Jul 11 at 10:26. Then A n C°°(C) is dense in A. An algebraic normalization. This gives us a new view of the intrinsic matrix: a sequence of 2D affine transformations. Note that the matrix form of an affine transformation is a 4-by-4 matrix with the fourth row 0, 0, 0 and 1. To scale the object's texture, set the Scale property. Firstly, and most commonly within the geometry model, the AffineTransformation2D object can be used in the ITransform2D::Transform method to transform an existing Geometry. It is assumed that the reader knows what a matrices are and how to multiply them. That is, the shape is defined up to an affine transformation in space. 2 A ne transformations In geometry, an a ne transformation is a function that maps an object from an a ne space to an other and which preserve structures. Tool to decrypt/encrypt with Affine automatically. Linear transformations A ne transformations Transformations in 3D Graphics 2009/2010, period 1 Lecture 5 Linear and a ne transformations Graphics, 1st period 2009/2010 Lecture 5: linear and a ne transformations. org, freedictionary. Find an afne transformation to reect two-dimensional points about this line. Still to be implemented are geometric primitives and affine transformation of images. For affine transformations, the first two elements of this line are zeros. The usual way to represent an Affine Transform is by using a matrix. First i find the matching pairs in both of the images. , all points lying on a line initially still lie on a line after transformation) and ratios of distances (e. Carlson Center for Imaging Science Rochester Institute of Technology [email protected] Sometimes a similarity transformation doesn't do the trick. 2D and 3D Transformations Doug Bowman Adapted from notes by Yong Cao Virginia Tech. If X and F are compact connected metric abelian groups, T=a + A an affine transformation of X and S = b + Ban affine transformation of Y, what are necessary and sufficient conditions. Fast logarithm and exponential for 3D transformations ( rotational and shearing transformations ) Euclidean parametrisation map for 3D affine transformation (see [1]) Fast polar decomposition ( without SVD. 31: Using the transformation matrix to shear text 104 Figure 10. The affine transformation Imagine you have a ball lying at (1,0) in your coordinate system. There are various ways of achieving 180° or even 360° view, with their distinct pros and cons. In general, an affine transformation is a composition of rotations. Zapraszam, zapraszam kolejny niezrównoważony pseudomatematyczny bełkot. The transformations you can do with a 2D matrix are called affine transformations. Geospatial software of all varieties use an affine transform (sometimes refered to as "geotransform") to go from raster rows/columns to the x/y of the coordinate reference system. , or be the result of operators like vector_angle_to_rigid. Attributes affines list of AffineTransform objects. Full 2D affine transform. When a transformation takes place on a 2D plane, it is called 2D transformation. If A, B and C are collinear, so are their images under any affine map. Cartesian is a type of affine coordinate space, but we can transform it to other affine spaces as we prefer. If and are affine spaces, then every affine transformation : → is of the form ↦ +, where is a linear transformation on the space , is a vector in , and is a vector in. A 2D point transformation requires 9 multiplies and 6 adds But since affine transformations have always the form: The number of operations can be reduced to 4 multiplies and 4 adds ab c x ax by cz defydx eyfz g hi zg xhy iz ++ =++ ++ 00 1 1 1 ab c x ax by c defydx eyf + + =++. برای پردازش‌های بعدی، صرفا تبدیل‌های پایه‌ای عکس شامل چرخش و تبدیل مقیاسی که خطوط موازی را حفظ می‌کند انجام خواهد شد (به آن «تبدیل آفین» (Affine transformation) گفته می‌شود). They preserve straight lines but necessarily not angles or lengths. The transformation between images is modeled as locally affine but globally smooth, and explicitly accounts for local and global variations in image intensities. txt for the full license. In the AIR package, the 2D affine model is parameterized in terms of six parameters defined below. The algorithm compares an input image to its database of preprocessed images and determines if the input matches any image in the database. Combined Rotation and Translation using 4x4 matrix. Therefore, the scale invariant detectors fail in the case of significant affine transformations. Consequently, the distorted text region can be rectified according to the affine parameters. Affine Transformations take place in three steps (TRS) in. Real-Time Tool for Affine Transformations of Two Dimensional IFS Fractal 151 2. And there is even more general formula that covers affine transformations as a corner case but introduces projection. (Method: Since is affine, one can write (i) , where is the homogeneous part of and is the translation; then also (ii). ) Since afﬁne transformations form a group, group theory shows that there exist matrix representations for the group – that is, there is a group of matrices that follows the same rules as the group, with the matrices being. Any plane projective transformation can be expressed by an invertible 3×3 matrix in homogeneous coordinates; conversely, any invertible 3×3 matrix defines a projective transformation of the plane. This paper also introduces a secure and efficient symmetric cryptosystem based on affine transformation. A Retrospective: A Data Locality Optimizing Algorithm M. mapping required in enciphering and deciphering and number of affine transformations. De Bruijn-like digraphs 3 Affine TCP digraphs 4. Similarity transformations preserve the angles of the original object, but not necessarily the size. Transformation Matrix. However, it considers only rotations, translations, and uniform scale changes in finding the mapping. (c) Extra discussion on the plane-to-plane projectivity. どこで出てくるか 3. We can apply affine transformations to an image by describing the transformation with a 3x3 matrix and applying the transformation to each pixel location in the original image to get that pixel's location in the target image. Generic affine transformations are represented by the Transform class which internally is a (Dim+1)^2 matrix. If we do a translation, T, by by^we convert the problem to reection about a line passing through the origin; the translation matrix is T= 2 4 1 0 0 0 1 b 0 0 1 3 5:. This code registers 2-D images. A linear transformation on a vector space can be represented (in a particular basis) as a matrix; an affine transformation can be represented (in a particular coordinate system) as a matrix together with a translation vector. Using matrix multiplication, find the image of the point (3, 4). Copying and pasting the three blocks of PostScript into a text file with a. From the above, We can use an Affine Transformation to express: Rotations (linear transformation) Translations (vector addition) Scale operations (linear transformation) you can see that, in essence, an Affine Transformation represents a relation between two images. Using matrix multiplication, find a point whose image is (13, –4). In linear algebra, a frame of reference is like a vector basis [2], and the transformation to another frame of reference is a change of basis. compose(B) = T B x T A. There are various ways of achieving 180° or even 360° view, with their distinct pros and cons. Affine Transformation in Image Processing: Explained with C++ Transformations are used to change the geometry of the contents within the image.

format: plain


text:
## Cardinal Ordinal Numbers Examples

Cardinal Ordinal Numbers Examples – It is possible to enumerate infinite sets with ordinal numbers. They can also be used to generalize ordinal numbers.But before you are able to use them, you must comprehend what they are and how they function. 1st The ordinal numbers are among the fundamental concepts in mathematics. It is a … Read more

## Cardinal To Ordinal Numbers

Cardinal To Ordinal Numbers – There are a myriad of sets that can be enumerated by using ordinal numbers as tools. They also can help generalize ordinal amounts. 1st The ordinal number is one of the fundamental concepts in math. It is a number that indicates the position of an object within a set of … Read more


text:
# c++ question about stack , heap and dereferencing

## Recommended Posts

finky45    100
This is probably a stupid question as I think I know what the answer is but I want to make sure: By declaring an object with the "new" operator, which creates something on the heap, does that mean that all variables AND pointers contained in it are also on the heap? If so... another question: In my game right now, I have a lot of pointer dereferencing this->getThat()->getSomething()->getAnother()->youguessedit(); No, that is not an exaggeration. Is this really slow? And if it is, do I gain any speed by not creating pointers in objects that I know will be created on the heap anyway? So I would end up using: this->that().something().another().youguessedit(); ...Or is it the same thing?

##### Share on other sites
jpetrie    13160
Quote:
 By declaring an object with the "new" operator, which creates something on the heap, does that mean that all variables AND pointers contained in it are also on the heap?

More or less, yes. There are nitpicky little details and the occasionally obscure edge case, but generally once you put something on the heap, it and its subobjects are on the heap.

Quote:
 Is this really slow? And if it is, do I gain any speed by not creating pointers in objects that I know will be created on the heap anyway? So I would end up using:this->that().something().another().youguessedit();...Or is it the same thing?

There are number of things wrong with this technique. Speed is one of them -- or rather, decreases in technical speed are a side-effect of the poor cache locality of the objects you are likely accessing. That is to say, all those pointers you're following may be pointing to all sorts of different locations in memory, and jumping around like that isn't particularly optimal.

However, the speed penality is probaby small -- small enough that, if this were a good, correct way to access your objects, it would not be worth changing.

However, it's not a good way to access your objects. You aren't doing any checks for null pointers, for example. If the objects can't ever be null, you should perhaps be returning references instead.

How you expose the properties (return them) is not neccessarily the same as how you store them (you could store pointers to Foo inside the class, but return a reference to Foo from GetFoo()). Expose them according to how they should be used -- generally references if they cannot be null -- and store them according to how they should exist. If a particular field of an objects is always present, there's usually no reason for that field to be a pointer to heap storage.

In general, it's usually better to avoid pointers unless you need the behavior a pointer can provide you.

A final note is that this kind of deep pointer chasing is usually symptomatic of poor design: it suggests that you are doing a lot of a processing related to the tail-end of the pointer chain at a higher level point (the base-end of the pointer chain) and thus that your objects are probably little more than "dumb" containers for data with a bunch of naive get/set methods.

##### Share on other sites
stonemetal    288
when you create an object on the heap the whole object is on the heap, so yes to the first question. Each pointer dereference is a memory access and as such is a performance hit but slow no not really. not using pointers means those functions could be inlined. The main question I would be asking myself though is why is it necessary to hop through three or four references to reach something. It sounds like you may have over-engineered and now have containers of containers of containers.

##### Share on other sites
finky45    100
Quote:
 Original post by jpetrieHowever, it's not a good way to access your objects. You aren't doing any checks for null pointers, for example. If the objects can't ever be null, you should perhaps be returning references instead.

Well most of them can be null, when they are deleted.

Quote:
 Original post by jpetrieIn general, it's usually better to avoid pointers unless you need the behavior a pointer can provide you.

The reason I did this was to make damn sure my objects would be stored on the heap as I would have lots of them and didn't want to run out of stack memory.

Quote:
 Original post by jpetrieA final note is that this kind of deep pointer chasing is usually symptomatic of poor design: it suggests that you are doing a lot of a processing related to the tail-end of the pointer chain at a higher level point (the base-end of the pointer chain) and thus that your objects are probably little more than "dumb" containers for data with a bunch of naive get/set methods.

Some are. I have an object which stores arrays of ships, bullets, asteroids etc... This is so I can do collision detection among my ships, and render lists of objects. Then each ship stores SDL_Surfaces (basically images) along with smaller objects such as guns, which also store SDL_Surfaces, about 32 each (SDL can't rotate images, I have to preload them).

My objects do more than just hold data:
When I call .Move() on my Ships, they will also set the angle and location (in the world) of their guns. That location is used by the render function to display things relative to each other on my screen.

But even if they were just dumb containers... isn't that what OOP is all about? organizing things in containers?

Another question about speed: Since my objects contain a lot of data that might be useless in some functions, for example, collision detection. I do plan on doing pixel-perfect detection at some point which means I will need the surfaces, but does making a call on a huge object take longer?

i.e "Object A has 1000 other objects (or pointers to them, if its the same thing for this purpose). Object B has only 5 other objects. If I make a call like ObjectA.getX vs. ObjectB.getX (where X is considerably smaller than the other members) will there be a difference? If so, how big, and why is there a difference? In other words when I make a call on an object does the whole object get copied somewhere, or only the part of it that I am trying to access?

##### Share on other sites
jpetrie    13160
Quote:
 The reason I did this was to make damn sure my objects would be stored on the heap as I would have lots of them and didn't want to run out of stack memory.

This is a premature optimization. It's surprisingly difficult to store too much information on the stack "accidentally." You don't need to make everything a pointer to ensure that, either, and you shouldn't. Remember that which region of memory an object ends up living in isn't as system as "pointer == heap, no pointer == stack." It also has to do with the location of the containg object and that object's declaration and initialization.

Quote:
 Some are. I have an object which stores arrays of ships, bullets, asteroids etc... This is so I can do collision detection among my ships, and render lists of objects. Then each ship stores SDL_Surfaces (basically images) along with smaller objects such as guns, which also store SDL_Surfaces, about 32 each (SDL can't rotate images, I have to preload them).

There should be a separation between logic and presentation; if Ship contains any sort of game logic (a measure of life left, how much bullets the ship has, what weapons its carrying, how to fire the gun, et cetera) it is a logic object and should not have anything to do with rendering. Logic should drive rendering -- that is, tell the rendering subsystem what to draw based on current state -- but they should not, ideally, be mixed together.

Quote:
 But even if they were just dumb containers... isn't that what OOP is all about? organizing things in containers?

Not at all. Object oriented design is about building complete representations that model reality in some way -- "objects" with understanding of both state and behavior. When you externalize your behavior, you start moving to the realm of procedural programming.

Furthermore, good OO design has a lot to do with isolating responsibily, scoping that responsibility to the smallest scope that makes sense. In your case, you seem to have an exeedingly large amount of responsibility tucked away at the high-level end of your objects, and almost no functionality at the low end. This gives the higher-level objects more responsiblity, violating the principle of single responsibility that helps make OO designs cleaner, more maintainable, and reusable.

Quote:
 Another question about speed: Since my objects contain a lot of data that might be useless in some functions, for example, collision detection. I do plan on doing pixel-perfect detection at some point which means I will need the surfaces, but does making a call on a huge object take longer?

No, a member function call is, internally, usually just a call to a regular function that takes the first parameter ("this") that is a pointer to the object that function is being invoked on. The size of that object is irrelevant.

##### Share on other sites
Zahlman    1682
Quote:
 Original post by finky45The reason I did this was to make damn sure my objects would be stored on the heap as I would have lots of them and didn't want to run out of stack memory.

This is generally faulty thinking. Consider, for example:

class Foo {  Bar x, y, z;};

If we put a Foo on the heap, then its contained Bars are also all on the heap, because they are, well, contained. Baked right into the memory structure of the Foo object.

Quote:
 My objects do more than just hold data:When I call .Move() on my Ships, they will also set the angle and location (in the world) of their guns.

Good.

Quote:
 That location is used by the render function to display things relative to each other on my screen.

This depends on how you do it, though. A very powerful guiding principle for OO is "tell, don't ask", aka dependency inversion.

Quote:
 But even if they were just dumb containers... isn't that what OOP is all about? organizing things in containers?

OO is about breathing life into the "things". Organization is just good practice.

Quote:
 i.e "Object A has 1000 other objects (or pointers to them, if its the same thing for this purpose). Object B has only 5 other objects. If I make a call like ObjectA.getX vs. ObjectB.getX (where X is considerably smaller than the other members) will there be a difference? If so, how big, and why is there a difference? In other words when I make a call on an object does the whole object get copied somewhere, or only the part of it that I am trying to access?

There is no such thing as partially copying an object. However, calling a function on an object does not involve copying it. Assuming getX() just returns an 'x' member of the object, what conceptually happens is that some known offset is added to the memory location of the object, and a type-of-x-sized chunk of memory is retrieved from that location.

Let's try an example.

// Suppose we have some declarations like (of course I am omitting lots of stuff)class Renderer {  SDL_Surface* screen;  public:  // Draw the region (x, y, w, h) of the surface onto screen, at (xpos, ypos).  void drawSpriteAt(int xpos, int ypos, int x, int y, int w, int h, const SDL_Surface* surface) const;};class Level {  std::vector<Enemy*> enemies;  public:  Enemy* getEnemy(int index) const;};class Enemy {  SDL_Surface* surface;  SDL_Rect rect; // the portion of the surface that illustrates this enemy  SDL_Point position;  public:  SDL_Surface* getSurface() const;  SDL_Rect& getRect() const;  SDL_Point& getPosition() const;};Level* level;Renderer* renderer;// bad in many waysrenderer->drawSpriteAt(level->getEnemy(i)->getPosition().x, level->getEnemy(i)->getPosition().y, level->getEnemy(i)->getRect().x, level->getEnemy(i)->getRect().y, level->getEnemy(i)->getRect().w, level->getEnemy(i)->getRect().h, level->getEnemy(i)->getSurface());

On the surface, it seems like we're doing a few things correctly: we have accessors instead of just looking at data members directly, and the code has been written to be const-correct. However, we're actually making things hugely more complicated than they need to be, and exactly wrongly organized.

The first things we can do are to get rid of the unnecessary indirection (keep in mind that even if we put all *our* stuff on the stack, the really *big* stuff - i.e., the data pointed at by the SDL_Surface*s - will be put on the heap by SDL), and use a reference to clean up the repeated access pattern.

class Renderer {  SDL_Surface* screen;  public:  // Draw the region (x, y, w, h) of the surface onto screen, at (xpos, ypos).  void drawSpriteAt(int xpos, int ypos, int x, int y, int w, int h, const SDL_Surface* surface) const;};class Level {  std::vector<Enemy> enemies;  public:  Enemy& getEnemy(int index) const;};class Enemy {  SDL_Surface* surface;  SDL_Rect rect;  SDL_Point position;  public:  SDL_Surface* getSurface() const;  SDL_Rect& getRect() const;  SDL_Point& getPosition() const;};Level level;Renderer renderer;// Improved slightlyEnemy& e = level.getEnemy(i);SDL_Point& point = e.getPosition();SDL_Rect& rect = e.getRect();renderer->drawSpriteAt(point.x, point.y, rect.x, rect.y, rect.w, rect.h, e.getSurface());

Now the function call is a lot more readable: we can immediately see what each parameter is for. But it's still rather complicated: why not just pass the structures for position and sprite-rect, and let drawSpriteAt do the unpacking? (I could have made the first example worse: imagine separate accessor functions for x, y, w, h of the rect for example!)

But that is still missing the point: we are reaching into the Enemy structure to do the job of drawing it. That puts the responsibility in the wrong place. The Enemy is the object with the information that's needed for drawing, so the Enemy should assume the responsibility for that draw call. We apply that tell, don't ask principle, and give the Enemy the power to draw itself, and remove the now-unneeded accessors.

class Renderer {  SDL_Surface* screen;  public:  // Draw the region rect of the surface onto screen, at p.  void drawSpriteAt(SDL_Point p, SDL_Rect rect, const SDL_Surface* surface) const;};class Level {  std::vector<Enemy> enemies;  public:  Enemy& getEnemy(int index) const;  int enemyCount() const;};class Enemy {  SDL_Surface* surface;  SDL_Rect rect;  SDL_Point position;  public:  // This time, I'll show the implementation:  void drawTo(const Renderer& r) {    r.drawSpriteAt(position, rect, surface);  }};Level level;Renderer renderer;// Improving bit by bit... now let's see the whole loop:for (int i = 0; i < level.enemyCount(); ++i) {  level.getEnemy(i).drawTo(renderer);}

Wow, much shorter this time! But we can still improve, by repeating the technique for the Level. It knows what all the enemies are; why ask it continually for each enemy in order to draw them? The same principle applies: the level can do the drawing.

class Renderer {  SDL_Surface* screen;  public:  // Draw the region rect of the surface onto screen, at p.  void drawSpriteAt(SDL_Point p, SDL_Rect rect, const SDL_Surface* surface) const;};class Level {  std::vector<Enemy> enemies;  public:  void drawAllEnemies(const Renderer& r) const {    // Because we're not "squeezed through the interface" of another class now,    // we can do the loop in a more natural way:    std::vector<Enemy> end = enemies.end();    for (std::vector<Enemy> it = enemies.begin(); it != end; ++it) {      it->drawTo(r);    }  }};class Enemy {  SDL_Surface* surface;  SDL_Rect rect;  SDL_Point position;  public:  // This time, I'll show the implementation:  void drawTo(const Renderer& r) {    r.drawSpriteAt(position, rect, surface);  }};Level level;Renderer renderer;level.drawAllEnemies(renderer);

Beautiful. Now all the code is in the right place. Only one more change I want to make: the Enemy class presumably has a lot of other stuff in it besides the data for drawing the critter, and there are presumably lots of other things in the game that will need to be drawn the same way. We don't want to have to duplicate this setup in other classes, so it makes sense to extract a Sprite struct, and give the drawTo() function to that. Then the Enemy simply holds a Sprite, and delegates to it for drawing:

class Enemy {  Sprite s; // looks very much like the old Enemy above :)  public:  void drawTo(const Renderer& r) {    s.drawTo(r);  }};

Now we can reuse that in other classes. Instead of duplicating the set of data members and the drawTo implementation, we just duplicate this bit of delegation (and we don't even need that, if we make clever use of inheritance; but be careful - composition and delegation is often more flexible and avoids subtle design problems).

##### Share on other sites
DevFred    840
Quote:
 Original post by ZahlmanOO is about breathing life into the "things".

That sounds quite dramatic.

##### Share on other sites
Arjan B    1136
Wow Zahlman, that's like a whole mini-tutorial ^^. I've always been a little confused about a nice way to keep code organized, readable and "OOP". Your examples made it pretty clear to me and seem like a nice guideline (so I bookmarked this thread). Thank you ^^!

Sorry if this is seen as an annoying off-topic post.. But I just wanted to mention it.

##### Share on other sites
finky45    100
Thanks Zahlman,

Looks I have to change a few things in my code now, and redesign part of it at least.

##### Share on other sites
finky45    100
Got another question for Zahlman:

In my game, the player will always be in the middle of the screen. Consequently where I draw the enemies depends on where the player is in the level.

I don't know how I can implement this while keeping my code object oriented.

If I tell the enemy to draw itself, it needs to know where the player is, to give the right SDL_Rect to the renderer. But it knowing where the player is, is out of its scope. I don't think the enemies need to know where the player is located for drawing purposes. However they will probably know where the player is for other purposes (such as AI), which confuses me even more...

Also, It doesn't seem right for it to be in the renderer object since that brings me back to the kind of code I had before, with getPlayer() type methods.

So, where is the calculation made to offset the SDL_Rect that will be given to the renderer? Where would you put it?

##### Share on other sites
Zahlman    1682
Quote:
 Original post by finky45If I tell the enemy to draw itself, it needs to know where the player is, to give the right SDL_Rect to the renderer. But it knowing where the player is, is out of its scope.

Quote:
 So, where is the calculation made to offset the SDL_Rect that will be given to the renderer? Where would you put it?

No. The renderer knows where it is. The calculation is made in the renderer. The enemy (and player!) gives the renderer an SDL_Point that represents its position in "world space". (The SDL_Rect in my example is for finding a *part* of the spritesheet image to blit *from*, onto the screen.) The renderer translates that point accordingly. The renderer happens to be always on top of the player, because we tell the player about the existence of the renderer at creation (and it stores some kind of reference or pointer), and when the player moves, it tells the renderer to move also.

If the idea of a renderer "being somewhere" bothers you, think of it as a camera instead. Or you may need to make a separate "camera" object that is a part of the renderer (similar to how the "sprite" gets extracted from the enemy).

Quote:
 I don't think the enemies need to know where the player is located for drawing purposes. However they will probably know where the player is for other purposes (such as AI), which confuses me even more...

The enemy asks the player "how far are you from here?", giving its own location. For normal games ( ;) ) the enemy is not going to care about the player's position relative to the edges of the world, but only relative to itself.

##### Share on other sites
dashurc    236
Sorry if this has been covered in the above posts (I only read the first couple), but even if you want the internal representation of something to be a pointer so that you can allocate it on the heap, you can always dereference the pointer inside the class that contains it and return it as a reference.

Generally, any time you dereference a pointer by using * or -> it's a good practice to check to see if it's NULL first. Doing that in the containing class (when you return the reference), and asserting in the case where something is NULL when it shouldn't be can clean up your code a bit, and not having to debug crashes in lines of code that look like the following (or worse) is always a plus:

##### Share on other sites
Shakedown    230
Quote:
 Original post by ZahlmanThe Enemy is the object with the information that's needed for drawing, so the Enemy should assume the responsibility for that draw call. We apply that tell, don't ask principle, and give the Enemy the power to draw itself, and remove the now-unneeded accessors.

What about using a drawVisitor to handle all the functionality of drawing? Remove the power of the Enemy to draw itself, but give the Enemy the ability to provide any necessary information that is required by the drawVisitor, or any other visitor.

Wouldn't this allow for any kind of rendering Visitor to be applied? You could render your Enemies in 2-D or 3-D, or even use pure text output.

##### Share on other sites
finky45    100
Quote:
Original post by Zahlman
Quote:
 Original post by finky45If I tell the enemy to draw itself, it needs to know where the player is, to give the right SDL_Rect to the renderer. But it knowing where the player is, is out of its scope.

Quote:
 So, where is the calculation made to offset the SDL_Rect that will be given to the renderer? Where would you put it?

No. The renderer knows where it is. The calculation is made in the renderer. The enemy (and player!) gives the renderer an SDL_Point that represents its position in "world space". (The SDL_Rect in my example is for finding a *part* of the spritesheet image to blit *from*, onto the screen.) The renderer translates that point accordingly. The renderer happens to be always on top of the player, because we tell the player about the existence of the renderer at creation (and it stores some kind of reference or pointer), and when the player moves, it tells the renderer to move also.

If the idea of a renderer "being somewhere" bothers you, think of it as a camera instead. Or you may need to make a separate "camera" object that is a part of the renderer (similar to how the "sprite" gets extracted from the enemy).

Quote:
 I don't think the enemies need to know where the player is located for drawing purposes. However they will probably know where the player is for other purposes (such as AI), which confuses me even more...

The enemy asks the player "how far are you from here?", giving its own location. For normal games ( ;) ) the enemy is not going to care about the player's position relative to the edges of the world, but only relative to itself.

You're a smart fella Zhalman. Your responses give me so many wonderful ideas and open up the possibilities of my code. Having a "camera" class lets me easily draw 2 different level locations on the screen. If I ever end up finishing this game I think your name belongs in the credits =), as well as other people on here. Hopefully I won't be needing your help again, but I most likely will.

##### Share on other sites
Zahlman    1682
Quote:
Original post by Shakedown
Quote:
 Original post by ZahlmanThe Enemy is the object with the information that's needed for drawing, so the Enemy should assume the responsibility for that draw call. We apply that tell, don't ask principle, and give the Enemy the power to draw itself, and remove the now-unneeded accessors.

What about using a drawVisitor to handle all the functionality of drawing? Remove the power of the Enemy to draw itself, but give the Enemy the ability to provide any necessary information that is required by the drawVisitor, or any other visitor.

Wouldn't this allow for any kind of rendering Visitor to be applied? You could render your Enemies in 2-D or 3-D, or even use pure text output.

Sure. I was trying not to cover too much at once. [wink] Programming is naturally an iterative process, though; we add extra layers of flexibility as a need is proven, and continually make minor improvements to the organization as we go (refactoring), to make those larger changes easier. Applying the Visitor pattern can be a refactoring - after we've already found that we need to draw in two different ways.

In a way, the Sprite factoring is a step in that direction, anyway. Right now, the Level is doing the "visiting", and the Enemies give back Sprite objects - except that actually, it delegates work to the Sprite objects instead. If we gave back data (in the form of "dumb" Sprites), the Visitor could decide how to do the drawing, but it comes at the expense of treating our Sprite like "just data". This is fine, pragmatically; it's better not to delude ourselves in cases like that. But first, establish a need.


text:
# Find the four numbers forming a G.P. in which the $3^{rd}$ term is greater than the $1^{st}$ term by $9$ and the $2^{nd}$ term is greater than the $4^{th}$ term by $18$.

$\begin{array}{1 1}3,-9,27,-81 \\ 2,-6,18,-54 \\ 3,6,12,24 \\ 3,-6,12,-24 \end{array}$

Toolbox:
• $a^2-b^2=(a-b)(a+b)$
• $a^3-b^3=(a-b)(a^2+ab+b^2)$
Let the four terms in G,P, be $a,ar,ar^2\:\:and\:\:ar^3$
It is given that $3^{rd}$ term is greater than the $1^{st}$ term by $9$.
and
the $2^{nd}$ term is greater than the $4^{th}$ term by $18$.
$i.e., t_1+9=t_3$ and $t_4+18=t_2$
$\Rightarrow\:a+9=ar^2$.....(i) and
$ar^3+18=ar$.........(ii)
$\Rightarrow\:a(r^2-1)=9\:\:\:and\:\:\:a(r-r^3)=18$
Dividing the two equations
$\Rightarrow\:\large\frac{ar(1-r^2)}{a(r^2-1)}=\frac{18}{9}$
Taking - sign common from numerator
$\Rightarrow\:-\large\frac{ar(r^2-1)}{a(r^2-1)}=\frac{18}{9}$
$\Rightarrow\:r=-2$
Substituting the value of $r$ in (i) we get
$\Rightarrow\:a=\large\frac{9}{(-2)^2-1}=\frac{9}{3}$$=3$
Substituting the values of $a\:\:and\:\:r$ we get
$ar=3\times (-2)=-6,\:\:ar^2=3\times (-2)^2=12\:\;and\:\:ar^3=3\times(-2)^3=-24$
$\therefore$ The four numbers in G.P are $3,-6,12,-24$


text:
# $C^{2, \alpha}$ regularity for elliptic equations with Neumann boundary conditons

Say $\Omega\subseteq \mathbb{R}^n$ is a bounded open set and $0<\alpha<1$. I need some $C^{2, \alpha}(\overline\Omega)$ regularity result for elliptic equations with Neumann boundary conditions but that is what I find in Jurgen Jost' book:

If $u$ is a weak solution of $\Delta u=f$ in $\Omega$ and $f\in C^\alpha(\Omega)$, then $u\in C^{2,\alpha}(\Omega)$..........(1)

But it says that we can identify $C^{2, \alpha}(\Omega)$ with $C^{2,\alpha}(\overline\Omega)$ here:
http://www.math.ucsd.edu/~bdriver/231-02-03/Lecture_Notes/Holder-spaces.pdf.

However, Jost used both $C^{2, \alpha}(\Omega)$ and $C^{2,\alpha}(\overline\Omega)$ (when he is doing regularity for Dirichlet boundary) in his book, which indicated these two spaces are not the same?

Or do we have $u\in C^{2,\alpha}(\overline\Omega)$ in (1)? Otherwise where can I find some $C^{2,\alpha}(\overline\Omega)$ regularity result with Neumann boundary conditon?

Let $\Omega\subset\mathbb{R}^N$ be a open bounded domain and assume that $f:\Omega\to\mathbb{R}^N$ satisfies $$\frac{|f(x)-f(y)|}{|x-y|^\alpha}\leq M,\ \forall\ x,y\in\Omega\tag{1}$$

for some fixed $\alpha\in (0,1)$. We can conclude from $(1)$ that $f$ is uniformly continuous in $\Omega$.

Because $f$ is uniformly continuous in $\Omega$, we can extend it in a unique way to the boundary of $\Omega$ and we get a function (still denoted by $f$) $f:\overline{\Omega}\to\mathbb{R}$ which is continuus. The question is: Is this function Holder continuous with exponente $\alpha$?

The answer is yes: take $x,y\in\partial\Omega$ with $x\neq y$ and choose $x_n,y_n\in\Omega$ such that $f(x_n)\to f(x)$ and $f(y_n)\to f(y)$. Note that $$\frac{|f(x)-f(y)|}{|x-y|^\alpha}=\lim_{x_n,y_n\to x,y}\frac{|f(x_n)-f(y_n)|}{|x_n-y_n|^\alpha}\leq M$$

The last equality is true because of the continuity of the function $g(x,y)=\frac{|f(x)-f(y)|}{|x-y|^\alpha}$.

We conclude that (in terms of identification) $C^\alpha(\Omega)=C^\alpha(\overline{\Omega})$.

Now here, come the crucial observation. If $\Omega$ does not have a nice boundary, then it's nonsense to talk about $C^1(\overline{\Omega})$ or $C^2(\overline{\Omega})$, therefore, if we ask some regularity on the boundary, to wit, $\partial\Omega \in C^{2,\alpha}$, hence, the same argument given above we have that $C^{2,\alpha}(\Omega)=C^{2,\alpha}(\overline{\Omega})$

Take a look in Theorem 11.2.2. of the book you mentioned from Jost. Note that the boundary regularity is required.

• Thank you very much for your reply. It helps me a lot. – user100356 Oct 12 '13 at 19:00
• You are welcome @user100356 – Tomás Oct 12 '13 at 19:03


text:
# Thermal radiation of a nitrogen sphere

Let's imagine a :

• sphere of 100% pure nitrogen (N2),
• (edit: 1 m diameter) with a constant volume (edit: using a kind of "magic forcefield")
• (edit : at 1 bar)
• in the void
• far from any light source (edit: background is at 0 K)
• at 300K

At this temperature, we should except any solid material to emit IR and to cool down ; it may be approximated by the dark body using an emissivity coefficient. But what happens to our N2 sphere ?

Will it cool down ? At which rate ?

(edit : Bonus question : if the sphere is at 1000K, will it glow as red iron ?)

• According to you, the Nitrogen is at 300K, yeah? What is the temperature of the surroundings you've kept in? Is it absolute zero? – Hritik Narayan Feb 7 '15 at 13:10
• The sphere is in the void, and let's say that the sorrounding "observing" universe is at absolute zero. – Hyades Feb 7 '15 at 13:14
• Unless the sphere has a surface the N2 gas is gonna expand and diffuse into space – pentane Feb 7 '15 at 16:29
• @pentane. Yes, you're right, but this is a theoretical case, for studying radiative thermal behaviour of a gas. As written by Brionius, there is a magical forcefield that keeps its shape and volume constant. – Hyades Feb 7 '15 at 17:30
• Nitrogen at 1 bar in a 1m sphere at 300K is nothing like a blackbody. It is optically thin to visible and IR radiation. You need the emission coefficient integrated over all wavelengths (which will not be $\sigma T^4$) multiplied by the (small) optical depth. – Rob Jeffries Oct 29 '15 at 23:15

At 300K, radiation from your ball of Nitrogen should be pretty well approximated by a black body spectrum. The power density emitted by a black body is given by the Stefan-Boltzmann law:

$$j = \sigma T^4$$

Where $j$ is the power radiated per unit surface area. Therefore, we'll need to know the size of your sphere. Let's keep it general, and say it has a radius $R$, and therefore an area $A = 4 \pi R^2$. I will also assume for simplicity that this sphere of gas is confined by some kind of magic forcefield, and not worry about volume changes. The total power radiating is therefore

$$P = A j$$ $$P = 4 \pi R^2 j$$ $$P = 4 \pi R^2 \sigma T^4$$

For a diatomic gas, the internal energy is given by $U = \frac{5}{2} N k T$. You haven't specified how much gas is in this sphere, or the pressure, so we will again retain generality by keeping the number of particles (not moles) of gas at a constant $N$.

Now we are close to the goal of finding out how fast the sphere cools:

$$P = -\frac{dU}{dt}$$ $$4 \pi R^2 \sigma T^4 = -\frac{d}{dt} (\frac{5}{2} N k T)$$ $$4 \pi R^2 \sigma T^4 = -\frac{5}{2} N k \frac{dT}{dt}$$ $$\frac{dT}{dt} = -\frac{8 \pi R^2 \sigma}{5 N k} T^4$$ $$\frac{dT}{T^4} = -\frac{8 \pi R^2 \sigma}{5 N k} dt$$

Integrating...

$$- \frac{1}{3} (T^{-3} - T_0^{-3}) = -\frac{8 \pi R^2 \sigma}{5 N k} t$$ $$T^{-3} = \frac{24 \pi R^2 \sigma}{5 N k} t + T_0^{-3}$$

Finally, the temperature as a function of time for a sphere of nitrogen gas due to radiative losses is approximated by

$$T(t) = \left (\frac{1}{ \frac{24 \pi R^2 \sigma}{5 N k} t + T_0^{-3}}\right)^{\frac{1}{3}}$$

Where $T_0$ is the initial temperature, $R$ is the radius of the sphere, and $N$ is the number of particles (not moles) of gas in the sphere.

Here is a screenshot of the graph in case you can't use Desmos.

Caveats:

1. This cooling function will hold until the gas becomes cool enough that rotational degrees of freedom are frozen out; then the internal energy will have a different relation to temperature. The cooling function will have the same form, just with different constants.

2. Nitrogen gas is not a perfect blackbody - there are rotational, vibrational, and atomic resonances, but it's probably pretty close, especially at a temperature as low as 300°K.

3. This model assumes the thermal energy is lost from the entire volume uniformly, when in fact the nitrogen on the surface will lose the most. This will result in non-uniform temperature, as well as complicated heat movement via conduction and convection that are difficult to analyze. These effects will be smaller, and this result more accurate, if the sphere radius $R$ is small.

• I've tested the expression for a 1 m sphere at 1 bar for 1 s, and it gives 1.4e-5 K. Is it an error from my calculation or do you have the same result ? – Hyades Feb 7 '15 at 15:20
• Do we need to include an emissivity for the pure N2 in the SB law ? It's difficult to find any value for N2 regarding this quantity, do you know any reference website where I may find it ? – Hyades Feb 7 '15 at 15:22
• Just a precision : I used the perfect gas law to find N=168 mol – Hyades Feb 7 '15 at 15:23
• Yes, I agree that the blackbody assumption breaks down when the distance between the particles approaches the dimensions of the sphere. But for a large number of particles, it would radiate the same amount of power as a sphere of iron at the same temperature. Note power, not energy. The amount of energy radiated would be much less, and the temperature would drop considerably faster. – Brionius Feb 7 '15 at 20:12
• I think it's a stretch to say the surface emission is the same as it would be for a solid. Atoms deeper inside the gas can participate in the emission since their radiation has a good probability of escape; this will affect the results in a way that I find difficult to calculate. I think you are making unsubstantiated assumptions - how the emission will vary with density is an interesting question which I don't think your answer addresses. – Floris Feb 7 '15 at 20:41

The body will lose heat according to the Stefan-Boltman law, that is the heat loss per unit surface area goes as

$$\epsilon \sigma T^4$$

where $\epsilon$ is the emissivity (which is a function of wavelength). It will be hard to judge how quickly the sphere will lose heat - but it is absolutely certain that it will lose heat, given that the surroundings are cooler and therefore heat can be lost by radiation, but not absorbed.

The fact that this is a gas and not a solid doesn't come into it: that just changes how closely the gas molecules are associated with each other; and molecules inside will radiate but they have equal probability of receiving radiation "from outside" so the next flux is still determined by the surface, that is the number of atoms "on the outside".

On further reflection it is possible that the heat loss per unit time scales with the density of the material - but then so does the heat capacity, so I think that if you do the calculation for "solid nitrogen" and scale it, you will get the right answer. Assuming you can estimate the emissivity accurately.

• Is it sure that the black-body law can be used in the case of a gas ? Will the pure N2 sphere emit a black-body spectrum ? I mean that I find it hard to link the black-body assumptions (cavity) with the case of N2 sphere. – Hyades Feb 7 '15 at 14:27
• I've read on numerous website that the light from a flame comes from soot, and not from the heated atmosphere. If the N2 sphere above is at 1000 K, will it glow as red iron, as it would be if a black-body – Hyades Feb 7 '15 at 17:49
• @Hyades yes the soot particles, being more dense and more black, make good radiators. I did say that you need to take emissivity of the molecules into account - this may be quite low. – Floris Feb 7 '15 at 20:43


text:
## Section5.3Eigenvalues and Characteristic Polynomials (GT3)

### Subsection5.3.1Class Activities

#### Activity5.3.1.

An invertible matrix $$M$$ and its inverse $$M^{-1}$$ are given below:

\begin{equation*} M=\left[\begin{array}{cc}1&2\\3&4\end{array}\right] \hspace{2em} M^{-1}=\left[\begin{array}{cc}-2&1\\3/2&-1/2\end{array}\right] \end{equation*}

Which of the following is equal to $$\det(M)\det(M^{-1})\text{?}$$

1. $$\displaystyle -1$$

2. $$\displaystyle 0$$

3. $$\displaystyle 1$$

4. $$\displaystyle 4$$

#### Observation5.3.3.

Consider the linear transformation $$A : \IR^2 \rightarrow \IR^2$$ given by the matrix $$A = \left[\begin{array}{cc} 2 & 2 \\ 0 & 3 \end{array}\right]\text{.}$$

It is easy to see geometrically that

\begin{equation*} A\left[\begin{array}{c}1 \\ 0 \end{array}\right] = \left[\begin{array}{cc} 2 & 2 \\ 0 & 3 \end{array}\right]\left[\begin{array}{c}1 \\ 0 \end{array}\right]= \left[\begin{array}{c}2 \\ 0 \end{array}\right]= 2 \left[\begin{array}{c}1 \\ 0 \end{array}\right]\text{.} \end{equation*}

It is less obvious (but easily checked once you find it) that

\begin{equation*} A\left[\begin{array}{c} 2 \\ 1 \end{array}\right] = \left[\begin{array}{cc} 2 & 2 \\ 0 & 3 \end{array}\right]\left[\begin{array}{c}2 \\ 1 \end{array}\right]= \left[\begin{array}{c} 6 \\ 3 \end{array}\right] = 3\left[\begin{array}{c} 2 \\ 1 \end{array}\right]\text{.} \end{equation*}

#### Definition5.3.4.

Let $$A \in M_{n,n}\text{.}$$ An eigenvector for $$A$$ is a vector $$\vec{x} \in \IR^n$$ such that $$A\vec{x}$$ is parallel to $$\vec{x}\text{.}$$

In other words, $$A\vec{x}=\lambda \vec{x}$$ for some scalar $$\lambda\text{.}$$ If $$\vec x\not=\vec 0\text{,}$$ then we say $$\vec x$$ is a nontrivial eigenvector and we call this $$\lambda$$ an eigenvalue of $$A\text{.}$$

#### Activity5.3.5.

Finding the eigenvalues $$\lambda$$ that satisfy

\begin{equation*} A\vec x=\lambda\vec x=\lambda(I\vec x)=(\lambda I)\vec x \end{equation*}

for some nontrivial eigenvector $$\vec x$$ is equivalent to finding nonzero solutions for the matrix equation

\begin{equation*} (A-\lambda I)\vec x =\vec 0\text{.} \end{equation*}

Which of the following must be true for any eigenvalue?

1. The kernel of the transformation with standard matrix $$A-\lambda I$$ must contain the zero vector, so $$A-\lambda I$$ is invertible.

2. The kernel of the transformation with standard matrix $$A-\lambda I$$ must contain a non-zero vector, so $$A-\lambda I$$ is not invertible.

3. The image of the transformation with standard matrix $$A-\lambda I$$ must contain the zero vector, so $$A-\lambda I$$ is invertible.

4. The image of the transformation with standard matrix $$A-\lambda I$$ must contain a non-zero vector, so $$A-\lambda I$$ is not invertible.

#### Definition5.3.7.

The expression $$\det(A-\lambda I)$$ is called characteristic polynomial of $$A\text{.}$$

For example, when $$A=\left[\begin{array}{cc}1 & 2 \\ 3 & 4\end{array}\right]\text{,}$$ we have

\begin{equation*} A-\lambda I= \left[\begin{array}{cc}1 & 2 \\ 3 & 4\end{array}\right]- \left[\begin{array}{cc}\lambda & 0 \\ 0 & \lambda\end{array}\right]= \left[\begin{array}{cc}1-\lambda & 2 \\ 3 & 4-\lambda\end{array}\right]\text{.} \end{equation*}

Thus the characteristic polynomial of $$A$$ is

\begin{equation*} \det\left[\begin{array}{cc}1-\lambda & 2 \\ 3 & 4-\lambda\end{array}\right] = (1-\lambda)(4-\lambda)-(2)(3) = \lambda^2-5\lambda-2 \end{equation*}

and its eigenvalues are the solutions to $$\lambda^2-5\lambda-2=0\text{.}$$

#### Activity5.3.8.

Let $$A = \left[\begin{array}{cc} 5 & 2 \\ -3 & -2 \end{array}\right]\text{.}$$

##### (a)

Compute $$\det (A-\lambda I)$$ to determine the characteristic polynomial of $$A\text{.}$$

##### (b)

Set this characteristic polynomial equal to zero and factor to determine the eigenvalues of $$A\text{.}$$

#### Activity5.3.9.

Find all the eigenvalues for the matrix $$A=\left[\begin{array}{cc} 3 & -3 \\ 2 & -4 \end{array}\right]\text{.}$$

#### Activity5.3.10.

Find all the eigenvalues for the matrix $$A=\left[\begin{array}{cc} 1 & -4 \\ 0 & 5 \end{array}\right]\text{.}$$

#### Activity5.3.11.

Find all the eigenvalues for the matrix $$A=\left[\begin{array}{ccc} 3 & -3 & 1 \\ 0 & -4 & 2 \\ 0 & 0 & 7 \end{array}\right]\text{.}$$

### Subsection5.3.3Slideshow

Slideshow of activities available at https://teambasedinquirylearning.github.io/linear-algebra/2022/GT3.slides.html.

### Subsection5.3.5Mathematical Writing Explorations

#### Exploration5.3.12.

What are the maximum and minimum number of eigenvalues associated with an $$n \times n$$ matrix? Write small examples to convince yourself you are correct, and then prove this in generality.

### Subsection5.3.6Sample Problem and Solution

Sample problem Example B.1.23.

You have attempted of activities on this page.