Search Results

Search found 1011 results on 41 pages for 'linear algebra'.

Page 5/41 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Matrices: Arrays or separate member variables?

    - by bjz
    I'm teaching myself 3D maths and in the process building my own rudimentary engine (of sorts). I was wondering what would be the best way to structure my matrix class. There are a few options: Separate member variables: struct Mat4 { float m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44; // methods } A multi-dimensional array: struct Mat4 { float[4][4] m; // methods } An array of vectors struct Mat4 { Vec4[4] m; // methods } I'm guessing there would be positives and negatives to each. From 3D Math Primer for Graphics and Game Development, 2nd Edition p.155: Matrices use 1-based indices, so the first row and column are numbered 1. For example, a12 (read “a one two,” not “a twelve”) is the element in the first row, second column. Notice that this is different from programming languages such as C++ and Java, which use 0-based array indices. A matrix does not have a column 0 or row 0. This difference in indexing can cause some confusion if matrices are stored using an actual array data type. For this reason, it’s common for classes that store small, fixed size matrices of the type used for geometric purposes to give each element its own named member variable, such as float a11, instead of using the language’s native array support with something like float elem[3][3]. So that's one vote for method one. Is this really the accepted way to do things? It seems rather unwieldy if the only benefit would be sticking with the conventional math notation.

    Read the article

  • Portal View/Projection Matrix near plane

    - by melak47
    For RenderToTexture/Camera based portal rendering, the basics seems simple enough. However, with a free camera, most of the time it is going to be looking at such portals at an angle: Now a regular near clipping plane will not always work here, it will either intersect with the wall the portal is sitting on, or possibly with objects in front of the wall. The desired near clipping plane would be aligned like the portal, producing a view volume more like this: or this in 3D: So here is my question: How does one construct or "truncate" a view/projection matrix to achieve such an off-camera-normal (near) clipping plane?

    Read the article

  • Mouse pointer position to screen space

    - by Ylisar
    If I have a mouse pointer position in pixels of canvas, I can easily convert it to the -1..1 range for both X & Y by lerping by dividing with canvas dimensions. However, the problem is what I should put in Z & W if I want my screen space position to be on the near plane? The step afterwards would be for me to multiply by the inverse of view-projection to take me to world space, where I easily can construct a ray from the cameras world space position.

    Read the article

  • Vector transform equation explanation

    - by cyberdemon
    I'm trying to understand the maths of moving points in a 3d space by making a game written in C#. I'm looking at this wolfire blog series which explains some basic 3d maths. I've read the first two parts but am stuck on the 3rd. I know it's all really rudimentary stuff but I find Googling for help with equations really hard. The one I'm struggling with is: 0*(0.66,0.75) + 2*(-0.75, 0.66) = (-1.5, 1.3) How can anything multiplied by 0 not be 0? So my question is how does this look in code: x(a,b) + y(c,d) I know it's basic stuff but I just can't see it.

    Read the article

  • Use a vector to index a matrix without linear index

    - by David_G
    G'day, I'm trying to find a way to use a vector of [x,y] points to index from a large matrix in MATLAB. Usually, I would convert the subscript points to the linear index of the matrix.(for eg. Use a vector as an index to a matrix in MATLab) However, the matrix is 4-dimensional, and I want to take all of the elements of the 3rd and 4th dimensions that have the same 1st and 2nd dimension. Let me hopefully demonstrate with an example: Matrix = nan(4,4,2,2); % where the dimensions are (x,y,depth,time) Matrix(1,2,:,:) = 999; % note that this value could change in depth (3rd dim) and time (4th time) Matrix(3,4,:,:) = 888; % note that this value could change in depth (3rd dim) and time (4th time) Matrix(4,4,:,:) = 124; Now, I want to be able to index with the subscripts (1,2) and (3,4), etc and return not only the 999 and 888 which exist in Matrix(:,:,1,1) but the contents which exist at Matrix(:,:,1,2),Matrix(:,:,2,1) and Matrix(:,:,2,2), and so on (IRL, the dimensions of Matrix might be more like size(Matrix) = (300 250 30 200) I don't want to use linear indices because I would like the results to be in a similar vector fashion. For example, I would like a result which is something like: ans(time=1) 999 888 124 999 888 124 ans(time=2) etc etc etc etc etc etc I'd also like to add that due to the size of the matrix I'm dealing with, speed is an issue here - thus why I'd like to use subscript indices to index to the data. I should also mention that (unlike this question: Accessing values using subscripts without using sub2ind) since I want all the information stored in the extra dimensions, 3 and 4, of the i and jth indices, I don't think that a slightly faster version of sub2ind still would not cut it..

    Read the article

  • How to partition bits in a bit array with less than linear time

    - by SiLent SoNG
    This is an interview question I faced recently. Given an array of 1 and 0, find a way to partition the bits in place so that 0's are grouped together, and 1's are grouped together. It does not matter whether 1's are ahead of 0's or 0's are ahead of 1's. An example input is 101010101, and output is either 111110000 or 000011111. Solve the problem in less than linear time. Make the problem simpler. The input is an integer array, with each element either 1 or 0. Output is the same integer array with integers partitioned well. To me, this is an easy question if it can be solved in O(N). My approach is to use two pointers, starting from both ends of the array. Increases and decreases each pointer; if it does not point to the correct integer, swap the two. int * start = array; int * end = array + length - 1; while (start < end) { // Assume 0 always at the end if (*end == 0) { --end; continue; } // Assume 1 always at the beginning if (*start == 1) { ++start; continue; } swap(*start, *end); } However, the interview insists there is a sub-linear solution. This makes me thinking hard but still not get an answer. Can anyone help on this interview question?

    Read the article

  • Linear Search with Jagged Array?

    - by Nerathas
    Hello, I have the following program that creates 100 random elements trough a array. Those 100 random value's are unique, and every value only gets displayed once. Although with the linear search it keeps looking up the entire array. How would i be able to get a Jagged Array into this, so it only "scans" the remaining places left? (assuming i keep the table at 100 max elements, so if one random value is generated the array holds 99 elements with linear search scans and on...) I assume i would have to implent the jagged array somewhere in the FoundLinearInArray? Hopefully this made any sence. Regards. private int ValidNumber(int[] T, int X, int Range) { Random RndInt = new Random(); do { X = RndInt.Next(1, Range + 1); } while (FoundLinearInArray(T, X)); return X; }/*ValidNumber*/ private bool FoundLinearInArray(int[] A, int X) { byte I = 0; while ((I < A.Length) && (A[I] != X)) { I++; } return (I < A.Length); }/*FoundInArray*/ public void FillArray(int[] T, int Range) { for (byte I = 0; I < T.Length; I++) { T[I] = ValidNumber(T, I, Range); } }/*FillArray*/

    Read the article

  • Admob in xml not showing in Linear

    - by NoobMe
    i am implementing admob on my app it appears when the parent is in relative layout but i must not use the alignparentbottom so i am changing it to linear but it doesnt show when i change it to linear.. any tips? help? thanks in advance here it is in xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <RelativeLayout android:id="@+id/banner_holder" android:layout_width="match_parent" android:layout_height="wrap_content" > <ImageView android:id="@+id/offline_banner" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerInParent="true" android:background="@color/black" android:src="@drawable/offline_banner" /> <com.google.ads.AdView xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" android:id="@+id/adView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" ads:adSize="SMART_BANNER" ads:adUnitId="@string/unit_id" ads:loadAdOnCreate="true" /> </RelativeLayout> <FrameLayout android:id="@+id/fragmentContainer" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout> i want the admob to be at the bottom part of the screen without using the alignparentbottom of relative layout thanks~

    Read the article

  • is there a formal algebra method to analyze programs?

    - by Gabriel
    Is there a formal/academic connection between an imperative program and algebra, and if so where would I learn about it? The example I'm thinking of is: if(C1) { A1(); A2(); } if(C2) { A1(); A2(); } Represented as a sum of terms: (C1)(A1) + (C1)(A2) + (C2)(A1) + (C2)(A2) = (C1+C2)(A1+A2) The idea being that manipulation could lead to programatic refactoring - "factoring" being the common concept in this example.

    Read the article

  • Moving from Linear Probing to Quadratic Probing (hash collisons)

    - by Nazgulled
    Hi, My current implementation of an Hash Table is using Linear Probing and now I want to move to Quadratic Probing (and later to chaining and maybe double hashing too). I've read a few articles, tutorials, wikipedia, etc... But I still don't know exactly what I should do. Linear Probing, basically, has a step of 1 and that's easy to do. When searching, inserting or removing an element from the Hash Table, I need to calculate an hash and for that I do this: index = hash_function(key) % table_size; Then, while searching, inserting or removing I loop through the table until I find a free bucket, like this: do { if(/* CHECK IF IT'S THE ELEMENT WE WANT */) { // FOUND ELEMENT return; } else { index = (index + 1) % table_size; } while(/* LOOP UNTIL IT'S NECESSARY */); As for Quadratic Probing, I think what I need to do is change how the "index" step size is calculated but that's what I don't understand how I should do it. I've seen various pieces of code, and all of them are somewhat different. Also, I've seen some implementations of Quadratic Probing where the hash function is changed to accommodated that (but not all of them). Is that change really needed or can I avoid modifying the hash function and still use Quadratic Probing? EDIT: After reading everything pointed out by Eli Bendersky below I think I got the general idea. Here's part of the code at http://eternallyconfuzzled.com/tuts/datastructures/jsw_tut_hashtable.aspx: 15 for ( step = 1; table->table[h] != EMPTY; step++ ) { 16 if ( compare ( key, table->table[h] ) == 0 ) 17 return 1; 18 19 /* Move forward by quadratically, wrap if necessary */ 20 h = ( h + ( step * step - step ) / 2 ) % table->size; 21 } There's 2 things I don't get... They say that quadratic probing is usually done using c(i)=i^2. However, in the code above, it's doing something more like c(i)=(i^2-i)/2 I was ready to implement this on my code but I would simply do: index = (index + (index^index)) % table_size; ...and not: index = (index + (index^index - index)/2) % table_size; If anything, I would do: index = (index + (index^index)/2) % table_size; ...cause I've seen other code examples diving by two. Although I don't understand why... 1) Why is it subtracting the step? 2) Why is it diving it by 2?

    Read the article

  • Non-linear regression models in PostgreSQL using R

    - by Dave Jarvis
    Background I have climate data (temperature, precipitation, snow depth) for all of Canada between 1900 and 2009. I have written a basic website and the simplest page allows users to choose category and city. They then get back a very simple report (without the parameters and calculations section): The primary purpose of the web application is to provide a simple user interface so that the general public can explore the data in meaningful ways. (A list of numbers is not meaningful to the general public, nor is a website that provides too many inputs.) The secondary purpose of the application is to provide climatologists and other scientists with deeper ways to view the data. (Using too many inputs, of course.) Tool Set The database is PostgreSQL with R (mostly) installed. The reports are written using iReport and generated using JasperReports. Poor Model Choice Currently, a linear regression model is applied against annual averages of daily data. The linear regression model is calculated within a PostgreSQL function as follows: SELECT regr_slope( amount, year_taken ), regr_intercept( amount, year_taken ), corr( amount, year_taken ) FROM temp_regression INTO STRICT slope, intercept, correlation; The results are returned to JasperReports using: SELECT year_taken, amount, year_taken * slope + intercept, slope, intercept, correlation, total_measurements INTO result; JasperReports calls into PostgreSQL using the following parameterized analysis function: SELECT year_taken, amount, measurements, regression_line, slope, intercept, correlation, total_measurements, execute_time FROM climate.analysis( $P{CityId}, $P{Elevation1}, $P{Elevation2}, $P{Radius}, $P{CategoryId}, $P{Year1}, $P{Year2} ) ORDER BY year_taken This is not an optimal solution because it gives the false impression that the climate is changing at a slow, but steady rate. Questions Using functions that take two parameters (e.g., year [X] and amount [Y]), such as PostgreSQL's regr_slope: What is a better regression model to apply? What CPAN-R packages provide such models? (Installable, ideally, using apt-get.) How can the R functions be called within a PostgreSQL function? If no such functions exist: What parameters should I try to obtain for functions that will produce the desired fit? How would you recommend showing the best fit curve? Keep in mind that this is a web app for use by the general public. If the only way to analyse the data is from an R shell, then the purpose has been defeated. (I know this is not the case for most R functions I have looked at so far.) Thank you!

    Read the article

  • Calculating rotation and translation matrices between two odometry positions for monocular linear triangulation

    - by user1298891
    Recently I've been trying to implement a system to identify and triangulate the 3D position of an object in a robotic system. The general outline of the process goes as follows: Identify the object using SURF matching, from a set of "training" images to the actual live feed from the camera Move/rotate the robot a certain amount Identify the object using SURF again in this new view Now I have: a set of corresponding 2D points (same object from the two different views), two odometry locations (position + orientation), and camera intrinsics (focal length, principal point, etc.) since it's been calibrated beforehand, so I should be able to create the 2 projection matrices and triangulate using a basic linear triangulation method as in Hartley & Zissermann's book Multiple View Geometry, pg. 312. Solve the AX = 0 equation for each of the corresponding 2D points, then take the average In practice, the triangulation only works when there's almost no change in rotation; if the robot even rotates a slight bit while moving (due to e.g. wheel slippage) then the estimate is way off. This also applies for simulation. Since I can only post two hyperlinks, here's a link to a page with images from the simulation (on the map, the red square is simulated robot position and orientation, and the yellow square is estimated position of the object using linear triangulation.) So you can see that the estimate is thrown way off even by a little rotation, as in Position 2 on that page (that was 15 degrees; if I rotate it any more then the estimate is completely off the map), even in a simulated environment where a perfect calibration matrix is known. In a real environment when I actually move around with the robot, it's worse. There aren't any problems with obtaining point correspondences, nor with actually solving the AX = 0 equation once I compute the A matrix, so I figure it probably has to do with how I'm setting up the two camera projection matrices, specifically how I'm calculating the translation and rotation matrices from the position/orientation info I have relative to the world frame. How I'm doing that right now is: Rotation matrix is composed by creating a 1x3 matrix [0, (change in orientation angle), 0] and then converting that to a 3x3 one using OpenCV's Rodrigues function Translation matrix is composed by rotating the two points (start angle) degrees and then subtracting the final position from the initial position, in order to get the robot's straight and lateral movement relative to its starting orientation Which results in the first projection matrix being K [I | 0] and the second being K [R | T], with R and T calculated as described above. Is there anything I'm doing really wrong here? Or could it possibly be some other problem? Any help would be greatly appreciated.

    Read the article

  • How to use unset() for this Linear Linked List in PHP

    - by Peter
    I'm writing a simple linear linked list implementation in PHP. This is basically just for practice... part of a Project Euler problem. I'm not sure if I should be using unset() to help in garbage collection in order to avoid memory leaks. Should I include an unset() for head and temp in the destructor of LLL? I understand that I'll use unset() to delete nodes when I want, but is unset() necessary for general clean up at any point? Is the memory map freed once the script terminates even if you don't use unset()? I saw this SO question, but I'm still a little unclear. Is the answer that you simply don't have to use unset() to avoid any sort of memory leaks associated with creating references? I'm using PHP 5.. btw. Unsetting references in PHP PHP references tutorial Here is the code - I'm creating references when I create $temp and $this-head at certain points in the LLL class: class Node { public $data; public $next; } class LLL { // The first node private $head; public function __construct() { $this->head = NULL; } public function insertFirst($data) { if (!$this->head) { // Create the head $this->head = new Node; $temp =& $this->head; $temp->data = $data; $temp->next = NULL; } else { // Add a node, and make it the new head. $temp = new Node; $temp->next = $this->head; $temp->data = $data; $this->head =& $temp; } } public function showAll() { echo "The linear linked list:<br/>&nbsp;&nbsp;"; if ($this->head) { $temp =& $this->head; do { echo $temp->data . " "; } while ($temp =& $temp->next); } else { echo "is empty."; } echo "<br/>"; } } Thanks!

    Read the article

  • Android: Using linear gradient as background looks banded

    - by user329692
    Hi All! I'm trying to apply a linear gradient to my ListView. This is the content of my drawable xml: <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <gradient android:startColor="#3A3C39" android:endColor="#181818" android:angle="270" /> <corners android:radius="0dp" /> </shape> So I apply it to my ListView with: android:background="@drawable/shape_background_grey" It works but it looks very "banded" on emulator and on a real device too. Is there any way to reduce this "behaviour"?

    Read the article

  • linear interpolation on 8bit microcontroller

    - by JB
    I need to do a linear interpolation over time between two values on an 8 bit PIC microcontroller (Specifically 16F627A but that shouldn't matter) using PIC assembly language. Although I'm looking for an algorithm here as much as actual code. I need to take an 8 bit starting value, an 8 bit ending value and a position between the two (Currently represented as an 8 bit number 0-255 where 0 means the output should be the starting value and 255 means it should be the final value but that can change if there is a better way to represent this) and calculate the interpolated value. Now PIC doesn't have a divide instruction so I could code up a general purpose divide routine and effectivly calculate (B-A)/(x/255)+A at each step but I feel there is probably a much better way to do this on a microcontroller than the way I'd do it on a PC in c++ Has anyone got any suggestions for implementing this efficiently on this hardware?

    Read the article

  • android linear layout solution

    - by dykzei
    ![alt text][1] [1]: http://s48.radikal.ru/i120/1005/ff/6e439e04bbc8.jpg hi what i'm trying to achieve is #1 but what i get is #2 it seems linear layout stacks with height of it's first element and shrinks second's element height to that. the xml for those is the following: <?xml version="1.0" encoding="utf-8"?> android:layout_weight="5" / android:text="Aaa aaaaa aaa aaaaa, aaaaaaa aaa aaa a, aaa aa aaaaaaa aaa aa. Aaa aaaaa aaa aaaaa, aaaaaaa aaa aaa a, aaa aa aaaaaaa aaa aa. Aaa aaaaa aaa aaaaa, aaaaaaa aaa aaa a, aaa aa aaaaaaa aaa aa. Aaa aaaaa aaa aaaaa, aaaaaaa aaa aaa a, aaa aa aaaaaaa aaa aa. Aaa aaaaa aaa aaaaa, aaaaaaa aaa aaa a, aaa aa aaaaaaa aaa aa. Aaa aaaaa aaa aaaaa, aaaaaaa aaa aaa a, aaa aa aaaaaaa aaa aa." /

    Read the article

  • Linear complexity and quadratic complexity

    - by jasonline
    I'm just not sure... If you have a code that can be executed in either of the following complexities: A sequence of O(n), like for example: two O(n) in sequence O(n²) The preferred version would be the one that can be executed in linear time. Would there be a time such that the sequence of O(n) would be too much and that O(n²) would be preferred? In other words, is the statement C x O(n) < O(n²) always true for any constant C? Why or why not? What are the factors that would affect the condition such that it would be better to choose the O(n²) complexity?

    Read the article

  • Implementing a linear, binary SVM (support vector machine)

    - by static_rtti
    I want to implement a simple SVM classifier, in the case of high-dimensional binary data (text), for which I think a simple linear SVM is best. The reason for implementing it myself is basically that I want to learn how it works, so using a library is not what I want. The problem is that most tutorials go up to an equation that can be solved as a "quadratic problem", but they never show an actual algorithm! So could you point me either to a very simple implementation I could study, or (better) to a tutorial that goes all the way to the implementation details? Thanks a lot!

    Read the article

  • Tool to write linear temporal logic from UML 2.0 sequence diagram

    - by user326180
    i am working on checking model consistency of software. to do this i need to write linear temporal logic for UML 2.0 sequence diagram. if any body have any other tool for the same please response as soon as possible. I will be very obliged to you. i have found charmy tool have plugin for the same. Does anybody have source code for charmy tool(CHecking ARchitectural Model consistencY). It is not available on their website. Thanks in advance.

    Read the article

  • Linear time and quadratic time

    - by jasonline
    I'm just not sure... If you have a code that can be executed in either of the following complexities: (1) A sequence of O(n), like for example: two O(n) in sequence (2) O(n²) The preferred version would be the one that can be executed in linear time. Would there be a time such that the sequence of O(n) would be too much and that O(n²) would be preferred? In other words, is the statement C x O(n) < O(n²) always true for any constant C? If no, what are the factors that would affect the condition such that it would be better to choose the O(n²) complexity?

    Read the article

  • Reporting Services Linear Gauge Scale

    - by lnediger
    I have set up a linear gauge in Reporting Services 2008. What I would like to do is specify my scale interval. The only problem with this is the scale intervals I would like to use are not at constant intervals. For example, say the scale min is $0 and the scale max is $10 000. Depending on the chart I may want an interval marker labelled at $2000, $5000, then $7945. These numbers would be calculated based on percentages of scale max specified in the dataset. I have not been able to figure out how I would go about doing this.

    Read the article

  • Understanding linear linked list

    - by ArtWorkAD
    Hi, I have some problems understanding the linear linked list data structure. This is how I define a list element: class Node{ Object data; Node link; public Node(Object pData, Node pLink){ this.data = pData; this.link = pLink; } } To keep it simple we say that a list are linked nodes so we do not need to define a class list (recursion principle). My problem is that I am really confused in understanding how nodes are connected, more precisely the sequence of the nodes when we connect them. Node n1 = new Node(new Integer(2), null); Node n2 = new Node(new Integer(1), n1); What is link? Is it the previous or the next element? Any other suggestions to help me understanding this data structure?

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >