LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default Circle equation in VB

Hi,
This is a VB question.
I created a matrix(or table)using certain dimensions from user.
diameter, xindex(cell height), yindex(cell width).
(diameter/xindex) gives me the number of cells in xaxis,
(diameter/yindex) gives me the number of cells in yaxis

Then I try to color cells that would fit in a circle.
The following equation works when xindex and yindex are equal.
When Xindex and Yindex are different I keep getting an ellipse shape.
The reason is that this circle equation assigns the same number of cells for
xaxis and yaxis and since the height and width are not same I get an ellipse.
This is the code I use.

Dim m As Long, n As Long
For m = 0 To rw - 1 ' rw is number of rows
For n = 0 To cl - 1 ' cl is number of columns

d = Sqr(((m - (rw / 2)) ^ 2) + ((n - (cl / 2)) ^ 2))
If d < (radiusInCells) Then
grille1.row = m ' row location
grille1.col = n ' col location
grille1.CellBackColor = vbRed ' color cell
End If
Next n
Next m

I got a solution from K. dales that worked for excel (excel uses points or
pixels for dimensions:
AspectRatio = Cells(1, 1).Width / Cells(1, 1).Height
For i = 1 To 900
For j = 1 To 250
d = Sqr((i - 100) ^ 2 + (j - 65) ^ 2)
If d < 60 Then
Cells(i, Int(j / AspectRatio)).Interior.ColorIndex = 45


I tried using this AspectRation variable in my code but did not work:
AspectRatio= xindex(cell height)/yindex(cell width).
Then used it as follows:

Dim m As Long, n As Long
For m = 0 To rw - 1 ' rw is number of rows
For n = 0 To cl - 1 ' cl is number of columns

d = Sqr(((m - (rw / 2)) ^ 2) + ((n - (cl / 2)) ^ 2))
If d < (RadiusIncells) Then
grille1.row = m ' row location
grille1.col = (Int(n / AspectRatio)) 'Col location
grille1.CellBackColor = vbRed ' color cell
End If
Next n
Next m

Any input on this is greatly appreciated

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Green Circle Art Excel Discussion (Misc queries) 1 August 27th 09 02:37 AM
How do I make circle within circle graphs in Excel 2003? Lance Charts and Charting in Excel 2 December 5th 06 01:59 AM
VALUE WITH A CIRCLE teakwood Excel Discussion (Misc queries) 2 September 11th 06 05:39 PM
How do I set up a circle within a circle chart? Ken Charts and Charting in Excel 3 August 4th 06 12:39 PM
Equation Editor- problem when editing an equation Gaby L. Excel Discussion (Misc queries) 0 September 27th 05 09:24 PM


All times are GMT +1. The time now is 07:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"