Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7089135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:53:06+00:00 2026-05-28T07:53:06+00:00

I have been having some trouble reversing my vectors in my game when a

  • 0

I have been having some trouble reversing my vectors in my game when a collision occurs what I need to do is flip the value to the inverse of the current value each time a marble hits an object. The vectors are directions that I need to reverse to make the bounce of look realistic.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:53:07+00:00Added an answer on May 28, 2026 at 7:53 am

    So what you’re talking about is a vector in the mathematical sense, rather than the container. Let’s still assume that you’ve implemented it with an std::vector<fieldT> where e.g. typedef double fieldT. You seem to want to have the direction reflected by some obstacle. It’s easy when the “mirror” lies in direction of one of your basis vector, then you only need to negate that component – a “mirror” in the xy-plane (in 3D) would do

    v[2] = -v[2];
    

    i.e. flip the z-component, in the yz-plane it would be

    v[0] = -v[0];
    

    It gets more complicated if the reflections occur in arbitrary direction. One possibility is to determine the speed component in direction of the plane – that’s done by calculating the scalar product between the speed vector and the normal vector of the plane – and then substracting twice the normal vector, weighted with that factor.

    std::vector<fieldT> n   // normal vector of the plane
                      , v   // speed vector
                      ;
    
    fieldT eta=0;
    for (unsigned i=0; i<n.size(); ++i)     //scalar product between v and n
      eta += v[i]*n[i];
    for (unsigned i=0; i<n.size(); ++i)     //substract twice the weighted normal vector
      v[i] -= 2*eta*n[i];
    

    A more general approach would be modelling the reflection by matrix application: a reflection is essentially application of an orthogonal linear mapping.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been having some real trouble with this for a while. I am
I have been having some trouble finding a good way to output just the
I'm having some trouble extending Classes in PHP. Have been Googling for a while.
I have been having some trouble with matplotlib since I started using python. When
I have been having some trouble loading the CheckBoxList with data. I have been
I've been having some trouble with a guessing game that populates an array with
I have been having some trouble figuring out how exactly I get a process's
I am having some trouble highlighting checkboxes and radio buttons that have been selected.
I have been having some trouble getting the following to work: <IfModule mod_rewrite.c> DirectoryIndex
I have been having some trouble to select the rows of my table which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.