Welcome,
Guest
. Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News:
Home
Help
Login
Register
TheSwamp
»
Code Red
»
.NET
»
Topic:
Point3d X value
« previous
next »
Print
Pages: [
1
] |
Go Down
Author
Topic: Point3d X value (Read 2574 times)
0 Members and 1 Guest are viewing this topic.
shers
Guest
Point3d X value
«
on:
May 18, 2015, 12:07:03 PM »
Hi,
It is not possible to assign value to Point3d Coordinates one by one, like Point3d insPt.X = 2. Is there any other option?
Thanks
Logged
Jeff_M
King Gator
Posts: 4096
C3D user & customizer
Re: Point3d X value
«
Reply #1 on:
May 18, 2015, 12:37:35 PM »
Point3d newpt = new Point3d(2, insPt.Y, insPt.Z);
Logged
BlackBox
King Gator
Posts: 3770
Re: Point3d X value
«
Reply #2 on:
May 18, 2015, 12:43:26 PM »
Duplicate thread here:
http://forums.augi.com/showthread.php?161727-Point3d
Logged
"How we think determines what we do, and what we do determines what we get."
gile
Gator
Posts: 2507
Marseille, France
WWW
Re: Point3d X value
«
Reply #3 on:
May 18, 2015, 12:45:06 PM »
Hi,
The type Point3d, as many others .NET structures, is immutable.
You cannot edit a Point3d, you have to create a new one.
Logged
Speaking English as a French Frog
gile
Gator
Posts: 2507
Marseille, France
WWW
Re: Point3d X value
«
Reply #4 on:
May 18, 2015, 04:40:38 PM »
If you really need a mutable point to improve performances* while you make many changes to a point coordinates, you can build a little class where the point coordinates are read/write enabled.
The mutable point type may have explicit cast operators from and to the Point3d type.
Code - C#:
[Select]
using
Autodesk.AutoCAD.Geometry
;
namespace
MutablePoint
{
public
class
Point
{
public
Point
(
double
x,
double
y,
double
z
)
{
this
.
X
=
x
;
this
.
Y
=
y
;
this
.
Z
=
z
;
}
public
double
X
{
get
;
set
;
}
public
double
Y
{
get
;
set
;
}
public
double
Z
{
get
;
set
;
}
public
void
Add
(
Vector3d disp
)
{
this
.
X
+=
disp
.
X
;
this
.
Y
+=
disp
.
Y
;
this
.
Z
+=
disp
.
Z
;
}
public
static
explicit
operator
Point
(
Point3d pt
)
{
return
new
Point
(
pt
.
X
, pt
.
Y
, pt
.
Z
)
;
}
public
static
explicit
operator
Point3d
(
Point pt
)
{
return
new
Point3d
(
pt
.
X
, pt
.
Y
, pt
.
Z
)
;
}
}
}
Using:
Code - C#:
[Select]
Point pt
=
(
Point
)
Point3d
.
Origin
;
pt
.
X
=
10.0
;
pt
.
Y
=
20.0
;
Point3d p3d
=
(
Point3d
)
pt
;
// p3d = (10,20,0)
*mutable objects are more efficient with memory but immutable ones are safer ans easier to use in concurent programming.
Logged
Speaking English as a French Frog
shers
Guest
Re: Point3d X value
«
Reply #5 on:
May 19, 2015, 01:56:32 AM »
That's great! Thanks very much!
I also would like to know how to assign null value to Point3d, like
Point3d pt = null;
Thanks
«
Last Edit: May 19, 2015, 05:16:56 AM by sresh
»
Logged
gile
Gator
Posts: 2507
Marseille, France
WWW
Re: Point3d X value
«
Reply #6 on:
May 19, 2015, 07:16:09 AM »
Hi,
It looks like you're missing very basics .NET.
As I said upper Point3d is a structure, not a class. Structures are value types and classes are reference type and a structure instance must have a value and cannot be null (see
here
).
So, you can use a
Nullable type
(Nullable<Point3d> or Point3d?) or use the Point class (as defined upper) instead of Point3d structure.
Anyway, I'm very curious about what kind of stuff you're doing which requires mutable and nullable points...
Logged
Speaking English as a French Frog
ChrisCarlson
Guest
Re: Point3d X value
«
Reply #7 on:
May 19, 2015, 08:56:59 AM »
:confused: how can a coordinate system contain a null value either in the X,Y,Z or the entire value?
Logged
Print
Pages: [
1
] |
Go Up
« previous
next »
TheSwamp
»
Code Red
»
.NET
»
Topic:
Point3d X value