Creating polyline offsets

Creating polyline offsets

Anonymous
Not applicable
1,173 Views
2 Replies
Message 1 of 3

Creating polyline offsets

Anonymous
Not applicable

 

I trying to create a function that will take a polyline and apply an offset to it with the condition that the offset is always on the outside of the polyline. The problem I am having is that sometimes the offset is inside the polyline not outside and I cant seem to figure out why. The API docs say that a negative offset would indicate to most objects that the curve should be inside so i would guess that a positive offset would indicate that the curve should be outside. My code is below.

 

bool createPolylineOffset( AcDbPolyline *polyline, double offset, ACHAR *offsetLayer  )
{
	Acad::ErrorStatus errorStatus;
	AcDbObjectId ownerId;
	AcDbVoidPtrArray offsetPolylinePoints;
	AcDbPolyline *offsetPolyline;


	//Make sure that we are drawing our offset on the outside of the selected polyline
	offset = abs( offset );
	ownerId = polyline->ownerId();
	errorStatus = polyline->getOffsetCurves( offset, offsetPolylinePoints );


	if( errorStatus != Acad::eOk )
	{
		acutPrintf( L"\nError: Could not offset points %s", acadErrorStatusText( errorStatus ) );
		return false;
	}
	if( offsetPolylinePoints.length() != 1 )
	{
		acutPrintf( L"\nError: Could not get offset points" );
		deleteArray( offsetPolylinePoints );
		return false;
	}

	offsetPolyline = (AcDbPolyline*)(offsetPolylinePoints[0]);
	offsetPolyline->setLayer(offsetLayer);

    appendEntity(offsetPolyline, ownerId);
	
	offsetPolyline->close();
	return true;
}
0 Likes
Accepted solutions (1)
1,174 Views
2 Replies
Replies (2)
Message 2 of 3

Alexander.Rivilis
Mentor
Mentor
Accepted solution

Simplest way is getting two polyline:

 

 

polyline->getOffsetCurves( +offset, offsetPolylinePoints1);
polyline->getOffsetCurves( -offset, offsetPolylinePoints2);

 

double area1 = 0; offsetPolylinePoints1[0].getArea(area1);
double area2 = 0; offsetPolylinePoints2[0].getArea(area2);

if area1 > area2 then offsetPolylinePoints1[0] is a outside polyline.

 

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 3 of 3

Anonymous
Not applicable

Thank you for your help that makes a lot of sense.

0 Likes