Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TRect and diamonds

Status
Not open for further replies.

cyprus106

Programmer
Apr 30, 2001
654
0
0
I know how you would create a rectangle - through TRect, but how would I create a Diamond shape?

Basically what I'm trying to create is a large gridmap out of many smaller tiles, (The diamonds).

My first problem is that I truly need to create the diamond(s), not just paint a picture with lost of pretty diaminds in it that does nothing. I need to actually make a diamond, not a picture inside of a straight rectangle.
My second problem is that I have no idea how to do it. Does anybody else? Cyprus
 
Hi,
from your mail i understood that you wanted to tile a form (or other) with rectangles and diomonds in them. My first oponion that if you want an object oriented approach, use the VCL TSHAPE (rectangle) and TSHAPE->Brush->Bitmap property to load picture or second to draw diamonds by using TSHAPE->Brush->Bitmap->Canvas property.
Goodby!
 
That would work, but I have some problems with the methods that you described.

Loading a bitmap onto the TShape would change it's apperance, but then I would still not be able to tell when an object is within the rectangle or not, like finding out if something is past the Shape->Left. I need to make an actual diamond, not change it's apperance. I need to know when somethings within it's borders, outside, etc. putting a bitmap inside of a shape would not accomplish that. I need a grid that I can tell the boundries of it's individual squares that make it up. right now I'm just concentrating on making that diamond.

does anyone[/] know any way that's not just a work around of the problem?? Cyprus
 
Greetinx!

You can create your own class like TRect, for example named TDiamond. When you can define methods for the class and add method named OnTarget(TPoint point) in which you will verify point coordinates targetted or not to diamond.
The diamond can be determinated with 4 points which either defines its apex or rectangle boundary coordinates for the diamond.
For example: you have 4 coords of diamond apex: Left, Top, Right, Bottom.
In order to point on target to diamond, the 4 condition must be satisfied:
1) y-(((Top.y-Left.y)/(Top.x-Left.x))*x + Left.x)<=0
2) y-(((Right.y-Top.y)/(Right.x-Top.x))*x + Right.x)<=0
3) y-(((Bottom.y-Right.y)/(Bottom.x-Right.x))*x + Right.x)>=0
4) y-(((Left.y-Bottom.y)/(Left.x-Bottom.x))*x + Left.x)>=0
where x,y - coords of point

NOTE:You should test the conditions for their accuracy.
Happy programming!))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top