Click here to Skip to main content
16,018,904 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Snooker Game programing using c Programing. Pin
Daniel Pfeffer4-Apr-23 7:40
professionalDaniel Pfeffer4-Apr-23 7:40 
SuggestionMessage Closed Pin
29-Mar-23 15:32
Member 1496877129-Mar-23 15:32 
GeneralRe: Socket or file descriptor ? Pin
k505429-Mar-23 17:18
mvek505429-Mar-23 17:18 
GeneralRe: Socket or file descriptor ? Pin
Richard MacCutchan29-Mar-23 21:38
mveRichard MacCutchan29-Mar-23 21:38 
GeneralRe: Socket or file descriptor ? Pin
jschell30-Mar-23 5:45
jschell30-Mar-23 5:45 
GeneralMessage Closed Pin
30-Mar-23 6:28
Member 1496877130-Mar-23 6:28 
GeneralRe: Socket or file descriptor - more questions ? Pin
k505430-Mar-23 9:31
mvek505430-Mar-23 9:31 
QuestionFind X,Y index into 2D array/matrix using an angle and number of cells Pin
imk12326-Mar-23 7:37
imk12326-Mar-23 7:37 
Hello,
I am working on a robots projects and part of this project is a local map space (2D array/matrix).
This map consists of 201 x 201 1cm squares, with the robot sitting in the middle.
From a robots point of view this local map has a index range of -100x -100y to +100x +100y
With the robot sitting at cell 0,0, obviously from a c/c++ point of view.
The array/matrix is addressed from 0x to 200x and 0y to 200y. (0x,0y being array/matrix bottom left)
I have successfully implement a robot rolling road and robot array/matrix rotations.
However, for some reason my brain has gone into gimble lock.
Trying to figure how to find the array/matrix x,y indices for a number of cells at a given angle from the middle of the map (robots position).
The code below produces perfect result for 100 cells at 0,45,90,135,180,225,270,315 degrees but at other angle is fails, can someone help please.
Many thanks in advance imk

#define LOCAL_MAP_NUM_X_CELLS 201
#define LOCAL_MAP_NUM_Y_CELLS 201
#define DEG_TO_RAD 0.0174533

struct LocalMap
{
unsigned char Cell[ LOCAL_MAP_NUM_Y_CELLS ][ LOCAL_MAP_NUM_X_CELLS ];
}; typedef struct LocalMap LocalMap;

int Cell_X;
int Cell_Y;

ComputeLocalMapCellIntexFromCentre( 315 , 100 , &Cell_X , &Cell_Y );

int ComputeLocalMapCellIntexFromCentre( double Angle , int NumberCells , int *pCell_X , int *pCell_Y )
{
double AngleAdjustMent;
double Sin = sin( Angle * DEG_TO_RAD);
double Cos = cos( Angle * DEG_TO_RAD);
double NumCells;

AngleAdjustMent = ( fabs( sin( Angle * DEG_TO_RAD)) + fabs( cos( Angle * DEG_TO_RAD )) );

NumCells = (double)NumberCells;
NumCells = round( (double)NumCells * AngleAdjustMent );

NumberCells = (int)NumCells;

*pCell_X = (int)round( Sin * NumberCells ) + ( LOCAL_MAP_NUM_X_CELLS - 1 ) / 2;
*pCell_Y = (int)round( Cos * NumberCells ) + ( LOCAL_MAP_NUM_Y_CELLS - 1 ) / 2;

return( TRUE );
}

modified 26-Mar-23 13:43pm.

AnswerRe: Find X,Y index into 2D array/matrix using an angle and number of cells Pin
Mircea Neacsu26-Mar-23 8:04
Mircea Neacsu26-Mar-23 8:04 
AnswerRe: Find X,Y index into 2D array/matrix using an angle and number of cells Pin
Gerry Schmitz26-Mar-23 8:50
mveGerry Schmitz26-Mar-23 8:50 
QuestionWhat is the difference in C and C++ in terms of memory management ? Pin
Gulshan Negi20-Mar-23 22:57
professionalGulshan Negi20-Mar-23 22:57 
GeneralRe: What is the difference in C and C++ in terms of memory management ? Pin
Richard MacCutchan21-Mar-23 2:11
mveRichard MacCutchan21-Mar-23 2:11 
AnswerRe: What is the difference in C and C++ in terms of memory management ? Pin
jschell21-Mar-23 5:41
jschell21-Mar-23 5:41 
QuestionC language Pin
Pavani M18-Mar-23 5:24
Pavani M18-Mar-23 5:24 
AnswerRe: C language Pin
Richard MacCutchan18-Mar-23 6:53
mveRichard MacCutchan18-Mar-23 6:53 
AnswerRe: C language Pin
CPallini19-Mar-23 22:33
mveCPallini19-Mar-23 22:33 
QuestionMessage Closed Pin
5-Mar-23 5:33
Member 149687715-Mar-23 5:33 
AnswerRe: Reorganizing code Pin
Richard MacCutchan5-Mar-23 21:56
mveRichard MacCutchan5-Mar-23 21:56 
QuestionMessage Closed Pin
3-Mar-23 5:42
Member 149687713-Mar-23 5:42 
AnswerRe: How to implement variable amount of parameters? Pin
Mircea Neacsu3-Mar-23 6:10
Mircea Neacsu3-Mar-23 6:10 
AnswerRe: How to implement variable amount of parameters? Pin
k50543-Mar-23 6:18
mvek50543-Mar-23 6:18 
AnswerRe: How to implement variable amount of parameters? Pin
Richard MacCutchan3-Mar-23 21:57
mveRichard MacCutchan3-Mar-23 21:57 
AnswerRe: How to implement variable amount of parameters? Pin
jschell6-Mar-23 6:20
jschell6-Mar-23 6:20 
GeneralRe: How to implement variable amount of parameters? Pin
charlieg19-Mar-23 11:47
charlieg19-Mar-23 11:47 
QuestionC++ non-null pointers Pin
Mircea Neacsu2-Mar-23 7:47
Mircea Neacsu2-Mar-23 7:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.