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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:09:53+00:00 2026-06-08T12:09:53+00:00

I am attempting to test for a collision with a Rectangle2D.Float and a Point2D.Float.

  • 0

I am attempting to test for a collision with a Rectangle2D.Float and a Point2D.Float. I have a 2D world that contains a camera (which transforms the graphics2D canvas based off the camera’s AffineTransform). I then have a list of objects X that contain sub-objects Y. The canvas is transformed ontop of the camera’s transformation to X’s AffineTransformation, so the object is rendered in the correct location. I can successfully test for a collision with the mouse inside Object X, but I am having issues testing for the sub objects Y because the Y objects “think” they are at position (0,0) even though they have been located elsewhere because of their parent object X who was repositioned to say (200,200). So in other words, Object X and Y show up at position (200,200), but the collision happens at (0,0) and not at (200,200) like it is supposed to.

I believe it has to do with the right combination of calling AffineTransform.transform and AffineTransform.inverseTransform, but I cannot wrap my brain around the correct combintation.

  • 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-06-08T12:09:55+00:00Added an answer on June 8, 2026 at 12:09 pm

    This is a standard problem that arises when using concatenated transformations for interactive graphics.

    Let’s say T is the affine transformation matrix that positions an object X. Also let U be the matrix positioning some subobject Y with respect to X. Then each point p in Y is being transformed with the matrix expression

    p' = T U p
    

    where p' is the transformed point. The coordinate space where p' lives is the same as mouse coordinates. When you receive a mouse click at point c' (I’m using the prime ' here to match p' in the same coordinates), you have a choice. You can either transform c' “backward” using (T U)^(-1) to get c in the coordinate space of the subobject. Or you can manually calculate p' for all points p so you can compare it with c'.

    In general you will want to do the latter. The Java will be something like:

    AffineTransform TU = new AffineTransform(T);
    TU.concatenate(U);
    Point2D pPrime = new Point2D();
    TU.transform(p, pPrime);
    

    Now you will quickly notice that since you are manually calculating these points, you might keep a data structure of the transformed points around so you can always compare with mouse coordinates. The same data structure can be used for painting the screen with no transformations at all: they have already been applied. This is a pretty standard technique for interactive graphics. When the whole drawing is being updated rapidly, it loses its appeal. But when the drawing is large and at most small pieces are being updated at a time, it can be a big win for performance. You give some memory and get back some speed.

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

Sidebar

Related Questions

I'm attempting to test a Flex application in which Objects do not have static
I'm attempting to test that my service is calling Anemone.crawl correctly. I have the
I'm attempting to test interactions with a Nexus server that requires authentication for the
Attempting to build a C# NPAPI plugin I have found a tutorial which describes
I am attempting to test the monger mongodb driver for clojure (which is essentially
I'm attempting to unit test some code using NUnit. I have a method: public
I am attempting to test some code that uses Request.Item(key) but I can not
I want to be able to test some inner functions that I have without
I'm attempting to test a website I have running in a local IISExpress instance
I'm attempting to test links that should/shouldn't be seen when logged in, but RSpec

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.