Corner of a rotated rectangle

Blitz3D Forums/Blitz3D Programming/Corner of a rotated rectangle

LedgerARC(Posted 2009) [#1]
I'm working with 3D images, and I need to know the X and Y coordinates on-screen of the corner of the rotated image. I know the drawing position of the image in pixels, and the width and height of the image in pixels. Any body know?
Thanks, Floppyracer.


Zethrax(Posted 2009) [#2]
If you need to map a point from 3D space into 2D screen space, then take a look at the CameraProject command ( http://www.blitzbasic.com/b3ddocs/command.php?name=CameraProject&ref=3d_cat ).

If not, then you'll need to explain what you're trying to do a bit better.

EDIT: The CameraProject command returns zero if the point is outside the graphics buffer area, so it may not be possible to use it for this purpose. Bit of a nuisance actually, as I needed that command for a visibility portal system I was working on.


Matty(Posted 2009) [#3]
If your images are 3d do you mean you are using a sprite or a quad?

If you are using a quad then you can use the tformpoint commands to get the position of each vertex (corner) in world space and then use the camera project command to get the actual screen x/y position of those 3d coordinates.

from Matt


Ross C(Posted 2009) [#4]
For a maths type solution, find the length of a line, from the centre of the box, to a corner, when it's not rotated. An easy bit of distance math equation.

You know half of the width and half of the height, so you know the x/y cords of the centre and any of the corners. So, get a distance, and an angle from the centre to the edge. Then, when you want to know the corner again, simply add the angle you got originally onto the angle you have rotated by. then do:

x = cos(angle)*dist
y = sin(angle)*dist

I can't remember the exact way the blitz co-ord system works, so you may need to faff about with that.