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 6913767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:15:34+00:00 2026-05-27T09:15:34+00:00

In the accepted answer of question Mathematica and MouseListener – developing interactive graphics with

  • 0

In the accepted answer of question ” Mathematica and MouseListener – developing interactive graphics with Mma ” Sjoerd C de Vries demonstrates that it is possible to select an object in a 3D graphic and change its color.

I would like to know if it is possible (in a similar fashion as above) in a Graphics3D with two or more objects (e.g. two cuboids) to select one and change its coordinates (by moving or otherwise)?

  • 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-27T09:15:35+00:00Added an answer on May 27, 2026 at 9:15 am

    I’m partly reusing Sjoerd’s code here, but maybe something like this

    DynamicModule[{pos10, pos11 = {0, 0, 0}, 
      pos12 = {0, 0, 0}, pos20, pos21 = {0, 0, 0}, pos22 = {0, 0, 0}}, 
     Graphics3D[{EventHandler[
        Dynamic[{Translate[Cuboid[], pos11]}, ImageSize -> Tiny], 
       {"MouseDown" :> (pos10 = Mean@MousePosition["Graphics3DBoxIntercepts"]),
        "MouseDragged" :> (pos11 = 
          pos12 + Mean@MousePosition["Graphics3DBoxIntercepts"] - pos10),
        "MouseUp" :> (pos12 = pos11)}], 
      EventHandler[
       Dynamic[{Translate[Cuboid[{1, 1, 1}], pos21]}, ImageSize -> Tiny], 
       {"MouseDown" :> (pos20 = Mean@MousePosition["Graphics3DBoxIntercepts"]),
        "MouseDragged" :> (pos21 = 
           pos22 + Mean@MousePosition["Graphics3DBoxIntercepts"] - pos20),
        "MouseUp" :> (pos22 = pos21)}]},
      PlotRange -> {{-3, 3}, {-3, 3}, {-3, 3}}]]
    

    Note that this just moves the cuboids in a plane so you would have to rotate the bounding box to move them perpendicular to that plane, but it shouldn’t be too hard to introduce a third dimensions by adding modifier keys.


    Edit

    Thanks for the comments. Here’s an updated version of the code above. In this version the cubes jump back to within the bounding box if they happen to move outside so that should solve the problem of the disappearing cubes.

    DynamicModule[{init, cube, bb, restrict, generate},
     init = {{0, 0, 0}, {2, 1, 0}};
     bb = {{-3, 3}, {-3, 3}, {-3, 3}};
     cube[pt_, scale_] := 
      Translate[Scale[Cuboid[{-1/2, -1/2, -1/2}, {1/2, 1/2, 1/2}], scale], pt];
     restrict[pt_] := MapThread[Min[Max[#1[[1]], #2], #1[[2]]] &, {bb, pt}];
     generate[pos_, scale_] := Module[{mp, pos0, pos1, pos2},
       mp := MousePosition["Graphics3DBoxIntercepts"];
       pos1 = pos;
       EventHandler[
        Dynamic[{cube[pos1, scale]}, ImageSize -> Tiny], 
        {"MouseDown" :> (pos0 = LeastSquares[Transpose[mp], pos1].mp), 
         "MouseDragged" :> 
           ((pos1 = #[[2]] + Projection[pos0 - #[[2]], #[[1]] - #[[2]]]) &@mp),
         "MouseUp" :> (pos1 = restrict[pos1])}]];
    
     Graphics3D[generate[#, 1] & /@ init, PlotRange -> bb, PlotRangePadding -> .5]
    ]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question , has an accepted answer that only redirects the out command to
The accepted answer to the question C++ Library for image recognition: images containing words
Based the accepted answer to this question I've setup a NetBeans/tomcat environment. In testing
In another question, the accepted answer shows a method for reading the contents of
In another question , the accepted answer suggested replacing a (very cheap) if statement
I was reading over this question and wondered if the accepted answer might also
This is basically a duplicate of this question , but the accepted answer was
In light of the accepted answer pointing out that returning a non-const reference to
While I was reading the accepted answer of this question , I had the
This is specifically related to the accepted answer of another question I asked .

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.