Search Results

Search found 614 results on 25 pages for 'vectors'.

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

  • How can I calculate the angle between two 2D vectors?

    - by Error 454
    I am working on some movement AI where there are no obstacles and movement is restricted to the XY plane. I am calculating two vectors, v, the facing direction of ship 1, and w, the vector pointing from the position of ship 1 to ship 2. I am then calculating the angle between these two vectors using the formula arccos((v · w) / (|v| · |w|)) The problem I'm having is that arccos only returns values between 0° and 180°. This makes it impossible to determine whether I should turn left or right to face the other ship. Is there a better way to do this?

    Read the article

  • HTTP requests and Apache modules: Creative attack vectors

    - by pinkgothic
    Slightly unorthodox question here: I'm currently trying to break an Apache with a handful of custom modules. What spawned the testing is that Apache internally forwards requests that it considers too large (e.g. 1 MB trash) to modules hooked in appropriately, forcing them to deal with the garbage data - and lack of handling in the custom modules caused Apache in its entirety to go up in flames. Ouch, ouch, ouch. That particular issue was fortunately fixed, but the question's arisen whether or not there may be other similar vulnerabilities. Right now I have a tool at my disposal that lets me send a raw HTTP request to the server (or rather, raw data through an established TCP connection that could be interpreted as an HTTP request if it followed the form of one, e.g. "GET ...") and I'm trying to come up with other ideas. (TCP-level attacks like Slowloris and Nkiller2 are not my focus at the moment.) Does anyone have a few nice ideas how to confuse the server and/or its modules to the point of self-immolation? Broken UTF-8? (Though I doubt Apache cares about encoding - I imagine it just juggles raw bytes.) Stuff that is only barely too long, followed by a 0-byte, followed by junk? et cetera I don't consider myself a very good tester (I'm doing this by necessity and lack of manpower; I unfortunately don't even have a more than basic grasp of Apache internals that would help me along), which is why I'm hoping for an insightful response or two or three. Maybe some of you have done some similar testing for your own projects? (If stackoverflow is not the right place for this question, I apologise. Not sure where else to put it.)

    Read the article

  • is it wasteful/bad design to use a vector/list where in most instances it will only have one element

    - by lucid
    is it wasteful/bad design to use a vector/list where in most instances it will only have one element? example: class dragon { ArrayList<head> = new ArrayList<head> Heads; tail Tail = new tail(); body Body = new body(); dragon() { theHead=new head(); Heads.add(theHead); } void nod() { for (int i=0;i<Heads.size();i++) { heads.get(i).GoUpAndDown(); } } } class firedragon extends dragon { } class icedragon extends dragon { } class lightningdragon extends dragon { } // 10 other one-headed dragon declarations here class hydra extends dragon { hydra() { anotherHead=new head(); for (int i=0;i<2;i++) { Heads.add(anotherHead); } } } class superhydra extends dragon { superhydra() { anotherHead=new head(); for (int i=0;i<4;i++) { Heads.add(anotherHead); } } }

    Read the article

  • Create a HTML table from nested maps (and vectors)

    - by Kenny164
    I'm trying to create a table (a work schedule) I have coded previously using python, I think it would be a nice introduction to the Clojure language for me. I have very little experience in Clojure (or lisp in that matter) and I've done my rounds in google and a good bit of trial and error but can't seem to get my head around this style of coding. Here is my sample data (will be coming from an sqlite database in the future): (def smpl2 (ref {"Salaried" [{"John Doe" ["12:00-20:00" nil nil nil "11:00-19:00"]} {"Mary Jane" [nil "12:00-20:00" nil nil nil "11:00-19:00"]}] "Shift Manager" [{"Peter Simpson" ["12:00-20:00" nil nil nil "11:00-19:00"]} {"Joe Jones" [nil "12:00-20:00" nil nil nil "11:00-19:00"]}] "Other" [{"Super Man" ["07:00-16:00" "07:00-16:00" "07:00-16:00" "07:00-16:00" "07:00-16:00"]}]})) I was trying to step through this originally using for then moving onto doseq and finally domap (which seems more successful) and dumping the contents into a html table (my original python program outputed this from a sqlite database into an excel spreadsheet using COM). Here is my attempt (the create-table fn): (defn html-doc [title & body] (html (doctype "xhtml/transitional") [:html [:head [:title title]] [:body body]])) (defn create-table [] [:h1 "Schedule"] [:hr] [:table (:style "border: 0; width: 90%") [:th "Name"][:th "Mon"][:th "Tue"][:th "Wed"] [:th "Thur"][:th "Fri"][:th "Sat"][:th "Sun"] [:tr (domap [ct @smpl2] [:tr [:td (key ct)] (domap [cl (val ct)] (domap [c cl] [:tr [:td (key c)]]))]) ]]) (defroutes tstr (GET "/" ((html-doc "Sample" create-table))) (ANY "*" 404)) That outputs the table with the sections (salaried, manager, etc) and the names in the sections, I just feel like I'm abusing the domap by nesting it too many times as I'll probably need to add more domaps just to get the shift times in their proper columns and the code is getting a 'dirty' feel to it. I apologize in advance if I'm not including enough information, I don't normally ask for help on coding, also this is my 1st SO question :). If you know any better approaches to do this or even tips or tricks I should know as a newbie, they are definitely welcome. Thanks.

    Read the article

  • translation/rotation of a HUD against a camera using vectors in Euclidian 3D space

    - by Jakob
    i've got 2 points in 3D space: the camera position and the camera lookAt. the camera movement is restricted akin to typical first person shooter games. you can move the cam freely, tilt horizontally and up to 90 degrees vertically, but not roll. so now i want to draw a HUD to the screen, on which i can move the mouse freely, with the position of the cursor correctly translating into 3D space. the easy part was to draw something directly in front of the camera. V0 = camPos; V1 = lookAt; V2 = lookAt-camPos; normalize V2; mutiply V2 according to camera frustum V3 = V0+V2 draw something at V3 now the part i don't get: i could use V3 and add to that the rotations of the cam combined with the x/y of the mouse cursor, somehow, right? that's what i want.

    Read the article

  • Python Vector Class

    - by sfjedi
    I'm coming from a C# background where this stuff is super easy—trying to translate into Python for Maya. There's gotta' be a better way to do this. Basically, I'm looking to create a Vector class that will simply have x, y and z coordinates, but it would be ideal if this class returned a tuple with all 3 coordinates and if you could edit the values of this tuple through x, y and z properties, somehow. This is what I have so far, but there must be a better way to do this than using an exec statement, right? I hate using exec statements. class Vector(object): '''Creates a Maya vector/triple, having x, y and z coordinates as float values''' def __init__(self, x=0, y=0, z=0): self.x, self.y, self.z = x, y, z def attrsetter(attr): def set_float(self, value): setattr(self, attr, float(value)) return set_float for xyz in 'xyz': exec("%s = property(fget=attrgetter('_%s'), fset=attrsetter('_%s'))" % (xyz, xyz, xyz))

    Read the article

  • HT create a new vector in data frame that takes correlation of existing vectors

    - by Milktrader
    I have a time series of two indexes, with each row representing the closing price on the same day. I'd like to go to row 30 and lookback over the last 30 'days' and calculate the pearson correlation. And then store that value in a new vector. Then, repeat the calculation for the entire time series. It is a trivial task in Excel, so I'm convinced it can be done in R. I don't know the method to use though.

    Read the article

  • Variable sized packet structs with vectors

    - by Rev316
    Lately I've been diving into network programming, and I'm having some difficulty constructing a packet with a variable "data" property. Several prior questions have helped tremendously, but I'm still lacking some implementation details. I'm trying to avoid using variable sized arrays, and just use a vector. But I can't get it to be transmitted correctly, and I believe it's somewhere during serialization. Now for some code. Packet Header class Packet { public: void* Serialize(); bool Deserialize(void *message); unsigned int sender_id; unsigned int sequence_number; std::vector<char> data; }; Packet ImpL typedef struct { unsigned int sender_id; unsigned int sequence_number; std::vector<char> data; } Packet; void* Packet::Serialize(int size) { Packet* p = (Packet *) malloc(8 + 30); p->sender_id = htonl(this->sender_id); p->sequence_number = htonl(this->sequence_number); p->data.assign(size,'&'); //just for testing purposes } bool Packet::Deserialize(void *message) { Packet *s = (Packet*)message; this->sender_id = ntohl(s->sender_id); this->sequence_number = ntohl(s->sequence_number); this->data = s->data; } During execution, I simply create a packet, assign it's members, and send/receive accordingly. The above methods are only responsible for serialization. Unfortunately, the data never gets transferred. Couple of things to point out here. I'm guessing the malloc is wrong, but I'm not sure how else to compute it (i.e. what other value it would be). Other than that, I'm unsure of the proper way to use a vector in this fashion, and would love for someone to show me how (code examples please!) :) Edit: I've awarded the question to the most comprehensive answer regarding the implementation with a vector data property. Appreciate all the responses!

    Read the article

  • Vim OmniCppComplete on vectors of pointers

    - by Alex
    Hi, I might have done something wrong in the set up but is OmniCppComplete supposed to provide the members/functions of classes when doing this? vectorofpointers[0]-> At the moment all I get when trying that are things relating to the vector class itself, which obviously isn't very useful. I think it might have been working before I tagged /usr/include/ but I could be wrong. Also, is it possible to disable the preview window? I find it just clutters up my workspace. And since I enabled ShowPrototypeInAbbr I don't really need it. Thanks, Alex

    Read the article

  • STL Vectors, pointers and classes

    - by anubis9
    Hey! Let's say i have 2 classes: class Class1 { public: std::vector<CustomClass3*> mVec; public: Class1(); ~Class1() { //iterate over all the members of the vector and delete the objects } }; class InitializerClass2 { private: Class1 * mPtrToClass1; public: InitializerClass2(); void Initialize() { mPtrToClass1->mVec.push_back(new CustomClass3(bla bla parameters)); } }; Will this work? Or the memory allocated in the InitializerClass2::Initialize() method might get corrupted after the method terminates? Thanks!

    Read the article

  • Vectors rotations 3D camera tiliting

    - by TallGuy
    Hopefully easy answer, but I cannot get it. I have a 3D render engine I have written. I have the camera position, the lookat position and the up vector. I want to be able to "tilt" the camera left, right, up and down. Like a camera on a fixed tripod that you can grab the handle and tilt it it up, down, left right etc. The maths stumps me. I have been able to do forwards/backwards dolly and up/down/left/right panning, but cannot work out the vector math to get it to tilt. For left and right tilt I want to rotate the lookat position around the camera position, but I need to take into account the up vector, otherwise the rotation doesn't know which axis to to turn around. The maths/algorithm I need is along the lines of... Camera=(cx,cy,cz) Lookat=(lx,ly,lz) Up=(ux,uy,uz) RotatePointAroundVector(lx,ly,lz,ux,uy,uz,amount) Can anyone assist with the maths involved? Many thanks.

    Read the article

  • Unique keys for Sphinx along three vectors instead of two

    - by Brendon Muir
    I'm trying to implement thinking-sphinx across multiple 'sites' hosted under a single rails application. I'm working with the developer of thinking-sphinx to sort through the finer details and am making good progress, but I need help with a maths problem: Usually the formula for making a unique ID in a thinking-sphinx search index is to take the id, multiply it by the total number of models that are searchable, and add the number of the currently indexed model: id * total_models + current_model This works well, but now I also through an entity_id into the mix, so there are three vextors for making this ID unique. Could someone help me figure out the equation to gaurantee that the id's will never collide using these three variables: id, total_models, total_entities The entity ID is an integer. I thought of: id * (total_models + total_entities) + (current_model + current_entity) but that results in collisions. Any help would be greatly appreciated :)

    Read the article

  • Having trouble creating vectors of System::String^

    - by Justen
    So I have a regex expression to parse certain parts of a file name. I'm trying to store each part in its own vector until I use it later, but it won't let me. One error I get when I try making a vector of System::String^ is that error C3698: 'System::String ^' : cannot use this type as argument of 'new' Then, when I try just making a vector of std::string, it can't implicitly convert to type System::String^, and casting won't work either. void parseData() { System::String^ pattern = "(\\D+)(\\d+)(\\w{1})(\\d+)\\.(\\D{3})"; std::vector < System::String^ > x, y, filename, separator; Regex re( pattern ); for ( int i = 0; i < openFileDialog1->FileNames->Length; i++ ) { Match^ m = re.Match( openFileDialog1->FileNames[i] ); filename.push_back( m->Groups[0]->Value );/* x.push_back( m->Groups[1]->Value ); separator.push_back( m->Groups[2]->Value ); y.push_back( m->Groups[3]->Value );*/ } }

    Read the article

  • A question on vectors, pointers and iterators

    - by xbonez
    Guys, I have a midterm examination tomorrow, and I was looking over the sample paper, and I'm not sure about this question. Any help would be appreciated. Let v be a vector<Thingie*>, so that each element v[i] contains a pointer to a Thingie. If p is a vector<Thingie*>::iterator, answer the following questions: what type is p? what type is *p? what code provides the address of the actual Thingie? what code provides the actual Thingie?

    Read the article

  • Vector of vectors of T in template<T> class

    - by topright
    Why this code does not compile (Cygwin)? #include <vector> template <class Ttile> class Tilemap { typedef std::vector< Ttile > TtileRow; typedef std::vector< TtileRow > TtileMap; typedef TtileMap::iterator TtileMapIterator; // error here }; error: type std::vector<std::vector<Ttile, std::allocator<_CharT> >, std::allocator<std::vector<Ttile, std::allocator<_CharT> > > >' is not derived from typeTilemap'

    Read the article

  • Map entries become vectors when piped thru a macro

    - by Gavin Grover
    In Clojure, a map entry created within a macro is preserved... (class (eval `(new clojure.lang.MapEntry :a 7))) ;=> clojure.lang.MapEntry ...but when piped thru from the outside context collapses to a vector... (class (eval `~(new clojure.lang.MapEntry :a 7))) ;=> clojure.lang.PersistentVector This behavior is defined inside LispReader.syntaxQuote(Object form) condition if(form instanceof IPersistentCollection). Does anyone know if this is intended behavior or something that will be fixed?

    Read the article

  • Emacs, C++ code completion for vectors

    - by Caglar Toklu
    Hi, I am new to Emacs, and I have the following code as a sample. I have installed GNU Emacs 23.1.1 (i386-mingw-nt6.1.7600), installed cedet-1.0pre7.tar.gz. , installed ELPA, and company. You can find my simple Emacs configuration at the bottom. The problem is, when I type q[0] in main() and press . (dot), I see the 37 members of the vector, not Person although first_name and last_name are expected. The completion works as expected in the function greet() but it has nothing to do with vector. My question is, how can I accomplish code completion for vector elements too? #include <iostream> #include <vector> using namespace std; class Person { public: string first_name; string last_name; }; void greet(Person a_person) { // a_person.first_name is completed as expected! cout << a_person.first_name << "|"; cout << a_person.last_name << endl; }; int main() { vector<Person> q(2); Person guy1; guy1.first_name = "foo"; guy1.last_name = "bar"; Person guy2; guy2.first_name = "stack"; guy2.last_name = "overflow"; q[0] = guy1; q[1] = guy2; greet(guy1); greet(guy2); // cout q[0]. I want to see first_name or last_name here! } My Emacs configuration: ;;; This was installed by package-install.el. ;;; This provides support for the package system and ;;; interfacing with ELPA, the package archive. ;;; Move this code earlier if you want to reference ;;; packages in your .emacs. (when (load (expand-file-name "~/.emacs.d/elpa/package.el")) (package-initialize)) (load-file "~/.emacs.d/cedet/common/cedet.el") (semantic-load-enable-excessive-code-helpers) (require 'semantic-ia) (global-srecode-minor-mode 1) (semantic-add-system-include "/gcc/include/c++/4.4.2" 'c++-mode) (semantic-add-system-include "/gcc/i386-pc-mingw32/include" 'c++-mode) (semantic-add-system-include "/gcc/include" 'c++-mode) (defun my-semantic-hook () (imenu-add-to-menubar "TAGS")) (add-hook 'semantic-init-hooks 'my-semantic-hook)

    Read the article

  • Processing velocity-vectors during collision as neatly as possible

    - by DevEight
    Hello. I'm trying to create a good way to handle all possible collisions between two objects. Typically one will be moving and hitting the other, and should then "bounce" away. What I've done so far (I'm creating a typical game where you have a board and bounce a ball at bricks) is to check if the rectangles intersect and if they do, invert the Y-velocity. This is a really ugly and temporary solution that won't work in the long haul and since this is kind of processing is very common in games I'd really like to find a great way of doing this for future projects aswell. Any links or helpful info is appreciated. Below is what my collision-handling function looks like right now. protected void collision() { #region Boundaries if (bal.position.X + bal.velocity.X >= viewportRect.Width || bal.position.X + bal.velocity.X <= 0) { bal.velocity.X *= -1; } if (bal.position.Y + bal.velocity.Y <= 0) { bal.velocity.Y *= -1; } #endregion bal.rect = new Rectangle((int)bal.position.X+(int)bal.velocity.X-bal.sprite.Width/2, (int)bal.position.Y-bal.sprite.Height/2+(int)bal.velocity.Y, bal.sprite.Width, bal.sprite.Height); player.rect = new Rectangle((int)player.position.X-player.sprite.Width/2, (int)player.position.Y-player.sprite.Height/2, player.sprite.Width, player.sprite.Height); if (bal.rect.Intersects(player.rect)) { bal.position.Y = player.position.Y - player.sprite.Height / 2 - bal.sprite.Height / 2; if (player.position.X != player.prevPos.X) { bal.velocity.X -= (player.prevPos.X - player.position.X) / 2; } bal.velocity.Y *= -1; } foreach (Brick b in brickArray.list) { b.rect.X = Convert.ToInt32(b.position.X-b.sprite.Width/2); b.rect.Y = Convert.ToInt32(b.position.Y-b.sprite.Height/2); if (bal.rect.Intersects(b.rect)) { b.recieveHit(); bal.velocity.Y *= -1; } } brickArray.removeDead(); }

    Read the article

  • Sharing same vector control between different places

    - by Alexander K
    Hi everyone, I'm trying to implement the following: I have an Items Manager, that has an Item class inside. Item class can store two possible visual representations of it - BitmapImage(bitmap) and UserControl(vector). Then later, in the game, I need to share the same image or vector control between all possible places it takes place. For example, consider 10 trees on the map, and all point to the same vector control. Or in some cases this can be bitmap image source. So, the problem is that BitmapImage source can be easily shared in the application by multiple UIElements. However, when I try to share vector control, it fails, and says Child Element is already a Child element of another control. I want to know how to organize this in the best way. For example replace UserControl with other type of control, or storage, however I need to be sure it supports Storyboard animations inside. The code looks like this: if (bi.item.BitmapSource != null) { Image previewImage = new Image(); previewImage.Source = bi.item.BitmapSource; itemPane.ItemPreviewCanvas.Children.Add(previewImage); } else if (bi.item.VectorSource != null) { UserControl previewControl = bi.item.VectorSource; itemPane.ItemPreviewCanvas.Children.Add(previewControl); } Thanks in advance

    Read the article

  • STL vectors with uninitialized storage?

    - by Jim Hunziker
    I'm writing an inner loop that needs to place structs in contiguous storage. I don't know how many of these structs there will be ahead of time. My problem is that STL's vector initializes its values to 0, so no matter what I do, I incur the cost of the initialization plus the cost of setting the struct's members to their values. Is there any way to prevent the initialization, or is there an STL-like container out there with resizeable contiguous storage and uninitialized elements? (I'm certain that this part of the code needs to be optimized, and I'm certain that the initialization is a significant cost.) Also, see my comments below for a clarification about when the initialization occurs. SOME CODE: void GetsCalledALot(int* data1, int* data2, int count) { int mvSize = memberVector.size() memberVector.resize(mvSize + count); // causes 0-initialization for (int i = 0; i < count; ++i) { memberVector[mvSize + i].d1 = data1[i]; memberVector[mvSize + i].d2 = data2[i]; } }

    Read the article

  • J2me - Arrays vs vector ?

    - by Galaxy
    if we have to implementations of string split for j2me, one returns vector and the other returns array , in terms of performance on hand held devices which one is the best choice ?

    Read the article

  • Using an initializer_list on a map of vectors

    - by Hooked
    I've been trying to initialize a map of <ints, vector<ints> > using the new 0X standard, but I cannot seem to get the syntax correct. I'd like to make a map with a single entry with key:value = 1:<3,4 #include <initializer_list> #include <map> #include <vector> using namespace std; map<int, vector<int> > A = {1,{3,4}}; .... It dies with the following error using gcc 4.4.3: error: no matching function for call to std::map<int,std::vector<int,std::allocator<int> >,std::less<int>,std::allocator<std::pair<const int,std::vector<int,std::allocator<int> > > > >::map(<brace-enclosed initializer list>) Edit Following the suggestion by Cogwheel and adding the extra brace it now compiles with a warning that can be gotten rid of using the -fno-deduce-init-list flag. Is there any danger in doing so?

    Read the article

  • Are vector assignments copied by value or by reference in Google's Go language?

    - by Brian T Hannan
    In the following code, I create one peg puzzle then do a move on it which adds a move to its movesAlreadyDone vector. Then I create another peg puzzle then do a move on it which adds a move to its movesAlreadyDone vector. When I print out the values in that vector for the second one, it has the move in it from the first one along with the move from the second one. Can anyone tell me why it seems to be assigning by reference and not value? Are vector assignments copied by value or by reference in Google's Go language? package main import "fmt" import "container/vector" type Move struct { x0, y0, x1, y1 int } type PegPuzzle struct { movesAlreadyDone * vector.Vector; } func (p *PegPuzzle) InitPegPuzzle(){ p.movesAlreadyDone = vector.New(0); } func NewChildPegPuzzle(parent *PegPuzzle) *PegPuzzle{ retVal := new(PegPuzzle); retVal.movesAlreadyDone = parent.movesAlreadyDone; return retVal } func (p *PegPuzzle) doMove(move Move){ p.movesAlreadyDone.Push(move); } func (p *PegPuzzle) printPuzzleInfo(){ fmt.Printf("-----------START----------------------\n"); fmt.Printf("moves already done: %v\n", p.movesAlreadyDone); fmt.Printf("------------END-----------------------\n"); } func main() { p := new(PegPuzzle); cp1 := new(PegPuzzle); cp2 := new(PegPuzzle); p.InitPegPuzzle(); cp1 = NewChildPegPuzzle(p); cp1.doMove(Move{1,1,2,3}); cp1.printPuzzleInfo(); cp2 = NewChildPegPuzzle(p); cp2.doMove(Move{3,2,5,1}); cp2.printPuzzleInfo(); } Any help will be greatly appreciated. Thanks!

    Read the article

  • push_back private vectors with 2 methods, one isn't working

    - by jmclem
    I have a class with a private vector of doubles. To access or modify these values, at first I used methods such as void classA::pushVector(double i) { this->vector.push_back(i); } double classA::getVector(int i) { return vector[i]; } This worked for a while until I found I would have to overload a lot of operators for what I needed, so I tried to change it to get and set the vector directly instead of the values, i.e. void classA::setVector(vector<double> vector) { this->vector = vector; } vector<double> classA::getVector() { return vector; } Now, say there is a classB, which has a private classA element, which also has get and set methods to read and write. The problem was when I tried to push back a value to the end vector in classA. void classB::setFirstValue(double first) { this->getClassA().getVector().push_back(first); } This does absolutely nothing to the vector. It remains unchanged and I can't figure out why... Any ideas?

    Read the article

  • Quaternion Cameras and projectile vectors

    - by Tom J Nowell
    In our software we have a camera based on mouse movement, and a quarternion at its heart. We want to fire projectiles from this position, which we can do, however we want to use the camera to aim. The projectile takes a vector which it will add to its position each game frame. How do we acquire such a vector from a given camera/quaternion?

    Read the article

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