?
Solved

Visual Basic + API - Need help with the Incircle in a Triangle..  Create a Triangle with an Incircle. (Ellipse)

Posted on 2006-04-27
3
Medium Priority
?
252 Views
Last Modified: 2013-12-26
Need help placing the incircle.

Have coded the triangle, and the circle code, need help finding the points xleft,ytop,xright,ybottom, for the circle, so it fit perfect inside the triangle. (Incircle)

This is the code:

Option Explicit

Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As POINTAPI, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function FillRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long, ByVal hBrush As Long) As Long
Private Declare Function Polyline Lib "gdi32" (ByVal hdc As Long, lpPoint As POINTAPI, ByVal nCount As Long) As Long
Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, lpPoint As POINTAPI) As Long
Private Declare Function CreatePen Lib "gdi32" (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long

Private Declare Function Ellipse Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long


Private Type POINTAPI
   X As Long
   Y As Long
End Type

Private Sub UserControl_Initialize()

End Sub

Private Sub UserControl_Paint()


Dim hBrush As Long
Dim hRgn As Long
Dim hPen As Long
Dim OldPen As Long
Dim xleft As Long
Dim ytop As Long
Dim xright As Long
Dim ybottom As Long
 

Dim point(3) As POINTAPI

'Define all our X,Y coords.

point(0).X = 0
point(0).Y = UserControl.ScaleHeight - 1
point(1).X = UserControl.ScaleWidth - 1
point(1).Y = UserControl.ScaleHeight - 1
point(2).X = (UserControl.ScaleWidth - 1) / 2
point(2).Y = 0
point(3).X = point(0).X
point(3).Y = point(0).Y


'Use this to fill it with color

'hBrush = CreateSolidBrush(vbBlack)
'hRgn = CreatePolygonRgn(point(0), 3, 2)

'Call FillRgn(UserControl.hdc, hRgn, hBrush)
'Call DeleteObject(hRgn)
'Call DeleteObject(hBrush)

hPen = CreatePen(0, 2, vbBlack)
OldPen = SelectObject(UserControl.hdc, hPen)

'NEED HELP HERE!

xleft = ??
ytop = ??
xright = ??
ybottom = ??


hRgn = Ellipse(UserControl.hdc, xleft, ytop, xright, ybottom)

Call Polyline(UserControl.hdc, point(0), 4)
Call DeleteObject(hPen)
Call SelectObject(UserControl.hdc, OldPen)
 
 End Sub



Hope someone can help me.

Thanks
0
Comment
Question by:sudji
  • 2
3 Comments
 
LVL 28

Accepted Solution

by:
Ark earned 2000 total points
ID: 16570789
Homework? :-)

'NEED HELP HERE!
Dim s As Single, p As Single, r As Single, a As Single
a = Sqr(point(0).Y ^ 2 + point(2).X ^ 2)
p = a + a + point(1).X
s = point(1).Y * point(2).X
r = 2 * s / p
xleft = point(2).X - r
ytop = point(0).Y - r * 2
xright = point(2).X + r
ybottom = point(0).Y
0
 

Author Comment

by:sudji
ID: 16572448
Thansk! :)
0
 

Author Comment

by:sudji
ID: 16572451
Thanks even! :)

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month14 days, 7 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question