Announcement

Collapse
No announcement yet.

A question for you mathematicians out there (geometry I guess).

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • A question for you mathematicians out there (geometry I guess).

    I need to check for mouse click on rectangular areas that are not
    horizontal e.g. it may be an area 200 pixels long, 10 pixels wide but
    at an angle of 0, 15, 30, 45, 60, 75 or 90 degrees to the horizontal.

    The package I'm using has a 'PointinRect' function but it assumes
    a horizontal rectangular area.

    I am going to have to hand-code the test, so if anyone has an
    example they are willing to share I'd be very grateful.


    TIA

    T.
    FT.

  • #2
    You would have to subtend within your angular rectangle a number of smaller transparent rectangles, each coded similarly. The more small rectangles you have, the more closely your outline would be simulated - and the more work it will be!
    Brian (the devil incarnate)

    Comment


    • #3
      You can accomplish this with an image map.

      I'm not sure what server platform you are using.

      If you are using .Net 1.1 there's a third party image map control that has a nice design-time map editor you can play with. Here's a link: http://www.ewoodruff.us/EWSImageMaps.aspx

      Here's a screenshot of the polygon editor:


      .Net 2.0 has a built in image map control but it doesn't come with a design time editor so you have to specify the polygon regions via code manually.

      If you're using Classic ASP or PHP, Ruby, etc., I can't give you any advice other than to research what options are available for image maps.
      Last edited by schmosef; 3 October 2006, 05:49.
      P.S. You've been Spanked!

      Comment


      • #4
        Originally posted by Brian Ellis
        You would have to subtend within your angular rectangle a number of smaller transparent rectangles, each coded similarly. The more small rectangles you have, the more closely your outline would be simulated - and the more work it will be!
        Reminds me of my intro to calculus classes.
        P.S. You've been Spanked!

        Comment


        • #5
          Parfaitement!
          Brian (the devil incarnate)

          Comment


          • #6
            Can't you just instruct the user to tilt the screen somewhat?
            Join MURCs Distributed Computing effort for Rosetta@Home and help fight Alzheimers, Cancer, Mad Cow disease and rising oil prices.
            [...]the pervading principle and abiding test of good breeding is the requirement of a substantial and patent waste of time. - Veblen

            Comment


            • #7
              @Unf, LOL

              I should have said that I'm looking for VB-like code to run on standalone machines. Sorry, I was in a hurry. I will have the location of the mouseclick (x,y) and will know the locations of the corner points of the rectangles. The question is to determine if the click is within the perimeter of the rectangle.

              If there isn't an easy/ready-made solution I can simply go with labels and scanning the keyboard.
              FT.

              Comment


              • #8
                Although I do not know any VB, I think there is a reasonable solution.

                Ok, so I stole this idea from the guy who wanted to simply turn the monitor...

                It seems that the easiest thing to do is rotate the rectangle coordinates and the click coordinates back to a strictly vertical/horizontal rectangle.

                Keep the bottom left corner of your rotated rectangle. Call its coordinates xbl, ybl. (x bottom left and y bottom left)
                Rotate the other vertices of the box back as follows:

                Let xtr_old be the x coordinate of the top right vertex of the rotated rectangle
                Let xtr_new be the x coordinate of the top right vertex of the rotation corrected rectangle

                Let theta be the angle by which the rectangle has been rotated.

                xtr_new=(xtr_old-xbl)cos(theta) + (ytr_old-ybl)sin(theta)

                xtr_new=(ytr_old-ybl)cos(theta) - (xtr_old-xbl)sin(theta)

                You can do these same operations for the other 2 vertices, but to specify your new rectangle all you need is bottom left and top right coordinates)

                You now have a strictly vertical/horizontal rectangle.

                When a click has occured, take the coordinates of the click and rotate those by doing the following.

                x_click_corrected=(x_click_old-xbl)cos(theta) + (y_click_old-ybl)sin(theta)
                y_click_corrected=(y_click_old-ybl)cos(theta) - (x_click_old-xbl)sin(theta)

                Now you can use the 'PointinRect' function passing it the new rectangle coordinates and the new mouse click coordinates.


                I hope this helps...
                Just a month left of grad school!

                Comment


                • #9
                  That certainly does help Many thanks.

                  The target rectangles will always be fixed. All I need to do is transform the click-point by the relevant number of degrees and test against a horizontal rectangle. Brilliant.

                  Thanks again.
                  FT.

                  Comment

                  Working...
                  X